Skip to content

Commit 8a70503

Browse files
committed
feat: add step to prevent visa invitation letter spam registrations
1 parent d4c158f commit 8a70503

Some content is hidden

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

50 files changed

+7151
-5647
lines changed

cdk/BackendApp.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { App } from "aws-cdk-lib";
2-
import { BackendStack } from './BackendStack.ts';
1+
import { App } from 'aws-cdk-lib'
2+
import { BackendStack } from './BackendStack.ts'
33

44
export class BackendApp extends App {
5-
public constructor(
6-
stackName: string,
7-
{
8-
isTest,
9-
version,
10-
...backendArgs
11-
}: ConstructorParameters<typeof BackendStack>[2] & {
12-
isTest: boolean;
13-
version: string;
14-
}
15-
) {
16-
super({
17-
context: {
18-
isTest,
19-
version,
20-
},
21-
});
22-
new BackendStack(this, stackName, backendArgs);
23-
}
5+
public constructor(
6+
stackName: string,
7+
{
8+
isTest,
9+
version,
10+
...backendArgs
11+
}: ConstructorParameters<typeof BackendStack>[2] & {
12+
isTest: boolean
13+
version: string
14+
},
15+
) {
16+
super({
17+
context: {
18+
isTest,
19+
version,
20+
},
21+
})
22+
new BackendStack(this, stackName, backendArgs)
23+
}
2424
}

cdk/BackendStack.ts

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
1+
import { LambdaSource } from '@bifravst/aws-cdk-lambda-helpers/cdk'
2+
import { type PackedLayer } from '@bifravst/aws-cdk-lambda-helpers/layer'
13
import {
2-
App,
3-
CfnOutput,
4-
Stack,
5-
aws_lambda as Lambda,
6-
aws_s3 as S3,
7-
} from "aws-cdk-lib";
8-
import { ConfirmEmail } from "./ConfirmEmail.ts";
9-
import type { BackendLambdas } from "./lambdas/packBackendLambdas.ts";
10-
import { Registrations } from "./Registrations.ts";
11-
import { LambdaSource } from "@bifravst/aws-cdk-lambda-helpers/cdk";
12-
import { Register } from "./Register.ts";
13-
import { type PackedLayer } from "@bifravst/aws-cdk-lambda-helpers/layer";
14-
import { PublicProfiles } from "./PublicProfiles.ts";
15-
import { ParticipantsList } from "./ParticipantsList.ts";
4+
App,
5+
CfnOutput,
6+
aws_lambda as Lambda,
7+
aws_s3 as S3,
8+
Stack,
9+
} from 'aws-cdk-lib'
10+
import { ConfirmEmail } from './ConfirmEmail.ts'
11+
import type { BackendLambdas } from './lambdas/packBackendLambdas.ts'
12+
import { ParticipantsList } from './ParticipantsList.ts'
13+
import { PublicProfiles } from './PublicProfiles.ts'
14+
import { Register } from './Register.ts'
15+
import { Registrations } from './Registrations.ts'
1616

