From 8d2b5938eeffecb512c69d5528a2aa34f0a058d5 Mon Sep 17 00:00:00 2001 From: Joey Zhou Date: Tue, 7 Jan 2025 18:50:27 -0800 Subject: [PATCH 1/6] feat: add new reactivate endpoint wrapper --- src/utils/fxa.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/utils/fxa.ts b/src/utils/fxa.ts index a7ea81b1a80..0a17abbaae7 100644 --- a/src/utils/fxa.ts +++ b/src/utils/fxa.ts @@ -304,6 +304,50 @@ async function deleteSubscription(bearerToken: string): Promise { } /* c8 ignore stop */ +// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy +/* c8 ignore start */ +async function reactivate(bearerToken: string): Promise { + try { + const subs = (await getSubscriptions(bearerToken)) ?? []; + let subscriptionId; + for (const sub of subs) { + if ( + sub && + sub.productId && + sub.productId === process.env.PREMIUM_PRODUCT_ID + ) { + subscriptionId = sub.subscriptionId; + } + } + if (subscriptionId) { + const reactivateSubscriptionUrl = `${envVars.OAUTH_ACCOUNT_URI}/oauth/subscriptions/reactivate`; + const response = await fetch(reactivateSubscriptionUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${bearerToken}`, + }, + body: JSON.stringify({ + subscriptionId, + }), + }); + const responseJson = await response.json(); + if (!response.ok) throw new Error(responseJson); + logger.info("reactivate_fxa_subscription_success"); + } + } catch (e) { + if (e instanceof Error) { + logger.error("reactivate_fxa_subscription", { + stack: e.stack, + message: e.message, + }); + } + throw e; + } +} +/* c8 ignore stop */ + // Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy /* c8 ignore start */ async function applyCoupon( @@ -418,6 +462,7 @@ export { getSubscriptions, getBillingAndSubscriptions, deleteSubscription, + reactivate, applyCoupon, getAttachedClients, }; From 9ae1bde9918ddcc8d632388470aad80829b89d63 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:36:41 +0000 Subject: [PATCH 2/6] chore(deps-dev): bump yaml from 2.6.1 to 2.7.0 Bumps [yaml](https://github.com/eemeli/yaml) from 2.6.1 to 2.7.0. - [Release notes](https://github.com/eemeli/yaml/releases) - [Commits](https://github.com/eemeli/yaml/compare/v2.6.1...v2.7.0) --- updated-dependencies: - dependency-name: yaml dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 20 ++++++++++++++++---- package.json | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7723883002b..e75de27972e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -103,7 +103,7 @@ "stylelint-scss": "^6.10.0", "tsx": "^4.19.2", "typescript": "^5.7.2", - "yaml": "^2.6.1" + "yaml": "^2.7.0" }, "engines": { "node": "20.9.x", @@ -19258,6 +19258,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lint-staged/node_modules/yaml": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.6.1.tgz", + "integrity": "sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==", + "dev": true, + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/listr2": { "version": "8.2.5", "resolved": "https://registry.npmjs.org/listr2/-/listr2-8.2.5.tgz", @@ -26081,9 +26093,9 @@ "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" }, "node_modules/yaml": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.6.1.tgz", - "integrity": "sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.0.tgz", + "integrity": "sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA==", "dev": true, "bin": { "yaml": "bin.mjs" diff --git a/package.json b/package.json index bf1c818c2b1..9804d3171b2 100644 --- a/package.json +++ b/package.json @@ -164,6 +164,6 @@ "stylelint-scss": "^6.10.0", "tsx": "^4.19.2", "typescript": "^5.7.2", - "yaml": "^2.6.1" + "yaml": "^2.7.0" } } From 8d0740c1a4002248501bf33f9bf5912b99982f67 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:14:45 +0000 Subject: [PATCH 3/6] chore(deps): bump @stripe/stripe-js from 5.2.0 to 5.5.0 Bumps [@stripe/stripe-js](https://github.com/stripe/stripe-js) from 5.2.0 to 5.5.0. - [Release notes](https://github.com/stripe/stripe-js/releases) - [Commits](https://github.com/stripe/stripe-js/compare/v5.2.0...v5.5.0) --- updated-dependencies: - dependency-name: "@stripe/stripe-js" dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 9 ++++----- package.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e75de27972e..d910594b32c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@sentry/nextjs": "^8.47.0", "@sentry/node": "^8.0.0", "@sentry/utils": "^8.47.0", - "@stripe/stripe-js": "^5.2.0", + "@stripe/stripe-js": "^5.5.0", "@types/jsdom": "^21.1.7", "@types/node": "^22.10.2", "@types/react": "^18.3.12", @@ -9877,10 +9877,9 @@ } }, "node_modules/@stripe/stripe-js": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@stripe/stripe-js/-/stripe-js-5.2.0.tgz", - "integrity": "sha512-2ZpEaezx3S0QPtnske175NDaLvUvaVKd4ePHpUN0QF/uV4BBBBRUy5BvQONDym+utbbW0QhSJoiRPnp4FS+4Vg==", - "license": "MIT", + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/@stripe/stripe-js/-/stripe-js-5.5.0.tgz", + "integrity": "sha512-lkfjyAd34aeMpTKKcEVfy8IUyEsjuAT3t9EXr5yZDtdIUncnZpedl/xLV16Dkd4z+fQwixScsCCDxSMNtBOgpQ==", "engines": { "node": ">=12.16" } diff --git a/package.json b/package.json index 9804d3171b2..62fe8f2f158 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "@sentry/nextjs": "^8.47.0", "@sentry/node": "^8.0.0", "@sentry/utils": "^8.47.0", - "@stripe/stripe-js": "^5.2.0", + "@stripe/stripe-js": "^5.5.0", "@types/jsdom": "^21.1.7", "@types/node": "^22.10.2", "@types/react": "^18.3.12", From a99b0506c72bcb02570839d9426513f040b01cb2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:39:38 +0000 Subject: [PATCH 4/6] chore(deps-dev): bump sass from 1.83.0 to 1.83.1 Bumps [sass](https://github.com/sass/dart-sass) from 1.83.0 to 1.83.1. - [Release notes](https://github.com/sass/dart-sass/releases) - [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md) - [Commits](https://github.com/sass/dart-sass/compare/1.83.0...1.83.1) --- updated-dependencies: - dependency-name: sass dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index d910594b32c..bd2ac3fb70d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -96,7 +96,7 @@ "lint-staged": "^15.3.0", "mjml-browser": "^4.15.3", "prettier": "3.4.2", - "sass": "^1.83.0", + "sass": "^1.83.1", "storybook": "^8.4.6", "stylelint": "^16.12.0", "stylelint-config-recommended-scss": "^14.1.0", @@ -22945,9 +22945,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/sass": { - "version": "1.83.0", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.83.0.tgz", - "integrity": "sha512-qsSxlayzoOjdvXMVLkzF84DJFc2HZEL/rFyGIKbbilYtAvlCxyuzUeff9LawTn4btVnLKg75Z8MMr1lxU1lfGw==", + "version": "1.83.1", + "resolved": "https://registry.npmjs.org/sass/-/sass-1.83.1.tgz", + "integrity": "sha512-EVJbDaEs4Rr3F0glJzFSOvtg2/oy2V/YrGFPqPY24UqcLDWcI9ZY5sN+qyO3c/QCZwzgfirvhXvINiJCE/OLcA==", "devOptional": true, "dependencies": { "chokidar": "^4.0.0", diff --git a/package.json b/package.json index 62fe8f2f158..4badbc5b3c1 100644 --- a/package.json +++ b/package.json @@ -157,7 +157,7 @@ "lint-staged": "^15.3.0", "mjml-browser": "^4.15.3", "prettier": "3.4.2", - "sass": "^1.83.0", + "sass": "^1.83.1", "storybook": "^8.4.6", "stylelint": "^16.12.0", "stylelint-config-recommended-scss": "^14.1.0", From befa9571d155d86a5f090658f384f104fc1d5990 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 9 Jan 2025 16:08:51 +0100 Subject: [PATCH 5/6] Revert "Port S3 util module to TypeScript" This reverts commit e4573d52d034fecea548ee96fdc83cf48cbf23cc. It's still being imported from src/scripts/build/uploadAutoCompleteLocations.js, so it can't be plain TypeScript yet. --- src/utils/{s3.ts => s3.js} | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) rename src/utils/{s3.ts => s3.js} (84%) diff --git a/src/utils/s3.ts b/src/utils/s3.js similarity index 84% rename from src/utils/s3.ts rename to src/utils/s3.js index f93e09e25d2..11f5fcc7874 100644 --- a/src/utils/s3.ts +++ b/src/utils/s3.js @@ -24,7 +24,11 @@ const s3 = new S3({ }, }); -export async function uploadToS3(fileName: string, fileStream: Buffer) { +/** + * @param {string} fileName + * @param {Buffer} fileStream + */ +export async function uploadToS3(fileName, fileStream) { console.log("Attempt to upload to s3: ", fileName); const uploadParams = { Bucket, @@ -37,7 +41,7 @@ export async function uploadToS3(fileName: string, fileStream: Buffer) { params: uploadParams, }).done(); console.log("Successfully uploaded data to " + Bucket + "/" + fileName); - } catch (err) { - console.error(err, (err as Error).stack); + } catch (/** @type {any} */ err) { + console.error(err, err.stack); } } From 0fb9f97f6dfe47e75ea256ff046cada029ad48b4 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 9 Jan 2025 16:12:07 +0100 Subject: [PATCH 6/6] Fix `uploadToS3` import path Also change back to a regular import; I don't think it does much harm to import it when unnecessary, and potentially obfuscates invalid import paths. --- src/scripts/build/uploadAutoCompleteLocations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/build/uploadAutoCompleteLocations.js b/src/scripts/build/uploadAutoCompleteLocations.js index e0e8b503e10..ad215599064 100644 --- a/src/scripts/build/uploadAutoCompleteLocations.js +++ b/src/scripts/build/uploadAutoCompleteLocations.js @@ -27,6 +27,7 @@ import os from "os"; import path from "path"; import fs from "fs"; import AdmZip from "adm-zip"; +import { uploadToS3 } from "../../utils/s3.js"; const REMOTE_DATA_URL = "https://download.geonames.org/export/dump"; const DATA_COUNTRY_CODE = "US"; @@ -328,7 +329,6 @@ try { if (process.argv.includes("--skip-upload")) { console.debug("Skipping S3 upload"); } else { - const uploadToS3 = await import("../s3.js"); await uploadToS3(`autocomplete/${LOCATIONS_DATA_FILE}`, readStream); }