Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript support workers #6480

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

Conversation

rupertbates
Copy link
Member

@rupertbates rupertbates commented Nov 4, 2024

What are you doing in this PR?

This PR is the first step in migrating the support-workers state machine from Scala to Typescript.

There are a lot of changes in this PR, but they broadly break down into the following categories:

  • CDK changes to support deploying a Typescript lamba
  • boiler plate for a Typescript project - package.json, tsconfig.json etc.
  • Typescript schemas for all the state models passed between the various lambdas
  • One Typescript lambda - the CreatePaymentMethod one

In retrospect it probably would have been better to do the infrastructure stuff on its own as a separate PR but I did a lot of this over 2 days of a hack day so I didn't have time to make and merge incremental PRs.

Once this PR is merged, the CreatePaymentMethod step of the state machine will run from the Typescript lambda whilst all the others continue to run from the Scala ones. We can then swap the other lambdas out one by one, and delete the old scala code.

I have tested this in code with the following:

  • Supporter plus purchase with Visa, Mastercard, Discovery, Google Pay, Apple Pay, PayPal and Direct Debit
  • Guardian Weekly gift purchase with credit card.
  • Newspaper with Amex
  • Ran the smoke tests successfully

Copy link
Contributor

github-actions bot commented Nov 4, 2024

Size Change: 0 B

Total Size: 1.89 MB

ℹ️ View Unchanged
Filename Size
./public/compiled-assets/javascripts/[countryGroupId]/events/router.js 90.3 kB
./public/compiled-assets/javascripts/[countryGroupId]/router.js 93.4 kB
./public/compiled-assets/javascripts/ausMomentMap.js 108 kB
./public/compiled-assets/javascripts/contributionsRedirectStyles.js 20 B
./public/compiled-assets/javascripts/digitalSubscriptionLandingPage.js 222 kB
./public/compiled-assets/javascripts/downForMaintenancePage.js 67.3 kB
./public/compiled-assets/javascripts/error404Page.js 67.3 kB
./public/compiled-assets/javascripts/error500Page.js 67.2 kB
./public/compiled-assets/javascripts/favicons.js 617 B
./public/compiled-assets/javascripts/paperSubscriptionCheckoutPage.js 163 kB
./public/compiled-assets/javascripts/paperSubscriptionLandingPage.js 87.6 kB
./public/compiled-assets/javascripts/payPalErrorPage.js 65.9 kB
./public/compiled-assets/javascripts/payPalErrorPageStyles.js 20 B
./public/compiled-assets/javascripts/promotionTerms.js 73.5 kB
./public/compiled-assets/javascripts/subscriptionsLandingPage.js 72.9 kB
./public/compiled-assets/javascripts/subscriptionsRedemptionPage.js 118 kB
./public/compiled-assets/javascripts/unsupportedBrowserStyles.js 20 B
./public/compiled-assets/javascripts/weeklySubscriptionCheckoutPage.js 160 kB
./public/compiled-assets/javascripts/weeklySubscriptionLandingPage.js 88.2 kB
./public/compiled-assets/webpack/114.js 12.2 kB
./public/compiled-assets/webpack/127.js 3.53 kB
./public/compiled-assets/webpack/136.js 2.17 kB
./public/compiled-assets/webpack/163.js 8.9 kB
./public/compiled-assets/webpack/187.js 20 kB
./public/compiled-assets/webpack/192.js 5.69 kB
./public/compiled-assets/webpack/276.js 4.39 kB
./public/compiled-assets/webpack/344.js 2 kB
./public/compiled-assets/webpack/445.js 6.87 kB
./public/compiled-assets/webpack/492.js 7.58 kB
./public/compiled-assets/webpack/706.js 107 kB
./public/compiled-assets/webpack/719.js 13.5 kB
./public/compiled-assets/webpack/847.js 26 kB
./public/compiled-assets/webpack/969.js 37.8 kB
./public/compiled-assets/webpack/checkout.js 17.2 kB
./public/compiled-assets/webpack/GuardianAdLiteLanding.js 8.27 kB
./public/compiled-assets/webpack/LandingPage.js 15.5 kB
./public/compiled-assets/webpack/oneTimeCheckout.js 6.07 kB
./public/compiled-assets/webpack/ThankYou.js 44.4 kB