1717
export class BackendStack extends Stack {
18-
public constructor(
19-
parent: App,
20-
stackName: string,
21-
{
22-
lambdas,
23-
packedLayer,
24-
}: { lambdas: BackendLambdas; packedLayer: PackedLayer }
25-
) {
26-
super(parent, stackName);
18+
public constructor(
19+
parent: App,
20+
stackName: string,
21+
{
22+
lambdas,
23+
packedLayer,
24+
}: { lambdas: BackendLambdas; packedLayer: PackedLayer },
25+
) {
26+
super(parent, stackName)
2727

28-
const registrations = new Registrations(this);
28+
const registrations = new Registrations(this)
2929

30-
const layer = new Lambda.LayerVersion(this, "layer", {
31-
layerVersionName: `${Stack.of(this).stackName}-layer`,
32-
code: new LambdaSource(this, {
33-
id: "layer",
34-
zipFilePath: packedLayer.layerZipFilePath,
35-
hash: packedLayer.hash,
36-
}).code,
37-
compatibleArchitectures: [Lambda.Architecture.ARM_64],
38-
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
39-
});
30+
const layer = new Lambda.LayerVersion(this, 'layer', {
31+
layerVersionName: `${Stack.of(this).stackName}-layer`,
32+
code: new LambdaSource(this, {
33+
id: 'layer',
34+
zipFilePath: packedLayer.layerZipFilePath,
35+
hash: packedLayer.hash,
36+
}).code,
37+
compatibleArchitectures: [Lambda.Architecture.ARM_64],
38+
compatibleRuntimes: [Lambda.Runtime.NODEJS_22_X],
39+
})
4040

41-
const confirmEmail = new ConfirmEmail(this, {
42-
lambdas,
43-
registrations,
44-
layer,
45-
});
41+
const confirmEmail = new ConfirmEmail(this, {
42+
lambdas,
43+
registrations,
44+
layer,
45+
})
4646

47-
const register = new Register(this, {
48-
lambdas,
49-
registrations,
50-
layer,
51-
});
47+
const register = new Register(this, {
48+
lambdas,
49+
registrations,
50+
layer,
51+
})
5252

53-
const imageMagickLayer = new Lambda.LayerVersion(
54-
this,
55-
"imagemagick-layer",
56-
{
57-
code: Lambda.Code.fromBucket(
58-
S3.Bucket.fromBucketName(
59-
this,
60-
"imagemagickLayerBucket",
61-
// Must be in same region as the stack
62-
"imagemagick-layer"
63-
),
64-
// This is created using https://github.com/CyprusCodes/imagemagick-aws-lambda-2
65-
"layer.zip"
66-
),
67-
}
68-
);
53+
const imageMagickLayer = new Lambda.LayerVersion(
54+
this,
55+
'imagemagick-layer',
56+
{
57+
code: Lambda.Code.fromBucket(
58+
S3.Bucket.fromBucketName(
59+
this,
60+
'imagemagickLayerBucket',
61+
// Must be in same region as the stack
62+
'imagemagick-layer',
63+
),
64+
// This is created using https://github.com/CyprusCodes/imagemagick-aws-lambda-2
65+
'layer.zip',
66+
),
67+
},
68+
)
6969

70-
const publicProfiles = new PublicProfiles(this, {
71-
imageMagickLayer,
72-
lambdas,
73-
layer,
74-
registrations,
75-
});
70+
const publicProfiles = new PublicProfiles(this, {
71+
imageMagickLayer,
72+
lambdas,
73+
layer,
74+
registrations,
75+
})
7676

77-
const participantsList = new ParticipantsList(this, {
78-
lambdas,
79-
layer,
80-
registrations,
81-
});
77+
const participantsList = new ParticipantsList(this, {
78+
lambdas,
79+
layer,
80+
registrations,
81+
})
8282

83-
new CfnOutput(this, "requestTokenAPI", {
84-
value: confirmEmail.requestTokenURL.url,
85-
exportName: `${this.stackName}:requestTokenAPI`,
86-
});
83+
new CfnOutput(this, 'requestTokenAPI', {
84+
value: confirmEmail.requestTokenURL.url,
85+
exportName: `${this.stackName}:requestTokenAPI`,
86+
})
8787

88-
new CfnOutput(this, "confirmEmailURL", {
89-
value: confirmEmail.confirmEmailURL.url,
90-
exportName: `${this.stackName}:confirmEmailURL`,
91-
});
88+
new CfnOutput(this, 'confirmEmailURL', {
89+
value: confirmEmail.confirmEmailURL.url,
90+
exportName: `${this.stackName}:confirmEmailURL`,
91+
})
9292

93-
new CfnOutput(this, "registerURL", {
94-
value: register.registerURL.url,
95-
exportName: `${this.stackName}:registerURL`,
96-
});
93+
new CfnOutput(this, 'registerURL', {
94+
value: register.registerURL.url,
95+
exportName: `${this.stackName}:registerURL`,
96+
})
9797

98-
new CfnOutput(this, "publicProfilesURL", {
99-
value: publicProfiles.listPublicProfilesURL.url,
100-
exportName: `${this.stackName}:publicProfilesURL`,
101-
});
98+
new CfnOutput(this, 'publicProfilesURL', {
99+
value: publicProfiles.listPublicProfilesURL.url,
100+
exportName: `${this.stackName}:publicProfilesURL`,
101+
})
102102

103-
new CfnOutput(this, "listParticipantEmailsURL", {
104-
value: participantsList.listParticipantEmailsURL.url,
105-
exportName: `${this.stackName}:listParticipantEmailsURL`,
106-
});
107-
}
103+
new CfnOutput(this, 'listParticipantEmailsURL', {
104+
value: participantsList.listParticipantEmailsURL.url,
105+
exportName: `${this.stackName}:listParticipantEmailsURL`,
106+
})
107+
}
108108
}
109109

110110
export type StackOutputs = {
111-
requestTokenAPI: string;
112-
confirmEmailURL: string;
113-
};
111+
requestTokenAPI: string
112+
confirmEmailURL: string
113+
}

