Skip to content

Commit 6198d29

Browse files
authored
Stripe Link creation support in manage.acm (#48)
* basic setup * basic setup * use the stripe plink ID as the normal ID * fix vitest resolution * fix vitest module resolution part 2 * try a basic test * update mobile wallet test timeout * add unit tests for the stripe routes * update tests and utils * update live tests to have auth in gh env * fix live test * update event tests * fix linter warnings * build the create panel * basic create link panel tests * some cleanup
1 parent 19fce09 commit 6198d29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2248
-2270
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ jobs:
9292
run: make dev_health_check
9393
- name: Run live testing
9494
run: make test_live_integration
95+
env:
96+
JWT_KEY: ${{ secrets.JWT_KEY }}
9597
- name: Run E2E testing
9698
run: make test_e2e
9799
env:

.github/workflows/deploy-prod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ jobs:
9090
python-version: 3.11
9191
- name: Run live testing
9292
run: make test_live_integration
93+
env:
94+
JWT_KEY: ${{ secrets.JWT_KEY }}
9395
- name: Run E2E testing
9496
run: make test_e2e
9597
env:

cloudformation/iam.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Resources:
106106
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/infra-core-api-iam-userroles/*
107107
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/infra-core-api-iam-grouproles
108108
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/infra-core-api-iam-grouproles/*
109+
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/infra-core-api-stripe-links
110+
- !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/infra-core-api-stripe-links/*
109111

110112
PolicyName: lambda-dynamo
111113
Outputs:

cloudformation/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,34 @@ Resources:
262262
Projection:
263263
ProjectionType: ALL
264264

265+
StripeLinksTable:
266+
Type: 'AWS::DynamoDB::Table'
267+
DeletionPolicy: "Retain"
268+
UpdateReplacePolicy: "Retain"
269+
Properties:
270+
BillingMode: 'PAY_PER_REQUEST'
271+
TableName: infra-core-api-stripe-links
272+
DeletionProtectionEnabled: true
273+
PointInTimeRecoverySpecification:
274+
PointInTimeRecoveryEnabled: false
275+
AttributeDefinitions:
276+
- AttributeName: userId
277+
AttributeType: S
278+
- AttributeName: linkId
279+
AttributeType: S
280+
KeySchema:
281+
- AttributeName: userId
282+
KeyType: "HASH"
283+
- AttributeName: linkId
284+
KeyType: "RANGE"
285+
GlobalSecondaryIndexes:
286+
- IndexName: LinkIdIndex
287+
KeySchema:
288+
- AttributeName: linkId
289+
KeyType: "HASH"
290+
Projection:
291+
ProjectionType: "ALL"
292+
265293
CacheRecordsTable:
266294
Type: 'AWS::DynamoDB::Table'
267295
DeletionPolicy: "Retain"

generate_jwt.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import jwt from 'jsonwebtoken';
1+
import jwt from "jsonwebtoken";
22
import * as dotenv from "dotenv";
33
dotenv.config();
44

5-
const username = process.env.JWTGEN_USERNAME || '[email protected]'
5+
const username = process.env.JWTGEN_USERNAME || "[email protected]"
66
const payload = {
7-
aud: "custom_jwt",
8-
iss: "custom_jwt",
9-
iat: Math.floor(Date.now() / 1000),
10-
nbf: Math.floor(Date.now() / 1000),
11-
exp: Math.floor(Date.now() / 1000) + (3600 * 24), // Token expires after 24 hour
12-
acr: "1",
13-
aio: "AXQAi/8TAAAA",
14-
amr: ["pwd"],
15-
appid: "your-app-id",
16-
appidacr: "1",
17-
email: username,
18-
groups: ["0"],
19-
idp: "https://login.microsoftonline.com",
20-
ipaddr: "192.168.1.1",
21-
name: "Doe, John",
22-
oid: "00000000-0000-0000-0000-000000000000",
23-
rh: "rh-value",
24-
scp: "user_impersonation",
25-
sub: "subject",
26-
tid: "tenant-id",
27-
unique_name: username,
28-
uti: "uti-value",
29-
ver: "1.0"
7+
aud: "custom_jwt",
8+
iss: "custom_jwt",
9+
iat: Math.floor(Date.now() / 1000),
10+
nbf: Math.floor(Date.now() / 1000),
11+
exp: Math.floor(Date.now() / 1000) + 3600 * 24, // Token expires after 24 hour
12+
acr: "1",
13+
aio: "AXQAi/8TAAAA",
14+
amr: ["pwd"],
15+
appid: "your-app-id",
16+
appidacr: "1",
17+
email: username,
18+
groups: ["0"],
19+
idp: "https://login.microsoftonline.com",
20+
ipaddr: "192.168.1.1",
21+
name: "Doe, John",
22+
oid: "00000000-0000-0000-0000-000000000000",
23+
rh: "rh-value",
24+
scp: "user_impersonation",
25+
sub: "subject",
26+
tid: "tenant-id",
27+
unique_name: username,
28+
uti: "uti-value",
29+
ver: "1.0",
3030
};
3131

3232
const secretKey = process.env.JwtSigningKey;
33-
const token = jwt.sign(payload, secretKey, { algorithm: 'HS256' });
34-
console.log(`USERNAME=${username}`)
35-
console.log('=====================')
36-
console.log(token)
33+
const token = jwt.sign(payload, secretKey, { algorithm: "HS256" });
34+
console.log(`USERNAME=${username}`);
35+
console.log("=====================");
36+
console.log(token);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@
8181
"resolutions": {
8282
"pdfjs-dist": "^4.8.69"
8383
}
84-
}
84+
}

src/api/functions/authorization.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
DynamoDBClient,
3-
GetItemCommand,
4-
QueryCommand,
5-
} from "@aws-sdk/client-dynamodb";
1+
import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb";
62
import { unmarshall } from "@aws-sdk/util-dynamodb";
73
import { genericConfig } from "../../common/config.js";
84
import { DatabaseFetchError } from "../../common/errors/index.js";

src/api/functions/entraId.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
officersGroupTestingId,
77
} from "../../common/config.js";
88
import {
9-
BaseError,
109
EntraFetchError,
1110
EntraGroupError,
1211
EntraInvitationError,
@@ -19,7 +18,6 @@ import {
1918
EntraGroupActions,
2019
EntraInvitationResponse,
2120
} from "../../common/types/iam.js";
22-
import { FastifyInstance } from "fastify";
2321
import { UserProfileDataBase } from "common/types/msGraphApi.js";
2422
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2523
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";

src/api/functions/membership.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FastifyBaseLogger, FastifyInstance } from "fastify";
1+
import { FastifyBaseLogger } from "fastify";
22

33
export async function checkPaidMembership(
44
endpoint: string,
@@ -11,7 +11,13 @@ export async function checkPaidMembership(
1111
log.trace(`Got Membership API Payload for ${netId}: ${membershipApiPayload}`);
1212
try {
1313
return membershipApiPayload["isPaidMember"];
14-
} catch (e: any) {
14+
} catch (e: unknown) {
15+
if (!(e instanceof Error)) {
16+
log.error(
17+
"Failed to get response from membership API (unknown error type.)",
18+
);
19+
throw e;
20+
}
1521
log.error(`Failed to get response from membership API: ${e.toString()}`);
1622
throw e;
1723
}

src/api/functions/mobileWallet.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { getSecretValue } from "../plugins/auth.js";
22
import {
33
ConfigType,
44
genericConfig,
5-
GenericConfigType,
65
SecretConfig,
76
} from "../../common/config.js";
87
import {
98
InternalServerError,
109
UnauthorizedError,
1110
} from "../../common/errors/index.js";
12-
import { FastifyInstance, FastifyRequest } from "fastify";
13-
// these make sure that esbuild includes the files
1411
import icon from "../resources/MembershipPass.pkpass/icon.png";
1512
import logo from "../resources/MembershipPass.pkpass/logo.png";
1613
import strip from "../resources/MembershipPass.pkpass/strip.png";

0 commit comments

Comments
 (0)