@infoxchange/make-it-so 2.12.0-internal-testing-add-ix-ses-idenity.4 → 2.12.0-internal-testing-add-setup-proxy-globally.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -261,29 +261,6 @@ new IxDnsRecord(scope, "IxDnsRecord", {
261
261
 
262
262
  </details>
263
263
 
264
- <details>
265
- <summary><strong>IxSESIdentity</strong> - Creates an SES domain identity for a domain managed by IX.</summary>
266
-
267
- ```typescript
268
- import { IxSESIdentity } from "@infoxchange/make-it-so/cdk-constructs";
269
-
270
- new IxSESIdentity(scope, "IxSESIdentity", {
271
- // Email identity domain will be: example.dev.ixapps.org
272
- // Custom mail from domain will be: info.example.dev.ixapps.org
273
- domain: "example.dev.ixapps.org",
274
- mailFromSubdomain: "info", // optional, "mail" will be used otherwise
275
- });
276
- ```
277
-
278
- #### Options:
279
-
280
- | Prop | Type | Description |
281
- | ----------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
282
- | domain | string | The domain of the identity. An email address can also be provided in which case the domain will be extracted from the email. |
283
- | mailFromSubdomain | string | (optional) by default the custom mail from domain will be `mail.${domain}`. This lets you change that. It should be given as just the subdomain part, not the fully qualified domain. |
284
-
285
- </details>
286
-
287
264
  <details>
288
265
  <summary><strong>IxWebsiteRedirect</strong> - Creates a redirect from one domain to another.</summary>
289
266
 
@@ -7,13 +7,10 @@ type Props = {
7
7
  ttl?: number;
8
8
  hostedZoneId?: string;
9
9
  } & ({
10
- type: "A" | "CNAME" | "NS" | "SOA" | "TXT";
10
+ type: "A" | "CNAME" | "NS" | "SOA";
11
11
  } | {
12
12
  type: "ALIAS";
13
13
  aliasZoneId: string;
14
- } | {
15
- type: "MX";
16
- priority: number;
17
14
  });
18
15
  export declare class IxDnsRecord extends Construct {
19
16
  constructor(scope: ConstructScope, id: ConstructId, props: Props);
@@ -1 +1 @@
1
- {"version":3,"file":"IxDnsRecord.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxDnsRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9D,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,CACA;IACE,IAAI,EAAE,GAAG,GAAG,OAAO,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC;CAC5C,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;CAClB,CACJ,CAAC;AAEF,qBAAa,WAAY,SAAQ,SAAS;gBAC5B,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK;IAKhE,OAAO,CAAC,eAAe;CA6CxB"}
1
+ {"version":3,"file":"IxDnsRecord.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxDnsRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9D,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,CACA;IACE,IAAI,EAAE,GAAG,GAAG,OAAO,GAAG,IAAI,GAAG,KAAK,CAAC;CACpC,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CACJ,CAAC;AAEF,qBAAa,WAAY,SAAQ,SAAS;gBAC5B,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK;IAKhE,OAAO,CAAC,eAAe;CAyBxB"}
@@ -9,31 +9,14 @@ export class IxDnsRecord extends Construct {
9
9
  }
10
10
  createDnsRecord(scope, id, constructProps) {
11
11
  const dnsRecordUpdaterLambdaArn = StringParameter.valueForStringParameter(scope, "/shared-services/route53/lambdaArn");
12
- const keysMap = {
12
+ const lambdaProps = remapKeys(constructProps, {
13
13
  name: "RecordFQDN",
14
14
  value: "RecordValue",
15
15
  ttl: "RecordTTL",
16
16
  hostedZoneId: "HostedZoneId",
17
17
  type: "RecordType",
18
18
  aliasZoneId: "AliasZoneId",
19
- };
20
- let lambdaProps;
21
- if (constructProps.type === "TXT") {
22
- lambdaProps = remapKeys({
23
- ...constructProps,
24
- value: `"${constructProps.value}"`,
25
- }, keysMap);
26
- }
27
- else if (constructProps.type === "MX") {
28
- const { priority, ...rest } = constructProps;
29
- lambdaProps = remapKeys({
30
- ...rest,
31
- value: `${priority} ${rest.value}`,
32
- }, keysMap);
33
- }
34
- else {
35
- lambdaProps = remapKeys(constructProps, keysMap);
36
- }
19
+ });
37
20
  new CustomResource(scope, id + "-CertificateCustomResource", {
38
21
  resourceType: "Custom::DNSRecordUpdaterLambda",
39
22
  serviceToken: dnsRecordUpdaterLambdaArn,
@@ -1,7 +1,6 @@
1
1
  export * from "./IxVpcDetails.js";
2
2
  export * from "./IxCertificate.js";
3
3
  export * from "./IxDnsRecord.js";
4
- export * from "./IxSESIdentity.js";
5
4
  export * from "./IxNextjsSite.js";
6
5
  export * from "./IxStaticSite.js";
7
6
  export * from "./IxElasticache.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  export * from "./IxVpcDetails.js";
2
2
  export * from "./IxCertificate.js";
3
3
  export * from "./IxDnsRecord.js";
4
- export * from "./IxSESIdentity.js";
5
4
  export * from "./IxNextjsSite.js";
6
5
  export * from "./IxStaticSite.js";
7
6
  export * from "./IxElasticache.js";
@@ -0,0 +1,4 @@
1
+ import { fetch as undiciFetch } from "undici";
2
+ export declare function setupProxyGlobally(): void;
3
+ export declare function getProxiedFetch(): typeof undiciFetch;
4
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,IAAI,WAAW,EACrB,MAAM,QAAQ,CAAC;AAGhB,wBAAgB,kBAAkB,SAiBjC;AAED,wBAAgB,eAAe,uBAW9B"}
@@ -0,0 +1,29 @@
1
+ import { setGlobalDispatcher, getGlobalDispatcher, EnvHttpProxyAgent, fetch as undiciFetch, } from "undici";
2
+ import { bootstrap } from "global-agent";
3
+ export function setupProxyGlobally() {
4
+ // Make operation idempotent
5
+ if (getGlobalDispatcher() instanceof EnvHttpProxyAgent)
6
+ return;
7
+ // To cover libraries that use fetch
8
+ // See https://nodejs.org/api/globals.html#custom-dispatcher
9
+ // This might stop being needed at some point: https://github.com/actions/create-github-app-token/pull/143#discussion_r1747641337
10
+ const envHttpProxyAgent = new EnvHttpProxyAgent();
11
+ setGlobalDispatcher(envHttpProxyAgent);
12
+ // To cover libraries that use the http/https object
13
+ if (!process.env.GLOBAL_AGENT_HTTP_PROXY) {
14
+ process.env.GLOBAL_AGENT_HTTP_PROXY = process.env.HTTP_PROXY;
15
+ process.env.GLOBAL_AGENT_HTTPS_PROXY =
16
+ process.env.HTTPS_PROXY ?? process.env.HTTP_PROXY;
17
+ }
18
+ bootstrap();
19
+ }
20
+ export function getProxiedFetch() {
21
+ const fetch = (input, init = {}) => {
22
+ if (init.dispatcher) {
23
+ console.warn("A custom dispatcher was provided to fetch but this is ignored as a proxy agent is being used.");
24
+ }
25
+ const envHttpProxyAgent = new EnvHttpProxyAgent();
26
+ return undiciFetch(input, { ...init, dispatcher: envHttpProxyAgent });
27
+ };
28
+ return fetch;
29
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./fetch.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/proxy/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
@@ -0,0 +1 @@
1
+ export * from "./fetch.js";
@@ -1,4 +1,4 @@
1
1
  export declare function remapKeys<SourceObject extends object, MapObject extends Record<keyof SourceObject, string>>(object: SourceObject, keyMap: Readonly<MapObject>): {
2
- [k in keyof SourceObject as k extends keyof MapObject ? MapObject[k] : k]: SourceObject[k];
2
+ [k in keyof SourceObject]: MapObject[k];
3
3
  };
4
4
  //# sourceMappingURL=objects.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/objects.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CACvB,YAAY,SAAS,MAAM,EAC3B,SAAS,SAAS,MAAM,CAAC,MAAM,YAAY,EAAE,MAAM,CAAC,EAEpD,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAC1B;KACA,CAAC,IAAI,MAAM,YAAY,IAAI,CAAC,SAAS,MAAM,SAAS,GACjD,SAAS,CAAC,CAAC,CAAC,GACZ,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;CACxB,CAQA"}
1
+ {"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/objects.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CACvB,YAAY,SAAS,MAAM,EAC3B,SAAS,SAAS,MAAM,CAAC,MAAM,YAAY,EAAE,MAAM,CAAC,EAEpD,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAC1B;KAAG,CAAC,IAAI,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,CAAC;CAAE,CAQ7C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infoxchange/make-it-so",
3
- "version": "2.12.0-internal-testing-add-ix-ses-idenity.4",
3
+ "version": "2.12.0-internal-testing-add-setup-proxy-globally.1",
4
4
  "description": "Makes deploying services to IX infra easy",
5
5
  "repository": "github:infoxchange/make-it-so",
6
6
  "type": "module",
@@ -17,7 +17,8 @@
17
17
  "exports": {
18
18
  "./cdk-constructs": "./dist/cdk-constructs/index.js",
19
19
  "./deployConfig": "./dist/deployConfig.js",
20
- "./auth": "./dist/lib/auth/index.js"
20
+ "./auth": "./dist/lib/auth/index.js",
21
+ "./proxy": "./dist/lib/proxy/index.js"
21
22
  },
22
23
  "lint-staged": {
23
24
  "**/*": [
@@ -32,6 +33,7 @@
32
33
  "@eslint/js": "^9.3.0",
33
34
  "@tsconfig/node21": "^21.0.3",
34
35
  "@types/aws-cloudfront-function": "^1.0.6",
36
+ "@types/global-agent": "^3.0.0",
35
37
  "@types/jsonwebtoken": "^9.0.10",
36
38
  "aws-cdk-lib": "2.142.1",
37
39
  "constructs": "^10.3.0",
@@ -53,7 +55,9 @@
53
55
  "sst": "^2.0.0"
54
56
  },
55
57
  "dependencies": {
58
+ "global-agent": "^3.0.0",
56
59
  "jsonwebtoken": "^9.0.2",
60
+ "undici": "^7.16.0",
57
61
  "zod": "^3.24.2"
58
62
  }
59
63
  }
@@ -13,16 +13,12 @@ type Props = {
13
13
  hostedZoneId?: string;
14
14
  } & (
15
15
  | {
16
- type: "A" | "CNAME" | "NS" | "SOA" | "TXT";
16
+ type: "A" | "CNAME" | "NS" | "SOA";
17
17
  }
18
18
  | {
19
19
  type: "ALIAS";
20
20
  aliasZoneId: string;
21
21
  }
22
- | {
23
- type: "MX";
24
- priority: number;
25
- }
26
22
  );
27
23
 
28
24
  export class IxDnsRecord extends Construct {
@@ -40,35 +36,15 @@ export class IxDnsRecord extends Construct {
40
36
  scope,
41
37
  "/shared-services/route53/lambdaArn",
42
38
  );
43
- const keysMap = {
39
+
40
+ const lambdaProps = remapKeys(constructProps, {
44
41
  name: "RecordFQDN",
45
42
  value: "RecordValue",
46
43
  ttl: "RecordTTL",
47
44
  hostedZoneId: "HostedZoneId",
48
45
  type: "RecordType",
49
46
  aliasZoneId: "AliasZoneId",
50
- };
51
- let lambdaProps;
52
- if (constructProps.type === "TXT") {
53
- lambdaProps = remapKeys(
54
- {
55
- ...constructProps,
56
- value: `"${constructProps.value}"`,
57
- },
58
- keysMap,
59
- );
60
- } else if (constructProps.type === "MX") {
61
- const { priority, ...rest } = constructProps;
62
- lambdaProps = remapKeys(
63
- {
64
- ...rest,
65
- value: `${priority} ${rest.value}`,
66
- },
67
- keysMap,
68
- );
69
- } else {
70
- lambdaProps = remapKeys(constructProps, keysMap);
71
- }
47
+ });
72
48
 
73
49
  new CustomResource(scope, id + "-CertificateCustomResource", {
74
50
  resourceType: "Custom::DNSRecordUpdaterLambda",
@@ -1,7 +1,6 @@
1
1
  export * from "./IxVpcDetails.js";
2
2
  export * from "./IxCertificate.js";
3
3
  export * from "./IxDnsRecord.js";
4
- export * from "./IxSESIdentity.js";
5
4
  export * from "./IxNextjsSite.js";
6
5
  export * from "./IxStaticSite.js";
7
6
  export * from "./IxElasticache.js";
@@ -0,0 +1,39 @@
1
+ import {
2
+ setGlobalDispatcher,
3
+ getGlobalDispatcher,
4
+ EnvHttpProxyAgent,
5
+ fetch as undiciFetch,
6
+ } from "undici";
7
+ import { bootstrap } from "global-agent";
8
+
9
+ export function setupProxyGlobally() {
10
+ // Make operation idempotent
11
+ if (getGlobalDispatcher() instanceof EnvHttpProxyAgent) return;
12
+
13
+ // To cover libraries that use fetch
14
+ // See https://nodejs.org/api/globals.html#custom-dispatcher
15
+ // This might stop being needed at some point: https://github.com/actions/create-github-app-token/pull/143#discussion_r1747641337
16
+ const envHttpProxyAgent = new EnvHttpProxyAgent();
17
+ setGlobalDispatcher(envHttpProxyAgent);
18
+
19
+ // To cover libraries that use the http/https object
20
+ if (!process.env.GLOBAL_AGENT_HTTP_PROXY) {
21
+ process.env.GLOBAL_AGENT_HTTP_PROXY = process.env.HTTP_PROXY;
22
+ process.env.GLOBAL_AGENT_HTTPS_PROXY =
23
+ process.env.HTTPS_PROXY ?? process.env.HTTP_PROXY;
24
+ }
25
+ bootstrap();
26
+ }
27
+
28
+ export function getProxiedFetch() {
29
+ const fetch: typeof undiciFetch = (input, init = {}) => {
30
+ if (init.dispatcher) {
31
+ console.warn(
32
+ "A custom dispatcher was provided to fetch but this is ignored as a proxy agent is being used.",
33
+ );
34
+ }
35
+ const envHttpProxyAgent = new EnvHttpProxyAgent();
36
+ return undiciFetch(input, { ...init, dispatcher: envHttpProxyAgent });
37
+ };
38
+ return fetch;
39
+ }
@@ -0,0 +1 @@
1
+ export * from "./fetch.js";
@@ -4,11 +4,7 @@ export function remapKeys<
4
4
  >(
5
5
  object: SourceObject,
6
6
  keyMap: Readonly<MapObject>,
7
- ): {
8
- [k in keyof SourceObject as k extends keyof MapObject
9
- ? MapObject[k]
10
- : k]: SourceObject[k];
11
- } {
7
+ ): { [k in keyof SourceObject]: MapObject[k] } {
12
8
  return Object.fromEntries(
13
9
  Object.entries(object).map(([key, value]) => {
14
10
  // @ts-expect-error the typing for map() reduces keys to general string
@@ -1,15 +0,0 @@
1
- import { Construct } from "constructs";
2
- type ConstructScope = ConstructorParameters<typeof Construct>[0];
3
- type ConstructId = ConstructorParameters<typeof Construct>[1];
4
- type Props = {
5
- mailFromSubdomain?: string;
6
- } & ({
7
- domain: string;
8
- } | {
9
- from: string;
10
- });
11
- export declare class IxSESIdentity extends Construct {
12
- constructor(scope: ConstructScope, id: ConstructId, props: Props);
13
- }
14
- export {};
15
- //# sourceMappingURL=IxSESIdentity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IxSESIdentity.d.ts","sourceRoot":"","sources":["../../src/cdk-constructs/IxSESIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,KAAK,cAAc,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9D,KAAK,KAAK,GAAG;IACX,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GAAG,CACA;IACE,MAAM,EAAE,MAAM,CAAC;CAChB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CACJ,CAAC;AAEF,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK;CAqDjE"}
@@ -1,43 +0,0 @@
1
- import { Construct } from "constructs";
2
- import { IxDnsRecord } from "./IxDnsRecord.js";
3
- import * as ses from "aws-cdk-lib/aws-ses";
4
- import * as cdk from "aws-cdk-lib";
5
- export class IxSESIdentity extends Construct {
6
- constructor(scope, id, props) {
7
- const domain = "domain" in props ? props.domain : props.from.split("@")[1];
8
- const mailFromDomain = `${props.mailFromSubdomain ?? "mail"}.${domain}`;
9
- super(scope, id);
10
- const identity = new ses.EmailIdentity(scope, `${id}EmailIdentity`, {
11
- identity: ses.Identity.domain(domain),
12
- mailFromDomain,
13
- });
14
- // Based on https://github.com/aws/aws-cdk/blob/e2ef65a26c833ecb4a29c22e070c3c5f01c31995/packages/aws-cdk-lib/aws-ses/lib/email-identity.ts#L247
15
- for (const i of [1, 2, 3]) {
16
- new IxDnsRecord(scope, `${id}DkimDnsToken${i}`, {
17
- type: "CNAME",
18
- name: identity[`dkimDnsTokenName${i}`],
19
- value: identity[`dkimDnsTokenValue${i}`],
20
- ttl: 1800,
21
- });
22
- }
23
- // Based on
24
- // https://github.com/aws/aws-cdk/blob/e2ef65a26c833ecb4a29c22e070c3c5f01c31995/packages/aws-cdk-lib/aws-ses/lib/email-identity.ts#L512
25
- new IxDnsRecord(scope, `${id}MailFromMxRecord`, {
26
- type: "MX",
27
- name: mailFromDomain,
28
- value: `feedback-smtp.${cdk.Stack.of(scope).region}.amazonses.com`,
29
- priority: 10,
30
- });
31
- new IxDnsRecord(scope, `${id}MailFromTxtRecord`, {
32
- type: "TXT",
33
- name: mailFromDomain,
34
- value: "v=spf1 include:amazonses.com ~all",
35
- });
36
- // Set up DMARC record
37
- new IxDnsRecord(scope, `${id}DMARC`, {
38
- type: "TXT",
39
- name: `_dmarc.${domain}`,
40
- value: "v=DMARC1; p=none;",
41
- });
42
- }
43
- }
@@ -1,74 +0,0 @@
1
- import { Construct } from "constructs";
2
- import { IxDnsRecord } from "./IxDnsRecord.js";
3
- import * as ses from "aws-cdk-lib/aws-ses";
4
- import * as cdk from "aws-cdk-lib";
5
-
6
- type ConstructScope = ConstructorParameters<typeof Construct>[0];
7
- type ConstructId = ConstructorParameters<typeof Construct>[1];
8
-
9
- type Props = {
10
- mailFromSubdomain?: string;
11
- } & (
12
- | {
13
- domain: string;
14
- }
15
- | {
16
- from: string;
17
- }
18
- );
19
-
20
- export class IxSESIdentity extends Construct {
21
- constructor(scope: ConstructScope, id: ConstructId, props: Props) {
22
- const domain = "domain" in props ? props.domain : props.from.split("@")[1];
23
- const mailFromDomain = `${props.mailFromSubdomain ?? "mail"}.${domain}`;
24
-
25
- super(scope, id);
26
-
27
- const identity = new ses.EmailIdentity(scope, `${id}EmailIdentity`, {
28
- identity: ses.Identity.domain(domain),
29
- mailFromDomain,
30
- });
31
-
32
- // Based on https://github.com/aws/aws-cdk/blob/e2ef65a26c833ecb4a29c22e070c3c5f01c31995/packages/aws-cdk-lib/aws-ses/lib/email-identity.ts#L247
33
- for (const i of [1, 2, 3]) {
34
- new IxDnsRecord(scope, `${id}DkimDnsToken${i}`, {
35
- type: "CNAME",
36
- name: identity[
37
- `dkimDnsTokenName${i}` as
38
- | "dkimDnsTokenName1"
39
- | "dkimDnsTokenName2"
40
- | "dkimDnsTokenName3"
41
- ],
42
- value:
43
- identity[
44
- `dkimDnsTokenValue${i}` as
45
- | "dkimDnsTokenValue1"
46
- | "dkimDnsTokenValue2"
47
- | "dkimDnsTokenValue3"
48
- ],
49
- ttl: 1800,
50
- });
51
- }
52
-
53
- // Based on
54
- // https://github.com/aws/aws-cdk/blob/e2ef65a26c833ecb4a29c22e070c3c5f01c31995/packages/aws-cdk-lib/aws-ses/lib/email-identity.ts#L512
55
- new IxDnsRecord(scope, `${id}MailFromMxRecord`, {
56
- type: "MX",
57
- name: mailFromDomain,
58
- value: `feedback-smtp.${cdk.Stack.of(scope).region}.amazonses.com`,
59
- priority: 10,
60
- });
61
- new IxDnsRecord(scope, `${id}MailFromTxtRecord`, {
62
- type: "TXT",
63
- name: mailFromDomain,
64
- value: "v=spf1 include:amazonses.com ~all",
65
- });
66
-
67
- // Set up DMARC record
68
- new IxDnsRecord(scope, `${id}DMARC`, {
69
- type: "TXT",
70
- name: `_dmarc.${domain}`,
71
- value: "v=DMARC1; p=none;",
72
- });
73
- }
74
- }