cdk/ConfirmEmail.ts

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
import { PackedLambdaFn } from "@bifravst/aws-cdk-lambda-helpers/cdk";
2-
import { aws_iam as IAM, aws_lambda as Lambda } from "aws-cdk-lib";
3-
import type { ILayerVersion } from "aws-cdk-lib/aws-lambda";
4-
import { Construct } from "constructs";
5-
import type { BackendLambdas } from './lambdas/packBackendLambdas.ts';
6-
import type { Registrations } from './Registrations.ts';
1+
import { PackedLambdaFn } from '@bifravst/aws-cdk-lambda-helpers/cdk'
2+
import { aws_iam as IAM, aws_lambda as Lambda } from 'aws-cdk-lib'
3+
import type { ILayerVersion } from 'aws-cdk-lib/aws-lambda'
4+
import { Construct } from 'constructs'
5+
import type { BackendLambdas } from './lambdas/packBackendLambdas.ts'
6+
import type { Registrations } from './Registrations.ts'
77

88
export class ConfirmEmail extends Construct {
9-
public readonly requestTokenURL: Lambda.IFunctionUrl;
10-
public readonly confirmEmailURL: Lambda.IFunctionUrl;
11-
constructor(
12-
parent: Construct,
13-
{
14-
lambdas,
15-
registrations,
16-
layer,
17-
}: {
18-
lambdas: BackendLambdas;
19-
registrations: Registrations;
20-
layer: ILayerVersion;
21-
}
22-
) {
23-
super(parent, "confirm-email");
9+
public readonly requestTokenURL: Lambda.IFunctionUrl
10+
public readonly confirmEmailURL: Lambda.IFunctionUrl
11+
constructor(
12+
parent: Construct,
13+
{
14+
lambdas,
15+
registrations,
16+
layer,
17+
}: {
18+
lambdas: BackendLambdas
19+
registrations: Registrations
20+
layer: ILayerVersion
21+
},
22+
) {
23+
super(parent, 'confirm-email')
2424

25-
const requestTokenFn = new PackedLambdaFn(
26-
this,
27-
"requestTokenFn",
28-
lambdas.requestToken,
29-
{
30-
initialPolicy: [
31-
new IAM.PolicyStatement({
32-
actions: ["ses:SendEmail"],
33-
resources: ["*"],
34-
}),
35-
],
36-
environment: {
37-
EMAILS_TABLE_NAME: registrations.emailsTable.tableName,
38-
},
39-
layers: [layer],
40-
}
41-
);
25+
const requestTokenFn = new PackedLambdaFn(
26+
this,
27+
'requestTokenFn',
28+
lambdas.requestToken,
29+
{
30+
initialPolicy: [
31+
new IAM.PolicyStatement({
32+
actions: ['ses:SendEmail'],
33+
resources: ['*'],
34+
}),
35+
],
36+
environment: {
37+
EMAILS_TABLE_NAME: registrations.emailsTable.tableName,
38+
},
39+
layers: [layer],
40+
},
41+
)
4242

43-
this.requestTokenURL = requestTokenFn.fn.addFunctionUrl({
44-
authType: Lambda.FunctionUrlAuthType.NONE,
45-
});
43+
this.requestTokenURL = requestTokenFn.fn.addFunctionUrl({
44+
authType: Lambda.FunctionUrlAuthType.NONE,
45+
})
4646

47-
registrations.emailsTable.grantReadWriteData(requestTokenFn.fn);
47+
registrations.emailsTable.grantReadWriteData(requestTokenFn.fn)
4848

49-
const confirmEmailFn = new PackedLambdaFn(
50-
this,
51-
"confirmEmailFn",
52-
lambdas.confirmEmail,
53-
{
54-
environment: {
55-
EMAILS_TABLE_NAME: registrations.emailsTable.tableName,
56-
},
57-
layers: [layer],
58-
}
59-
);
49+
const confirmEmailFn = new PackedLambdaFn(
50+
this,
51+
'confirmEmailFn',
52+
lambdas.confirmEmail,
53+
{
54+
environment: {
55+
EMAILS_TABLE_NAME: registrations.emailsTable.tableName,
56+
},
57+
layers: [layer],
58+
},
59+
)
6060

61-
this.confirmEmailURL = confirmEmailFn.fn.addFunctionUrl({
62-
authType: Lambda.FunctionUrlAuthType.NONE,
63-
});
61+
this.confirmEmailURL = confirmEmailFn.fn.addFunctionUrl({
62+
authType: Lambda.FunctionUrlAuthType.NONE,
63+
})
6464

65-
registrations.emailsTable.grantReadData(confirmEmailFn.fn);
66-
}
65+
registrations.emailsTable.grantReadData(confirmEmailFn.fn)
66+
}
6767
}

0 commit comments

Comments
 (0)