@ericminassian/platform-core 0.3.0 → 0.4.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/dist/api.d.ts +1225 -45
- package/dist/api.js +471 -13
- package/dist/api.js.map +1 -1
- package/dist/auth.js +5 -2
- package/dist/auth.js.map +1 -1
- package/dist/base64url.d.ts +3 -0
- package/dist/base64url.js +15 -0
- package/dist/base64url.js.map +1 -0
- package/dist/bindings.d.ts +62 -12
- package/dist/bindings.js +1 -1
- package/dist/bindings.js.map +1 -1
- package/dist/cloudfront-function.d.ts +5 -1
- package/dist/cloudfront-function.js +64 -2
- package/dist/cloudfront-function.js.map +1 -1
- package/dist/compute.d.ts +52 -0
- package/dist/compute.js +65 -0
- package/dist/compute.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.js +9 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +56 -1
- package/dist/constants.js +56 -1
- package/dist/constants.js.map +1 -1
- package/dist/email.d.ts +84 -0
- package/dist/email.js +111 -0
- package/dist/email.js.map +1 -0
- package/dist/explore.d.ts +365 -0
- package/dist/explore.js +440 -0
- package/dist/explore.js.map +1 -0
- package/dist/fingerprint.d.ts +9 -0
- package/dist/fingerprint.js +19 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +111 -0
- package/dist/jobs.js +214 -0
- package/dist/jobs.js.map +1 -0
- package/dist/manifest.d.ts +270 -29
- package/dist/manifest.js +190 -22
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +83 -7
- package/dist/naming.js +89 -8
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +5897 -1672
- package/dist/platform-api.js +218 -8
- package/dist/platform-api.js.map +1 -1
- package/dist/realtime.d.ts +139 -0
- package/dist/realtime.js +201 -0
- package/dist/realtime.js.map +1 -0
- package/dist/router/decide.d.ts +2 -0
- package/dist/router/decide.js +38 -6
- package/dist/router.d.ts +35 -13
- package/dist/router.js +36 -0
- package/dist/router.js.map +1 -1
- package/dist/runtime-config.d.ts +57 -0
- package/dist/runtime-config.js +12 -0
- package/dist/runtime-config.js.map +1 -1
- package/dist/storage.d.ts +65 -0
- package/dist/storage.js +122 -0
- package/dist/storage.js.map +1 -0
- package/dist/telemetry.d.ts +135 -20
- package/dist/telemetry.js +108 -22
- package/dist/telemetry.js.map +1 -1
- package/dist/web-compute.d.ts +191 -0
- package/dist/web-compute.js +257 -0
- package/dist/web-compute.js.map +1 -0
- package/package.json +19 -7
- package/src/api.ts +564 -15
- package/src/auth.ts +6 -2
- package/src/base64url.ts +13 -0
- package/src/bindings.ts +67 -6
- package/src/cloudfront-function.ts +64 -2
- package/src/compute.ts +86 -0
- package/src/config.ts +31 -1
- package/src/constants.ts +64 -1
- package/src/email.ts +168 -0
- package/src/explore.ts +504 -0
- package/src/fingerprint.ts +20 -0
- package/src/index.ts +7 -0
- package/src/jobs.ts +281 -0
- package/src/manifest.ts +415 -45
- package/src/naming.ts +93 -9
- package/src/platform-api.ts +249 -8
- package/src/realtime.ts +298 -0
- package/src/router/decide.d.ts +2 -0
- package/src/router/decide.js +38 -6
- package/src/router.ts +33 -13
- package/src/runtime-config.ts +70 -0
- package/src/storage.ts +131 -0
- package/src/telemetry.ts +115 -22
- package/src/web-compute.ts +342 -0
package/dist/constants.d.ts
CHANGED
|
@@ -33,15 +33,70 @@ export interface HealthResponse {
|
|
|
33
33
|
export declare const HOST_HEADER = "x-platform-host";
|
|
34
34
|
/** Trace propagation header (W3C traceparent is also honored). */
|
|
35
35
|
export declare const TRACE_HEADER = "x-platform-trace";
|
|
36
|
+
/**
|
|
37
|
+
* The secret the router sends a request-mode server (a function URL anyone
|
|
38
|
+
* can call) with each request: the stage's `originSecret`. The SDK answers
|
|
39
|
+
* 403 to a request without it before any app code runs.
|
|
40
|
+
*/
|
|
41
|
+
export declare const ORIGIN_HEADER = "x-platform-origin";
|
|
42
|
+
/**
|
|
43
|
+
* The client's `ip:port` as the edge saw the connection; IPv6 is unbracketed
|
|
44
|
+
* (`2001:db8::7:51234`). CloudFront sets it and replaces any copy a client
|
|
45
|
+
* sends (so does `plat dev`), and servers only take requests from the edge
|
|
46
|
+
* (Web Function endpoints signed ones, request-mode servers those carrying
|
|
47
|
+
* `ORIGIN_HEADER`), so apps can trust it.
|
|
48
|
+
*/
|
|
49
|
+
export declare const VIEWER_ADDRESS_HEADER = "cloudfront-viewer-address";
|
|
50
|
+
/** The client's country (ISO 3166-1 alpha-2), from the edge; absent locally. */
|
|
51
|
+
export declare const VIEWER_COUNTRY_HEADER = "cloudfront-viewer-country";
|
|
52
|
+
/**
|
|
53
|
+
* Partition-key prefix of the SDK's rate-limit counters in a stage's table
|
|
54
|
+
* (`_rl#<limit>#<key>`). Collection names start with a letter, so no
|
|
55
|
+
* document shares it; the data browser leaves these items out.
|
|
56
|
+
*/
|
|
57
|
+
export declare const RATE_LIMIT_PK_PREFIX = "_rl#";
|
|
58
|
+
/** How long the edge's request floor asks a client over it to wait: WAF counts the last minute. */
|
|
59
|
+
export declare const EDGE_RETRY_AFTER_SECONDS = 60;
|
|
60
|
+
/**
|
|
61
|
+
* The control plane worker's invoke job that the edge floor's alarm runs when
|
|
62
|
+
* it goes off (an EventBridge rule in the foundation stack): it turns the floor on.
|
|
63
|
+
*/
|
|
64
|
+
export declare const EDGE_FLOOR_JOB = "edge-floor";
|
|
65
|
+
/**
|
|
66
|
+
* The body of the edge floor's 429 (`limits.edgeRequestsPerMinute`): the SDK's
|
|
67
|
+
* `RateLimited`, so a generated web client decodes it like an app's own 429.
|
|
68
|
+
*/
|
|
69
|
+
export declare const EDGE_RATE_LIMITED_BODY: {
|
|
70
|
+
readonly _tag: 'RateLimited';
|
|
71
|
+
readonly message: "Too many requests. Try again in 60 seconds.";
|
|
72
|
+
readonly retryAfter: 60;
|
|
73
|
+
};
|
|
36
74
|
/** Tags on every AWS resource the engine creates. */
|
|
37
75
|
export declare const TAGS: {
|
|
38
76
|
readonly managed: 'platform:managed';
|
|
39
77
|
readonly app: 'platform:app';
|
|
40
78
|
readonly stage: 'platform:stage';
|
|
79
|
+
/** On resources built per deployment (a service's task definition), so it can be found again. */
|
|
80
|
+
readonly deployment: 'platform:deployment';
|
|
41
81
|
};
|
|
42
82
|
/** The production stage. Its host has no stage suffix. */
|
|
43
83
|
export declare const PROD_STAGE = "prod";
|
|
44
84
|
/** Stage name used by `plat dev` against the AWS Emulator. */
|
|
45
85
|
export declare const LOCAL_STAGE = "local";
|
|
46
|
-
/** Lambda runtime for
|
|
86
|
+
/** Lambda runtime for Web Functions, request-mode servers and worker (Event) Functions. */
|
|
47
87
|
export declare const NODE_RUNTIME = "nodejs24.x";
|
|
88
|
+
/**
|
|
89
|
+
* Base of every container image the platform builds: Node.js 24 on Debian
|
|
90
|
+
* slim, linux/arm64, pinned to one image manifest (not the multi-platform
|
|
91
|
+
* index). The engine copies it from ECR Public into the platform's
|
|
92
|
+
* repository the first time a deploy needs it, so bumping it is a deliberate
|
|
93
|
+
* change: look up the arm64 entry of the tag's index and update both fields.
|
|
94
|
+
*/
|
|
95
|
+
export declare const CONTAINER_BASE_IMAGE: {
|
|
96
|
+
readonly registry: 'public.ecr.aws';
|
|
97
|
+
readonly repository: 'docker/library/node';
|
|
98
|
+
readonly tag: '24-slim';
|
|
99
|
+
readonly digest: 'sha256:5f8fabfed57b75127de2f584593d67a9e8c90e6b0f65652871f9ef0f759c0299';
|
|
100
|
+
};
|
|
101
|
+
/** Environment variable naming the service a container runs (`ais`). */
|
|
102
|
+
export declare const SERVICE_ENV = "PLATFORM_SERVICE";
|
package/dist/constants.js
CHANGED
|
@@ -22,16 +22,71 @@ export const HEALTH_PATH = '/__platform/health';
|
|
|
22
22
|
export const HOST_HEADER = 'x-platform-host';
|
|
23
23
|
/** Trace propagation header (W3C traceparent is also honored). */
|
|
24
24
|
export const TRACE_HEADER = 'x-platform-trace';
|
|
25
|
+
/**
|
|
26
|
+
* The secret the router sends a request-mode server (a function URL anyone
|
|
27
|
+
* can call) with each request: the stage's `originSecret`. The SDK answers
|
|
28
|
+
* 403 to a request without it before any app code runs.
|
|
29
|
+
*/
|
|
30
|
+
export const ORIGIN_HEADER = 'x-platform-origin';
|
|
31
|
+
/**
|
|
32
|
+
* The client's `ip:port` as the edge saw the connection; IPv6 is unbracketed
|
|
33
|
+
* (`2001:db8::7:51234`). CloudFront sets it and replaces any copy a client
|
|
34
|
+
* sends (so does `plat dev`), and servers only take requests from the edge
|
|
35
|
+
* (Web Function endpoints signed ones, request-mode servers those carrying
|
|
36
|
+
* `ORIGIN_HEADER`), so apps can trust it.
|
|
37
|
+
*/
|
|
38
|
+
export const VIEWER_ADDRESS_HEADER = 'cloudfront-viewer-address';
|
|
39
|
+
/** The client's country (ISO 3166-1 alpha-2), from the edge; absent locally. */
|
|
40
|
+
export const VIEWER_COUNTRY_HEADER = 'cloudfront-viewer-country';
|
|
41
|
+
/**
|
|
42
|
+
* Partition-key prefix of the SDK's rate-limit counters in a stage's table
|
|
43
|
+
* (`_rl#<limit>#<key>`). Collection names start with a letter, so no
|
|
44
|
+
* document shares it; the data browser leaves these items out.
|
|
45
|
+
*/
|
|
46
|
+
export const RATE_LIMIT_PK_PREFIX = '_rl#';
|
|
47
|
+
/** How long the edge's request floor asks a client over it to wait: WAF counts the last minute. */
|
|
48
|
+
export const EDGE_RETRY_AFTER_SECONDS = 60;
|
|
49
|
+
/**
|
|
50
|
+
* The control plane worker's invoke job that the edge floor's alarm runs when
|
|
51
|
+
* it goes off (an EventBridge rule in the foundation stack): it turns the floor on.
|
|
52
|
+
*/
|
|
53
|
+
export const EDGE_FLOOR_JOB = 'edge-floor';
|
|
54
|
+
/**
|
|
55
|
+
* The body of the edge floor's 429 (`limits.edgeRequestsPerMinute`): the SDK's
|
|
56
|
+
* `RateLimited`, so a generated web client decodes it like an app's own 429.
|
|
57
|
+
*/
|
|
58
|
+
export const EDGE_RATE_LIMITED_BODY = {
|
|
59
|
+
_tag: 'RateLimited',
|
|
60
|
+
message: `Too many requests. Try again in ${EDGE_RETRY_AFTER_SECONDS} seconds.`,
|
|
61
|
+
retryAfter: EDGE_RETRY_AFTER_SECONDS,
|
|
62
|
+
};
|
|
25
63
|
/** Tags on every AWS resource the engine creates. */
|
|
26
64
|
export const TAGS = {
|
|
27
65
|
managed: 'platform:managed',
|
|
28
66
|
app: 'platform:app',
|
|
29
67
|
stage: 'platform:stage',
|
|
68
|
+
/** On resources built per deployment (a service's task definition), so it can be found again. */
|
|
69
|
+
deployment: 'platform:deployment',
|
|
30
70
|
};
|
|
31
71
|
/** The production stage. Its host has no stage suffix. */
|
|
32
72
|
export const PROD_STAGE = 'prod';
|
|
33
73
|
/** Stage name used by `plat dev` against the AWS Emulator. */
|
|
34
74
|
export const LOCAL_STAGE = 'local';
|
|
35
|
-
/** Lambda runtime for
|
|
75
|
+
/** Lambda runtime for Web Functions, request-mode servers and worker (Event) Functions. */
|
|
36
76
|
export const NODE_RUNTIME = 'nodejs24.x';
|
|
77
|
+
/**
|
|
78
|
+
* Base of every container image the platform builds: Node.js 24 on Debian
|
|
79
|
+
* slim, linux/arm64, pinned to one image manifest (not the multi-platform
|
|
80
|
+
* index). The engine copies it from ECR Public into the platform's
|
|
81
|
+
* repository the first time a deploy needs it, so bumping it is a deliberate
|
|
82
|
+
* change: look up the arm64 entry of the tag's index and update both fields.
|
|
83
|
+
*/
|
|
84
|
+
export const CONTAINER_BASE_IMAGE = {
|
|
85
|
+
registry: 'public.ecr.aws',
|
|
86
|
+
repository: 'docker/library/node',
|
|
87
|
+
tag: '24-slim',
|
|
88
|
+
digest: 'sha256:5f8fabfed57b75127de2f584593d67a9e8c90e6b0f65652871f9ef0f759c0299',
|
|
89
|
+
};
|
|
90
|
+
/** Environment variable naming the service a container runs (`ais`). */
|
|
91
|
+
export const SERVICE_ENV = 'PLATFORM_SERVICE';
|
|
37
92
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,kFAAkF;IAClF,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,WAAW;IACnB,oCAAoC;IACpC,MAAM,EAAE,oCAAoC;IAC5C,8DAA8D;IAC9D,YAAY,EAAE,oCAAoC;IAClD,4EAA4E;IAC5E,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,IAAI;CACP,CAAC;AAEX,6EAA6E;AAC7E,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAchD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAC7C,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAE/C,qDAAqD;AACrD,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,OAAO,EAAE,kBAAkB;IAC3B,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE,gBAAgB;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,kFAAkF;IAClF,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,WAAW;IACnB,oCAAoC;IACpC,MAAM,EAAE,oCAAoC;IAC5C,8DAA8D;IAC9D,YAAY,EAAE,oCAAoC;IAClD,4EAA4E;IAC5E,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,IAAI;CACP,CAAC;AAEX,6EAA6E;AAC7E,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAo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E;CACzE,CAAC;AAEX,wEAAwE;AACxE,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC"}
|
package/dist/email.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** `plat dev`'s local inbox on every app host (served by the local router, never deployed). */
|
|
2
|
+
export declare const EMAIL_INBOX_PATH = "/__platform/mail";
|
|
3
|
+
/** Environment variable with the URL the SDK posts captured mail to (`plat dev`, `plat test`). */
|
|
4
|
+
export declare const LOCAL_MAIL_URL_ENV = "PLATFORM_LOCAL_MAIL_URL";
|
|
5
|
+
/** Recipients per UTC day when `email.dailyLimit` isn't set. */
|
|
6
|
+
export declare const EMAIL_DEFAULT_DAILY_LIMIT = 200;
|
|
7
|
+
/** Previews and local stages get at most this many recipients a day, whatever the app declares. */
|
|
8
|
+
export declare const EMAIL_NON_PROD_DAILY_LIMIT = 50;
|
|
9
|
+
/** SES accepts at most 50 recipients per message. */
|
|
10
|
+
export declare const EMAIL_MAX_RECIPIENTS = 50;
|
|
11
|
+
/** Usage rows outlive their day by this much, so the console can show yesterday. */
|
|
12
|
+
export declare const EMAIL_USAGE_TTL_SECONDS: number;
|
|
13
|
+
/**
|
|
14
|
+
* Local part of the user pool's sender. `login` is a reserved app name, so no
|
|
15
|
+
* app's address can ever be the same.
|
|
16
|
+
*/
|
|
17
|
+
export declare const EMAIL_LOGIN_LOCAL_PART = "login";
|
|
18
|
+
/** A display name for `email.name`: no quotes, angle brackets, backslashes or line breaks. */
|
|
19
|
+
export declare const EMAIL_NAME_PATTERN: RegExp;
|
|
20
|
+
export declare const EMAIL_NAME_MESSAGE = "must be 1-64 characters without quotes, angle brackets, backslashes or line breaks";
|
|
21
|
+
/** The domain every app sends from: `mail.<zone>` (`mail.platform.ericminassian.com`). */
|
|
22
|
+
export declare function emailDomain(zone: string): string;
|
|
23
|
+
/** The custom MAIL FROM (bounce) domain under `domain`, for SPF alignment. */
|
|
24
|
+
export declare function emailMailFromDomain(domain: string): string;
|
|
25
|
+
/** A stage's sender: `todo@<domain>` in prod, `todo--pr-12@<domain>` elsewhere. */
|
|
26
|
+
export declare function emailFromAddress(app: string, stage: string, domain: string): string;
|
|
27
|
+
/** Recipients a stage may send to per UTC day: the declared limit, capped outside prod. */
|
|
28
|
+
export declare function emailDailyLimit(stage: string, declared: number): number;
|
|
29
|
+
/** The UTC day a send counts against (`YYYY-MM-DD`): the usage row's sort key. */
|
|
30
|
+
export declare function emailUsageDay(now: number): string;
|
|
31
|
+
/** `"Name" <address>`, or the bare address. */
|
|
32
|
+
export declare function formatMailbox(address: string, name?: string): string;
|
|
33
|
+
export declare function isEmailAddress(value: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* True for addresses at reserved domains (`alice@example.com`, `bob@app.test`).
|
|
36
|
+
* Deployed stages log these instead of sending them: they always bounce, and
|
|
37
|
+
* bounces from test data would count against the app's reputation.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isReservedEmailDomain(address: string): boolean;
|
|
40
|
+
/** What `Email.send` takes. */
|
|
41
|
+
export interface EmailMessage {
|
|
42
|
+
/** One address or up to 50. Each counts once against the daily limit. */
|
|
43
|
+
readonly to: string | readonly string[];
|
|
44
|
+
readonly subject: string;
|
|
45
|
+
/** Plain-text body. */
|
|
46
|
+
readonly text: string;
|
|
47
|
+
/** HTML body, shown by clients that render HTML (they fall back to `text`). */
|
|
48
|
+
readonly html?: string;
|
|
49
|
+
/** Where replies go; the sending address takes no mail. */
|
|
50
|
+
readonly replyTo?: string | readonly string[];
|
|
51
|
+
}
|
|
52
|
+
/** Why a message wasn't sent. */
|
|
53
|
+
export type EmailNotSentReason =
|
|
54
|
+
/** The stage's recipients for today would pass `email.dailyLimit`. */
|
|
55
|
+
'daily-limit'
|
|
56
|
+
/** SES paused the app's sending (its reputation policy, the owner, or AWS). */
|
|
57
|
+
| 'paused'
|
|
58
|
+
/** The message is invalid, or SES refused it. */
|
|
59
|
+
| 'rejected';
|
|
60
|
+
/** The message's recipients and reply-to addresses, normalized, or why it can't be sent. */
|
|
61
|
+
export declare function checkEmailMessage(m: EmailMessage): {
|
|
62
|
+
ok: true;
|
|
63
|
+
to: string[];
|
|
64
|
+
replyTo: string[];
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
message: string;
|
|
68
|
+
};
|
|
69
|
+
/** One message as the CLI's local inbox keeps it (what the SDK posts to `LOCAL_MAIL_URL_ENV`). */
|
|
70
|
+
export interface CapturedEmail {
|
|
71
|
+
/** Message id, as `Email.send` returned it. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** ISO time it was captured. */
|
|
74
|
+
at: string;
|
|
75
|
+
app: string;
|
|
76
|
+
stage: string;
|
|
77
|
+
/** `"Name" <address>`. */
|
|
78
|
+
from: string;
|
|
79
|
+
to: readonly string[];
|
|
80
|
+
replyTo: readonly string[];
|
|
81
|
+
subject: string;
|
|
82
|
+
text: string;
|
|
83
|
+
html?: string;
|
|
84
|
+
}
|
package/dist/email.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email: transactional mail on Amazon SES.
|
|
3
|
+
*
|
|
4
|
+
* - The foundation verifies one domain, `mail.<zone>` (`emailDomain`), with
|
|
5
|
+
* DKIM, a custom MAIL FROM and DMARC. Every app sends from it.
|
|
6
|
+
* - Each stage that declares `email` is an SES tenant with its own
|
|
7
|
+
* configuration set (both `names.emailTenant`). SES keeps the tenant's
|
|
8
|
+
* suppression list, reports its metrics and pauses it on its own when its
|
|
9
|
+
* bounces or complaints get bad, so one app can't spoil mail for the rest.
|
|
10
|
+
* - The stage role may send only as its tenant and from its own address.
|
|
11
|
+
* - The SDK counts recipients per UTC day against the stage's limit, in the
|
|
12
|
+
* platform's telemetry table (`telemetryKeys.email`).
|
|
13
|
+
* - Under `plat dev` and `plat test` nothing is sent: the SDK posts each
|
|
14
|
+
* message to the CLI, which shows it at `EMAIL_INBOX_PATH`.
|
|
15
|
+
*
|
|
16
|
+
* Isomorphic: the SDK, the engine, the CLI and the control plane share it.
|
|
17
|
+
*/
|
|
18
|
+
import { PROD_STAGE } from './constants.js';
|
|
19
|
+
/** `plat dev`'s local inbox on every app host (served by the local router, never deployed). */
|
|
20
|
+
export const EMAIL_INBOX_PATH = '/__platform/mail';
|
|
21
|
+
/** Environment variable with the URL the SDK posts captured mail to (`plat dev`, `plat test`). */
|
|
22
|
+
export const LOCAL_MAIL_URL_ENV = 'PLATFORM_LOCAL_MAIL_URL';
|
|
23
|
+
/** Recipients per UTC day when `email.dailyLimit` isn't set. */
|
|
24
|
+
export const EMAIL_DEFAULT_DAILY_LIMIT = 200;
|
|
25
|
+
/** Previews and local stages get at most this many recipients a day, whatever the app declares. */
|
|
26
|
+
export const EMAIL_NON_PROD_DAILY_LIMIT = 50;
|
|
27
|
+
/** SES accepts at most 50 recipients per message. */
|
|
28
|
+
export const EMAIL_MAX_RECIPIENTS = 50;
|
|
29
|
+
/** Usage rows outlive their day by this much, so the console can show yesterday. */
|
|
30
|
+
export const EMAIL_USAGE_TTL_SECONDS = 3 * 24 * 3600;
|
|
31
|
+
/**
|
|
32
|
+
* Local part of the user pool's sender. `login` is a reserved app name, so no
|
|
33
|
+
* app's address can ever be the same.
|
|
34
|
+
*/
|
|
35
|
+
export const EMAIL_LOGIN_LOCAL_PART = 'login';
|
|
36
|
+
/** A display name for `email.name`: no quotes, angle brackets, backslashes or line breaks. */
|
|
37
|
+
export const EMAIL_NAME_PATTERN = /^[^"<>\\\r\n]{1,64}$/;
|
|
38
|
+
export const EMAIL_NAME_MESSAGE = 'must be 1-64 characters without quotes, angle brackets, backslashes or line breaks';
|
|
39
|
+
/** The domain every app sends from: `mail.<zone>` (`mail.platform.ericminassian.com`). */
|
|
40
|
+
export function emailDomain(zone) {
|
|
41
|
+
return `mail.${zone}`;
|
|
42
|
+
}
|
|
43
|
+
/** The custom MAIL FROM (bounce) domain under `domain`, for SPF alignment. */
|
|
44
|
+
export function emailMailFromDomain(domain) {
|
|
45
|
+
return `bounce.${domain}`;
|
|
46
|
+
}
|
|
47
|
+
/** A stage's sender: `todo@<domain>` in prod, `todo--pr-12@<domain>` elsewhere. */
|
|
48
|
+
export function emailFromAddress(app, stage, domain) {
|
|
49
|
+
return stage === PROD_STAGE ? `${app}@${domain}` : `${app}--${stage}@${domain}`;
|
|
50
|
+
}
|
|
51
|
+
/** Recipients a stage may send to per UTC day: the declared limit, capped outside prod. */
|
|
52
|
+
export function emailDailyLimit(stage, declared) {
|
|
53
|
+
return stage === PROD_STAGE ? declared : Math.min(declared, EMAIL_NON_PROD_DAILY_LIMIT);
|
|
54
|
+
}
|
|
55
|
+
/** The UTC day a send counts against (`YYYY-MM-DD`): the usage row's sort key. */
|
|
56
|
+
export function emailUsageDay(now) {
|
|
57
|
+
return new Date(now).toISOString().slice(0, 10);
|
|
58
|
+
}
|
|
59
|
+
/** `"Name" <address>`, or the bare address. */
|
|
60
|
+
export function formatMailbox(address, name) {
|
|
61
|
+
return name ? `"${name}" <${address}>` : address;
|
|
62
|
+
}
|
|
63
|
+
// ---------------------------------------------------------------- recipients
|
|
64
|
+
/**
|
|
65
|
+
* A pragmatic address check: one `@`, no whitespace, quotes, angle brackets,
|
|
66
|
+
* commas or semicolons, a dotted domain, and SMTP's length limits. SES checks
|
|
67
|
+
* the rest.
|
|
68
|
+
*/
|
|
69
|
+
const ADDRESS = /^[^\s@"<>(),;:\\[\]]{1,64}@(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+$/;
|
|
70
|
+
export function isEmailAddress(value) {
|
|
71
|
+
return ADDRESS.test(value);
|
|
72
|
+
}
|
|
73
|
+
/** Domains that can never receive mail (RFC 2606 and RFC 6761). */
|
|
74
|
+
const RESERVED_DOMAINS = ['example.com', 'example.net', 'example.org'];
|
|
75
|
+
const RESERVED_TLDS = new Set(['test', 'example', 'invalid', 'localhost']);
|
|
76
|
+
/**
|
|
77
|
+
* True for addresses at reserved domains (`alice@example.com`, `bob@app.test`).
|
|
78
|
+
* Deployed stages log these instead of sending them: they always bounce, and
|
|
79
|
+
* bounces from test data would count against the app's reputation.
|
|
80
|
+
*/
|
|
81
|
+
export function isReservedEmailDomain(address) {
|
|
82
|
+
const domain = address.slice(address.lastIndexOf('@') + 1).toLowerCase();
|
|
83
|
+
if (RESERVED_DOMAINS.some((d) => domain === d || domain.endsWith(`.${d}`)))
|
|
84
|
+
return true;
|
|
85
|
+
const tld = domain.slice(domain.lastIndexOf('.') + 1);
|
|
86
|
+
return RESERVED_TLDS.has(tld) || domain === 'localhost';
|
|
87
|
+
}
|
|
88
|
+
const asList = (v) => v === undefined ? [] : typeof v === 'string' ? [v] : [...v];
|
|
89
|
+
/** The message's recipients and reply-to addresses, normalized, or why it can't be sent. */
|
|
90
|
+
export function checkEmailMessage(m) {
|
|
91
|
+
const to = asList(m.to).map((a) => a.trim());
|
|
92
|
+
const replyTo = asList(m.replyTo).map((a) => a.trim());
|
|
93
|
+
if (to.length === 0)
|
|
94
|
+
return { ok: false, message: 'email.send needs at least one recipient in `to`' };
|
|
95
|
+
if (to.length > EMAIL_MAX_RECIPIENTS)
|
|
96
|
+
return {
|
|
97
|
+
ok: false,
|
|
98
|
+
message: `email.send takes at most ${EMAIL_MAX_RECIPIENTS} recipients (got ${to.length}); send several messages`,
|
|
99
|
+
};
|
|
100
|
+
const bad = [...to, ...replyTo].find((a) => !isEmailAddress(a));
|
|
101
|
+
if (bad !== undefined)
|
|
102
|
+
return { ok: false, message: `email.send: "${bad}" is not an email address` };
|
|
103
|
+
if (!m.subject.trim())
|
|
104
|
+
return { ok: false, message: 'email.send needs a subject' };
|
|
105
|
+
if (/[\r\n]/.test(m.subject))
|
|
106
|
+
return { ok: false, message: 'email.send: the subject must be one line' };
|
|
107
|
+
if (!m.text && !m.html)
|
|
108
|
+
return { ok: false, message: 'email.send needs a `text` body' };
|
|
109
|
+
return { ok: true, to, replyTo };
|
|
110
|
+
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