compressed-size-action

@rupertbates rupertbates force-pushed the typescript-support-workers branch from 98a1a59 to 7860f54 Compare November 11, 2024 16:41
Base automatically changed from support-workers-cdk to main November 12, 2024 10:50
@rupertbates rupertbates force-pushed the typescript-support-workers branch 2 times, most recently from cfd14ef to 0324201 Compare November 13, 2024 13:24
@rupertbates rupertbates force-pushed the typescript-support-workers branch 2 times, most recently from 32d6a8b to 1bf2ef2 Compare December 19, 2024 13:42
@rupertbates rupertbates force-pushed the typescript-support-workers branch from 1bf2ef2 to 52c75a7 Compare January 29, 2025 13:17
"PreparePaymentMethodForReuse"
).addCatch(failureHandler, catchProps);

const createPaymentMethodLambda = createLambda(
const createPaymentMethodLambda = createTypescriptLambda(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first and only (for now) lambda migrated to Typescript

@rupertbates rupertbates force-pushed the typescript-support-workers branch from 5e7fbb5 to 0434c11 Compare January 31, 2025 15:47
@@ -0,0 +1,13 @@
S3_BUCKET="membership-dist"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a shell script to simplify deploying the zipped artifact to CODE for a quicker testing cycle

"check-formatting": "prettier --check **.ts",
"build": "tsc",
"clean-target": "rm -rf target && mkdir -p target",
"install-runtime-dependencies": "yarn install --modules-folder target/typescript/node_modules --production",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line installs only the runtime (non-dev) dependencies into the target directory so they can be zipped up into the deployment artifact

@rupertbates rupertbates force-pushed the typescript-support-workers branch 2 times, most recently from 26037ea to 48f39b0 Compare February 3, 2025 10:34
@@ -0,0 +1,194 @@
import { combinedAddressLine } from '../model/address';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda and application code start here

@@ -0,0 +1,94 @@
import {
Copy link
Member Author

@rupertbates rupertbates Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests and json fixtures from here on except for some small utility classes and the tsconfig file at the end

Comment on lines +110 to 114
fileName: `support-workers.jar`,
runtime: Runtime.JAVA_21,
handler: `com.gu.support.workers.lambdas.${lambdaName}::handleRequest`,
functionName: `${this.stack}-${lambdaName}Lambda-${this.stage}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assume everything is just a duplicate between scala->ts other than these 4 lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionName is the same so it's just the three lines difference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making it a function that only takes those 3 parameters, to make it clearer they are the same

});
this.overrideLogicalId(lambda, {
logicalId: lambdaId,
reason: "Moving existing lambda to CDK",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably doesn't make sense any more does it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment? I think it's roughly accurate, what else would we put?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so it's a permanent change? (I realise it was not added from your PR)
In my mind I thought it needed to be overridden during the switch over to avoid clashes and then it could be removed?
Maybe if it's needed to match up with log group names or state machine definitions it would be something like
"Align function name with state machine definition"?

@rupertbates rupertbates force-pushed the typescript-support-workers branch from 48f39b0 to 773b901 Compare February 3, 2025 13:36
@johnduffell johnduffell changed the title Typescript support workers Reimplement support-workers CreatePaymentMethod lambda in Typescript Feb 3, 2025
@@ -97,6 +102,13 @@ jobs:
- "-PreparePaymentMethodForReuseLambda-"
fileName: support-workers.jar
dependencies: [cfn]
support-workers-typescript:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you've distinguished them by their language as it's clearer 👍 (vs the change from product-move-api -> product-switch-api)

S3_BUCKET="membership-dist"
S3_KEY="support/CODE/support-workers-typescript/support-workers.zip"
LAMBDA_FUNCTIONS=(
"-CreatePaymentMethodLambda-"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not put the - where it's used rather than in (every) function name?
support-${function}-CODE

@rupertbates rupertbates force-pushed the typescript-support-workers branch from 8c4140a to 1811f3a Compare February 3, 2025 18:13
@rupertbates rupertbates force-pushed the typescript-support-workers branch from 1811f3a to 7657069 Compare February 3, 2025 18:19
@johnduffell johnduffell changed the title Reimplement support-workers CreatePaymentMethod lambda in Typescript Typescript support workers Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants