@ericminassian/platform-core 0.2.0 → 0.4.0
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 +1847 -212
- package/dist/api.js +694 -1
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +19 -0
- package/dist/auth.js +32 -0
- 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 +69 -13
- 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 +70 -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 +21 -1
- package/dist/config.js +16 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +67 -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/fingerprint.d.ts +9 -0
- package/dist/fingerprint.js +19 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -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 +357 -112
- package/dist/manifest.js +270 -72
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +93 -6
- package/dist/naming.js +98 -6
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +7792 -0
- package/dist/platform-api.js +455 -0
- package/dist/platform-api.js.map +1 -0
- 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 +7 -1
- package/dist/router/decide.js +42 -5
- 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 +55 -0
- package/dist/storage.js +112 -0
- package/dist/storage.js.map +1 -0
- package/dist/telemetry.d.ts +350 -83
- package/dist/telemetry.js +188 -15
- 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 +28 -8
- package/src/api.ts +864 -238
- package/src/auth.ts +37 -0
- package/src/base64url.ts +13 -0
- package/src/bindings.ts +74 -7
- package/src/cloudfront-function.ts +70 -2
- package/src/compute.ts +86 -0
- package/src/config.ts +34 -2
- package/src/constants.ts +76 -1
- package/src/email.ts +168 -0
- package/src/fingerprint.ts +20 -0
- package/src/index.ts +6 -0
- package/src/jobs.ts +281 -0
- package/src/manifest.ts +542 -114
- package/src/naming.ts +103 -8
- package/src/platform-api.ts +630 -0
- package/src/realtime.ts +298 -0
- package/src/router/decide.d.ts +7 -1
- package/src/router/decide.js +42 -5
- package/src/router.ts +33 -13
- package/src/runtime-config.ts +70 -0
- package/src/storage.ts +120 -0
- package/src/telemetry.ts +198 -93
- package/src/web-compute.ts +342 -0
package/dist/constants.d.ts
CHANGED
|
@@ -18,19 +18,85 @@ export declare const PLATFORM_DEFAULTS: {
|
|
|
18
18
|
/** Prefix for every platform-owned path (auth, health) on every app host. */
|
|
19
19
|
export declare const PLATFORM_PATH_PREFIX = "/__platform/";
|
|
20
20
|
export declare const HEALTH_PATH = "/__platform/health";
|
|
21
|
+
/**
|
|
22
|
+
* Body served at `HEALTH_PATH`: by the SDK when the stage has a server, else
|
|
23
|
+
* by the edge router from its route record. `revision` is the deployment id,
|
|
24
|
+
* so a poller can tell which deployment answered.
|
|
25
|
+
*/
|
|
26
|
+
export interface HealthResponse {
|
|
27
|
+
ok: true;
|
|
28
|
+
app: string;
|
|
29
|
+
stage: string;
|
|
30
|
+
revision: string;
|
|
31
|
+
}
|
|
21
32
|
/** Header the router sets so apps (and the cache key) see the public host. */
|
|
22
33
|
export declare const HOST_HEADER = "x-platform-host";
|
|
23
34
|
/** Trace propagation header (W3C traceparent is also honored). */
|
|
24
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
|
+
};
|
|
25
74
|
/** Tags on every AWS resource the engine creates. */
|
|
26
75
|
export declare const TAGS: {
|
|
27
76
|
readonly managed: 'platform:managed';
|
|
28
77
|
readonly app: 'platform:app';
|
|
29
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';
|
|
30
81
|
};
|
|
31
82
|
/** The production stage. Its host has no stage suffix. */
|
|
32
83
|
export declare const PROD_STAGE = "prod";
|
|
33
84
|
/** Stage name used by `plat dev` against the AWS Emulator. */
|
|
34
85
|
export declare const LOCAL_STAGE = "local";
|
|
35
|
-
/** Lambda runtime for
|
|
86
|
+
/** Lambda runtime for Web Functions, request-mode servers and worker (Event) Functions. */
|
|
36
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;
|
|
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,E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,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ,EAAE,gBAAgB;IAC1B,UAAU,EAAE,qBAAqB;IACjC,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,yEAAyE;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
|
+
}
|
|
111
|
+
//# sourceMappingURL=email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.js","sourceRoot":"","sources":["../src/email.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,+FAA+F;AAC/F,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AACnD,kGAAkG;AAClG,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AAE5D,gEAAgE;AAChE,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,mGAAmG;AACnG,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAC7C,qDAAqD;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,oFAAoF;AACpF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACrD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAE9C,8FAA8F;AAC9F,MAAM,CAAC,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAC7B,oFAAoF,CAAC;AAEvF,0FAA0F;AAC1F,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,QAAQ,IAAI,EAAE,CAAC;AACxB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,OAAO,UAAU,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,KAAa,EAAE,MAAc;I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ACjH,CAAC;IACJ,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,GAAG,2BAA2B,EAAE,CAAC;IACrG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC;IACnF,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,0CAA0C,EAAE,CAAC;IACxG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,gCAAgC,EAAE,CAAC;IACxF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable short hashes (FNV-1a 32-bit): no crypto dependency so the SDK stays
|
|
3
|
+
* tiny. Their own module so naming (and the `./naming` subpath) doesn't pull
|
|
4
|
+
* in Effect through telemetry.
|
|
5
|
+
*/
|
|
6
|
+
/** FNV-1a of `s`'s code points, as an unsigned 32-bit integer. */
|
|
7
|
+
export declare function fnv1a(s: string): number;
|
|
8
|
+
/** `fnv1a` of the parts joined with `|`, as 8 hex digits. */
|
|
9
|
+
export declare function fingerprint(parts: readonly string[]): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable short hashes (FNV-1a 32-bit): no crypto dependency so the SDK stays
|
|
3
|
+
* tiny. Their own module so naming (and the `./naming` subpath) doesn't pull
|
|
4
|
+
* in Effect through telemetry.
|
|
5
|
+
*/
|
|
6
|
+
/** FNV-1a of `s`'s code points, as an unsigned 32-bit integer. */
|
|
7
|
+
export function fnv1a(s) {
|
|
8
|
+
let h = 0x811c9dc5;
|
|
9
|
+
for (const ch of s) {
|
|
10
|
+
h ^= ch.codePointAt(0);
|
|
11
|
+
h = Math.imul(h, 0x01000193) >>> 0;
|
|
12
|
+
}
|
|
13
|
+
return h;
|
|
14
|
+
}
|
|
15
|
+
/** `fnv1a` of the parts joined with `|`, as 8 hex digits. */
|
|
16
|
+
export function fingerprint(parts) {
|
|
17
|
+
return fnv1a(parts.join('|')).toString(16).padStart(8, '0');
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,MAAM,UAAU,KAAK,CAAC,CAAS;IAC7B,IAAI,CAAC,GAAG,UAAU,CAAC;IACnB,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QACnB,CAAC,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QACxB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAAC,KAAwB;IAClD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export * from './api.ts';
|
|
2
2
|
export * from './auth.ts';
|
|
3
3
|
export * from './bindings.ts';
|
|
4
|
+
export * from './compute.ts';
|
|
4
5
|
export * from './config.ts';
|
|
5
6
|
export * from './constants.ts';
|
|
6
7
|
export * from './cron.ts';
|
|
8
|
+
export * from './email.ts';
|
|
7
9
|
export * from './ids.ts';
|
|
10
|
+
export * from './jobs.ts';
|
|
8
11
|
export * from './manifest.ts';
|
|
9
12
|
export * from './naming.ts';
|
|
13
|
+
export * from './realtime.ts';
|
|
10
14
|
export * from './router.ts';
|
|
11
15
|
export * from './runtime-config.ts';
|
|
16
|
+
export * from './storage.ts';
|
|
12
17
|
export * from './telemetry.ts';
|
|
18
|
+
export * from './web-compute.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
export * from './api.js';
|
|
2
2
|
export * from './auth.js';
|
|
3
3
|
export * from './bindings.js';
|
|
4
|
+
export * from './compute.js';
|
|
4
5
|
export * from './config.js';
|
|
5
6
|
export * from './constants.js';
|
|
6
7
|
export * from './cron.js';
|
|
8
|
+
export * from './email.js';
|
|
7
9
|
export * from './ids.js';
|
|
10
|
+
export * from './jobs.js';
|
|
8
11
|
export * from './manifest.js';
|
|
9
12
|
export * from './naming.js';
|
|
13
|
+
export * from './realtime.js';
|
|
10
14
|
export * from './router.js';
|
|
11
15
|
export * from './runtime-config.js';
|
|
16
|
+
export * from './storage.js';
|
|
12
17
|
export * from './telemetry.js';
|
|
18
|
+
export * from './web-compute.js';
|
|
13
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
package/dist/jobs.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { HandlerKind } from './manifest.ts';
|
|
2
|
+
/** Marker on every job payload the platform sends to a worker function. */
|
|
3
|
+
export declare const JOB_MARKER = "job";
|
|
4
|
+
/** What a worker function receives for a queue message, a retry, or a delayed send. */
|
|
5
|
+
export interface JobPayload {
|
|
6
|
+
__platform: typeof JOB_MARKER;
|
|
7
|
+
kind: HandlerKind;
|
|
8
|
+
/** Queue or cron key, or event type. */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Stable across retries: the message's id, the event's id, or the cron run's. */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Which delivery this is, from 1. */
|
|
13
|
+
attempt: number;
|
|
14
|
+
/** Epoch ms when the message was sent, the event published or the cron fired. */
|
|
15
|
+
sentAt: number;
|
|
16
|
+
/** A queue message's body. */
|
|
17
|
+
body?: unknown;
|
|
18
|
+
/** An event's detail. */
|
|
19
|
+
detail?: unknown;
|
|
20
|
+
trace?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The largest job payload, in bytes of JSON. Retries and delayed sends go
|
|
24
|
+
* through a Scheduler schedule, whose input is capped at 256 KB, and a dead
|
|
25
|
+
* letter wraps the payload with its error, so this leaves room for both.
|
|
26
|
+
*/
|
|
27
|
+
export declare const JOB_PAYLOAD_MAX_BYTES: number;
|
|
28
|
+
/** Attempts per kind when a handler sets none. Lambda retried events and crons twice before. */
|
|
29
|
+
export declare const DEFAULT_ATTEMPTS: Readonly<Record<HandlerKind, number>>;
|
|
30
|
+
export declare const MAX_ATTEMPTS = 100;
|
|
31
|
+
/** The longest delay `send` takes: a one-shot schedule can be any time ahead, a year is plenty. */
|
|
32
|
+
export declare const MAX_JOB_DELAY_SECONDS: number;
|
|
33
|
+
/**
|
|
34
|
+
* Scheduler fires a one-shot schedule within about a minute of its time, and
|
|
35
|
+
* refuses times in the past, so a delayed send or retry is scheduled at least
|
|
36
|
+
* this far ahead.
|
|
37
|
+
*/
|
|
38
|
+
export declare const MIN_SCHEDULE_LEAD_SECONDS = 60;
|
|
39
|
+
/** Seconds before attempt `failed + 1`: 1, 2, 4 … minutes, at most an hour. */
|
|
40
|
+
export declare function retryDelaySeconds(failed: number): number;
|
|
41
|
+
/** `kind:name`, the key bindings use for a handler. */
|
|
42
|
+
export declare const handlerKey: (kind: HandlerKind, name: string) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Name of the one-shot schedule for a retry or delayed send (≤ 64 chars of
|
|
45
|
+
* Scheduler's alphabet). It leads with `_`, which no cron key (a cron's own
|
|
46
|
+
* schedule) or service stop schedule (`<key>--stop`) starts with, then the
|
|
47
|
+
* kind and queue or cron key, so the console can count what's waiting per
|
|
48
|
+
* queue with a name prefix. Event types can be long and contain `:`, so they
|
|
49
|
+
* are hashed.
|
|
50
|
+
*/
|
|
51
|
+
export declare function jobScheduleName(kind: HandlerKind, name: string, id: string): string;
|
|
52
|
+
export declare function jobSchedulePrefix(kind: HandlerKind, name: string): string;
|
|
53
|
+
export declare const isJobSchedule: (name: string) => boolean;
|
|
54
|
+
/** One-shot schedule expression for `at` (UTC, whole seconds). */
|
|
55
|
+
export declare function atExpression(at: Date): string;
|
|
56
|
+
/** What the SDK writes to the dead-letter queue when a handler failed its last attempt. */
|
|
57
|
+
export interface DeadLetter {
|
|
58
|
+
v: 1;
|
|
59
|
+
job: JobPayload;
|
|
60
|
+
/** Epoch ms. */
|
|
61
|
+
failedAt: number;
|
|
62
|
+
error: {
|
|
63
|
+
name: string;
|
|
64
|
+
message: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** A dead-letter queue message, whoever wrote it, in the terms the console shows. */
|
|
68
|
+
export interface DeadLetterView {
|
|
69
|
+
/** `invoke` is a direct `invokeJob` call that crashed or timed out. */
|
|
70
|
+
kind: HandlerKind | 'invoke';
|
|
71
|
+
name: string;
|
|
72
|
+
/** Deliveries made, when known. */
|
|
73
|
+
attempts: number | null;
|
|
74
|
+
error: {
|
|
75
|
+
name: string;
|
|
76
|
+
message: string;
|
|
77
|
+
};
|
|
78
|
+
/** Epoch ms. */
|
|
79
|
+
failedAt: number | null;
|
|
80
|
+
/** Who gave up: the SDK, Lambda (crash, timeout, too old), Scheduler or EventBridge (couldn't deliver). */
|
|
81
|
+
source: 'sdk' | 'lambda' | 'scheduler' | 'eventbridge';
|
|
82
|
+
/** What redriving sends, to the function the job's handler runs in now. */
|
|
83
|
+
redrive: JobPayload | {
|
|
84
|
+
__platform: 'invoke';
|
|
85
|
+
name: string;
|
|
86
|
+
payload: unknown;
|
|
87
|
+
trace?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** SQS message attributes as the SDK returns them. */
|
|
91
|
+
type Attributes = Record<string, {
|
|
92
|
+
StringValue?: string;
|
|
93
|
+
} | undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* Normalizes anything a worker function can receive into the job it stands
|
|
96
|
+
* for: a job payload as is, an EventBridge event, or a cron firing. `id` is
|
|
97
|
+
* used when the input carries none (a cron firing). Undefined for anything
|
|
98
|
+
* else, such as a direct `invoke`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function toJob(input: unknown, id: string, now: number): JobPayload | undefined;
|
|
101
|
+
/** Reads a dead-letter queue message; null for one the platform didn't write. */
|
|
102
|
+
export declare function readDeadLetter(body: string, attributes?: Attributes): DeadLetterView | null;
|
|
103
|
+
/**
|
|
104
|
+
* The oldest `@ericminassian/platform` whose bundles this platform deploys:
|
|
105
|
+
* jobs became pushed (bindings v2) in 0.4.0, and an older worker can't read
|
|
106
|
+
* them.
|
|
107
|
+
*/
|
|
108
|
+
export declare const MIN_SDK_VERSION = "0.4.0";
|
|
109
|
+
/** Whether bundles built with SDK `version` can be deployed (undefined: a CLI older than 0.4.0 sent none). */
|
|
110
|
+
export declare function sdkSupported(version: string | undefined): boolean;
|
|
111
|
+
export {};
|