From a5249ecc7c3acc29a1f9d5285bd77397263cb135 Mon Sep 17 00:00:00 2001 From: Nathan Grebowiec <44781230+njgreb@users.noreply.github.com> Date: Wed, 11 Nov 2020 18:56:45 -0700 Subject: [PATCH] feat: add option to disable auto add to cart (#759) --- .env-example | 1 + README.md | 1 + src/config.ts | 1 + src/store/lookup.ts | 3 ++- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env-example b/.env-example index 2193726..6d9e442 100644 --- a/.env-example +++ b/.env-example @@ -4,6 +4,7 @@ ASCII_BANNER= ASCII_COLOR= +AUTO_ADD_TO_CART= BROWSER_TRUSTED= COUNTRY= DESKTOP_NOTIFICATIONS= diff --git a/README.md b/README.md index f263ed6..3f5bcd4 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ environment variables are **optional**._ | Environment variable | Description | Notes | |:---:|---|---| +| `AUTO_ADD_TO_CART` | Enable auto add to cart on support stores | Default: `true` | | `BROWSER_TRUSTED` | Skip Chromium Sandbox | Useful for containerized environments, default: `false` | | `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` | | `INCOGNITO` | Puppeteer to run incognito or not | Debugging related, default: `false` | diff --git a/src/config.ts b/src/config.ts index f27ad7d..ed9d152 100644 --- a/src/config.ts +++ b/src/config.ts @@ -302,6 +302,7 @@ if (process.env.MAX_PRICE) { } const store = { + autoAddToCart: envOrBoolean(process.env.AUTO_ADD_TO_CART, true), country: envOrString(process.env.COUNTRY, 'usa'), maxPrice: { series: { diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 2aab596..6bfd4bf 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -117,7 +117,8 @@ async function lookupCard( } if (await lookupCardInStock(store, page, link)) { - const givenUrl = link.cartUrl ? link.cartUrl : link.url; + const givenUrl = + link.cartUrl && config.store.autoAddToCart ? link.cartUrl : link.url; logger.info(`${Print.inStock(link, store, true)}\n${givenUrl}`); if (config.browser.open) {