diff --git a/README.md b/README.md index a67ab30..ee16c19 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ main(); async function main() { // Search for products matching a certain string. const guestInfo = await MigrosAPI.account.oauth2.getGuestToken(); - const responseProductSearch = await MigrosAPI.products.productSearch.searchProduct({ + const responseProductSearch = await MigrosAPI.products.productSearch.searchProduct({ query: "cooking salt", }, { leshopch: guestInfo.token }) @@ -40,9 +40,9 @@ async function main() { hl: "", TS012f1684: "" } - // Get security options of your MigrosAPI Account - const securityOptions = await MigrosAPI.account.security.getOptions(loginCookies) - console.log(securityOptions) + // Get security options of your MigrosAPI Account + const securityOptions = await MigrosAPI.account.security.getOptions(loginCookies) + console.log(securityOptions) } ``` diff --git a/package-lock.json b/package-lock.json index d513ff3..262932a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "migros-api-wrapper", - "version": "1.1.12", + "version": "1.1.15", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "migros-api-wrapper", - "version": "1.1.12", + "version": "1.1.15", "license": "MIT", "dependencies": { "cheerio": "^1.0.0-rc.12", + "dotenv": "^16.4.5", "pino": "^8.6.1", "pino-pretty": "^9.1.1" }, @@ -1968,12 +1969,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -2508,6 +2509,17 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/electron-to-chromium": { "version": "1.4.647", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.647.tgz", @@ -2944,9 +2956,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" diff --git a/package.json b/package.json index 73b556f..362d1d2 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,10 @@ ], "main": "dist/index.js", "typings": "./dist/index.d.ts", - "files": ["/dist", "/src"], + "files": [ + "/dist", + "/src" + ], "scripts": { "test": "jest", "lint": "eslint . --ext .ts", @@ -46,6 +49,7 @@ }, "dependencies": { "cheerio": "^1.0.0-rc.12", + "dotenv": "^16.4.5", "pino": "^8.6.1", "pino-pretty": "^9.1.1" } diff --git a/tests/cumulus-receipt.test.ts b/tests/cumulus-receipt.test.ts index 5aa8bea..b212f2e 100644 --- a/tests/cumulus-receipt.test.ts +++ b/tests/cumulus-receipt.test.ts @@ -1,30 +1,36 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import { describe, test } from "@jest/globals"; -// import { MigrosAPI } from "../src"; +import { describe, test, expect } from "@jest/globals"; +import { MigrosAPI } from "../src"; +import * as dotenv from "dotenv"; +import path from "path"; describe("Check for Migros Cumulus Receipt", () => { test("Retrieve Cumulus Receipt", async () => { - // const responseReceipts = await MigrosAPI.account.cumulus.getCumulusReceipts( - // { - // from: new Date("01.12.2023"), - // to: new Date(), - // }, - // { - // ["cookie-banner-acceptance-state"]: "true", - // JSESSIONID: responseSession["set-cookie"]["JSESSIONID"], - // INGRESSCOOKIE: ".", - // }, - // ); - // console.log(responseReceipts); - // const response = await MigrosAPI.account.cumulus.getCumulusReceipt( - // { - // receiptId: responseReceipts[0].id, - // }, - // { - // JSESSIONID: responseSession["set-cookie"]["JSESSIONID"], - // INGRESSCOOKIE: ".", - // }, - // ); - // expect(response).toBe({}); + dotenv.config({ path: path.join(__dirname, "../.env") }); + if (!process.env.CUMULUS_JSESSIONID || !process.env.CUMULUS_INGRESSCOOKIE) { + console.log("Please provide JSESSIONID and INGRESSCOOKIE in .env"); + return; + } + const responseReceipts = await MigrosAPI.account.cumulus.getCumulusReceipts( + { + from: new Date("01.12.2023"), + to: new Date(), + }, + { + ["cookie-banner-acceptance-state"]: "true", + JSESSIONID: process.env.CUMULUS_JSESSIONID, + INGRESSCOOKIE: process.env.CUMULUS_INGRESSCOOKIE, + }, + ); + expect(responseReceipts).toBeInstanceOf(Array); + const response = await MigrosAPI.account.cumulus.getCumulusReceipt( + { + receiptId: responseReceipts[0].id, + }, + { + JSESSIONID: process.env.CUMULUS_JSESSIONID, + INGRESSCOOKIE: process.env.CUMULUS_INGRESSCOOKIE, + }, + ); + expect(response).toHaveProperty("cumulus"); }); }); diff --git a/tests/cumulus-receipts.test.ts b/tests/cumulus-receipts.test.ts index ebd3f57..99265f6 100644 --- a/tests/cumulus-receipts.test.ts +++ b/tests/cumulus-receipts.test.ts @@ -1,25 +1,27 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import { describe, expect, test } from '@jest/globals'; -// import { MigrosAPI } from "../src"; +import { describe, expect, test } from "@jest/globals"; +import { MigrosAPI } from "../src"; +import * as dotenv from "dotenv"; +import path from "path"; -describe('Check for Migros Cumulus Receipts', () => { - test('Retrieve Cumulus Receipts', async () => { - /* - const response = await MigrosAPI.account.cumulus.getCumulusReceipts({ - from: new Date("01.04.2022"), - to: new Date() - }, { - "BIGipServerpool_shared_migros.ch_80": ".", - "cookie-banner-acceptance-state": ".", - "mo-fulfilmentOption": ".", - "mo-lang": ".", - "mo-securityContext": ".", - "mo-sidebarsState": ".", - JSESSIONID: ".", - REALPERSON_SESSION: "." - }) - */ +describe("Check for Migros Cumulus Receipts", () => { + test("Retrieve Cumulus Receipts", async () => { + dotenv.config({ path: path.join(__dirname, "../.env") }); + if (!process.env.CUMULUS_JSESSIONID || !process.env.CUMULUS_INGRESSCOOKIE) { + console.log("Please provide JSESSIONID and INGRESSCOOKIE in .env"); + return; + } + const responseReceipts = await MigrosAPI.account.cumulus.getCumulusReceipts( + { + from: new Date("01.12.2023"), + to: new Date(), + }, + { + ["cookie-banner-acceptance-state"]: "true", + JSESSIONID: process.env.CUMULUS_JSESSIONID, + INGRESSCOOKIE: process.env.CUMULUS_INGRESSCOOKIE, + }, + ); + expect(responseReceipts).toBeInstanceOf(Array); + }); +}); - expect(null).toBe(null) - }); -}); \ No newline at end of file diff --git a/tests/migusto-recipe-products.test.ts b/tests/migusto-recipe-products.test.ts index 4c98585..6d9f794 100644 --- a/tests/migusto-recipe-products.test.ts +++ b/tests/migusto-recipe-products.test.ts @@ -12,6 +12,6 @@ describe("Search for recipe products", () => { }; const response = await MigrosAPI.migusto.recipeProducts(recipeProductOptions); - expect(response.productIds).toContain("233520695510"); + expect(response.productIds).toContain("103322000000"); }); });