Skip to content

Commit

Permalink
Merge branch 'main' into MNTOR-3919-2
Browse files Browse the repository at this point in the history
  • Loading branch information
mansaj authored Jan 13, 2025
2 parents 16b7f56 + 178f115 commit 9d7c486
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 20 deletions.
37 changes: 24 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -157,13 +157,13 @@
"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",
"stylelint-scss": "^6.10.0",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"yaml": "^2.6.1"
"yaml": "^2.7.0"
}
}
2 changes: 1 addition & 1 deletion src/scripts/build/uploadAutoCompleteLocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

Expand Down
45 changes: 45 additions & 0 deletions src/utils/fxa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,50 @@ async function deleteSubscription(bearerToken: string): Promise<boolean> {
}
/* 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<void> {
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(
Expand Down Expand Up @@ -418,6 +462,7 @@ export {
getSubscriptions,
getBillingAndSubscriptions,
deleteSubscription,
reactivate,
applyCoupon,
getAttachedClients,
};
10 changes: 7 additions & 3 deletions src/utils/s3.ts → src/utils/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}

0 comments on commit 9d7c486

Please sign in to comment.