@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.
Files changed (89) hide show
  1. package/dist/api.d.ts +1847 -212
  2. package/dist/api.js +694 -1
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.d.ts +19 -0
  5. package/dist/auth.js +32 -0
  6. package/dist/auth.js.map +1 -1
  7. package/dist/base64url.d.ts +3 -0
  8. package/dist/base64url.js +15 -0
  9. package/dist/base64url.js.map +1 -0
  10. package/dist/bindings.d.ts +69 -13
  11. package/dist/bindings.js +1 -1
  12. package/dist/bindings.js.map +1 -1
  13. package/dist/cloudfront-function.d.ts +5 -1
  14. package/dist/cloudfront-function.js +70 -2
  15. package/dist/cloudfront-function.js.map +1 -1
  16. package/dist/compute.d.ts +52 -0
  17. package/dist/compute.js +65 -0
  18. package/dist/compute.js.map +1 -0
  19. package/dist/config.d.ts +21 -1
  20. package/dist/config.js +16 -0
  21. package/dist/config.js.map +1 -1
  22. package/dist/constants.d.ts +67 -1
  23. package/dist/constants.js +56 -1
  24. package/dist/constants.js.map +1 -1
  25. package/dist/email.d.ts +84 -0
  26. package/dist/email.js +111 -0
  27. package/dist/email.js.map +1 -0
  28. package/dist/fingerprint.d.ts +9 -0
  29. package/dist/fingerprint.js +19 -0
  30. package/dist/fingerprint.js.map +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +6 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/jobs.d.ts +111 -0
  35. package/dist/jobs.js +214 -0
  36. package/dist/jobs.js.map +1 -0
  37. package/dist/manifest.d.ts +357 -112
  38. package/dist/manifest.js +270 -72
  39. package/dist/manifest.js.map +1 -1
  40. package/dist/naming.d.ts +93 -6
  41. package/dist/naming.js +98 -6
  42. package/dist/naming.js.map +1 -1
  43. package/dist/platform-api.d.ts +7792 -0
  44. package/dist/platform-api.js +455 -0
  45. package/dist/platform-api.js.map +1 -0
  46. package/dist/realtime.d.ts +139 -0
  47. package/dist/realtime.js +201 -0
  48. package/dist/realtime.js.map +1 -0
  49. package/dist/router/decide.d.ts +7 -1
  50. package/dist/router/decide.js +42 -5
  51. package/dist/router.d.ts +35 -13
  52. package/dist/router.js +36 -0
  53. package/dist/router.js.map +1 -1
  54. package/dist/runtime-config.d.ts +57 -0
  55. package/dist/runtime-config.js +12 -0
  56. package/dist/runtime-config.js.map +1 -1
  57. package/dist/storage.d.ts +55 -0
  58. package/dist/storage.js +112 -0
  59. package/dist/storage.js.map +1 -0
  60. package/dist/telemetry.d.ts +350 -83
  61. package/dist/telemetry.js +188 -15
  62. package/dist/telemetry.js.map +1 -1
  63. package/dist/web-compute.d.ts +191 -0
  64. package/dist/web-compute.js +257 -0
  65. package/dist/web-compute.js.map +1 -0
  66. package/package.json +28 -8
  67. package/src/api.ts +864 -238
  68. package/src/auth.ts +37 -0
  69. package/src/base64url.ts +13 -0
  70. package/src/bindings.ts +74 -7
  71. package/src/cloudfront-function.ts +70 -2
  72. package/src/compute.ts +86 -0
  73. package/src/config.ts +34 -2
  74. package/src/constants.ts +76 -1
  75. package/src/email.ts +168 -0
  76. package/src/fingerprint.ts +20 -0
  77. package/src/index.ts +6 -0
  78. package/src/jobs.ts +281 -0
  79. package/src/manifest.ts +542 -114
  80. package/src/naming.ts +103 -8
  81. package/src/platform-api.ts +630 -0
  82. package/src/realtime.ts +298 -0
  83. package/src/router/decide.d.ts +7 -1
  84. package/src/router/decide.js +42 -5
  85. package/src/router.ts +33 -13
  86. package/src/runtime-config.ts +70 -0
  87. package/src/storage.ts +120 -0
  88. package/src/telemetry.ts +198 -93
  89. package/src/web-compute.ts +342 -0
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Realtime: server-to-browser pub/sub on AWS AppSync Events.
3
+ *
4
+ * - One Event API serves the platform; each stage that declares `realtime`
5
+ * gets a channel namespace (`names.realtimeNamespace`).
6
+ * - Browsers connect to `wss://<app host>/__platform/realtime`, which the edge
7
+ * router passes to AppSync, and subscribe there. They never publish: the
8
+ * stage's server and worker publish with its IAM role.
9
+ * - `subscribe: 'public'` stages subscribe with the platform's API key;
10
+ * `'signed-in'` stages with a short-lived token from the app's server
11
+ * (`REALTIME_TOKEN_PATH`), checked by the platform's Lambda authorizer.
12
+ *
13
+ * Everything here is isomorphic (WebCrypto, no Node imports): the SDK, the
14
+ * authorizer and the browser client share it.
15
+ */
16
+ import { base64url, fromBase64url } from './base64url.js';
17
+ /** Where browsers connect (WebSocket) and read their `RealtimeClientConfig` (GET). The router answers both. */
18
+ export const REALTIME_PATH = '/__platform/realtime';
19
+ /** Where signed-in browsers get a `RealtimeToken`; served by the SDK on the app's server. */
20
+ export const REALTIME_TOKEN_PATH = '/__platform/realtime/token';
21
+ /**
22
+ * Key of the platform's realtime entry (`RealtimeEdgeEntry`) in the route
23
+ * store. Not a hostname, so it can never collide with a route record.
24
+ */
25
+ export const REALTIME_KVS_KEY = '__platform/realtime';
26
+ /** AppSync's paths on its HTTP and realtime domains. */
27
+ export const APPSYNC_PUBLISH_PATH = '/event';
28
+ export const APPSYNC_REALTIME_PATH = '/event/realtime';
29
+ /** Subprotocol every AppSync Events WebSocket offers (the auth header rides in a second one). */
30
+ export const APPSYNC_SUBPROTOCOL = 'aws-appsync-event-ws';
31
+ /** AppSync accepts at most this many events per publish request. */
32
+ export const REALTIME_PUBLISH_BATCH = 5;
33
+ /** AppSync rejects a single event larger than this many bytes. */
34
+ export const REALTIME_MAX_EVENT_BYTES = 240 * 1024;
35
+ // ---------------------------------------------------------------- channels
36
+ /**
37
+ * One segment of a channel: what AppSync allows, lowercased (a-z, 0-9,
38
+ * hyphens; starts and ends with a letter or digit; at most 50 chars).
39
+ */
40
+ const SEGMENT = '[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?';
41
+ /**
42
+ * A channel as app code names it: 1-4 segments (`board`, `boards/b1`). The
43
+ * stage's namespace is AppSync's first segment and AppSync allows five.
44
+ */
45
+ export const CHANNEL_PATTERN = new RegExp(`^${SEGMENT}(?:/${SEGMENT}){0,3}$`);
46
+ /** A declared channel in `plat.config.ts`: a channel, or a prefix of 1-3 segments ending in `/*`. */
47
+ export const CHANNEL_DECLARATION_PATTERN = new RegExp(`^${SEGMENT}(?:/${SEGMENT}){0,3}$|^${SEGMENT}(?:/${SEGMENT}){0,2}/\\*$`);
48
+ export const CHANNEL_MESSAGE = 'must be 1-4 segments of a-z, 0-9 and hyphens separated by "/", optionally ending in "/*"';
49
+ /**
50
+ * Channels under `user/<id>` are private to the signed-in user with that id;
51
+ * they can only be declared as `user/*`, and only with `subscribe: 'signed-in'`.
52
+ */
53
+ export const USER_CHANNEL_PREFIX = 'user';
54
+ /** Whether `channel` (or a wildcard subscription like `boards/*`) falls under the declared `pattern`. */
55
+ export function channelMatches(pattern, channel) {
56
+ if (!pattern.endsWith('/*'))
57
+ return pattern === channel;
58
+ const prefix = pattern.slice(0, -1); // keeps the trailing "/"
59
+ return channel.startsWith(prefix) && channel.length > prefix.length;
60
+ }
61
+ /** The declared pattern a channel (or wildcard subscription) belongs to, if any. */
62
+ export function declaredChannel(patterns, channel) {
63
+ return patterns.find((p) => channelMatches(p, channel));
64
+ }
65
+ /** A channel app code may publish to: concrete (no wildcard) and well formed. */
66
+ export function isChannel(channel) {
67
+ return CHANNEL_PATTERN.test(channel);
68
+ }
69
+ /** A channel a browser may subscribe to: a channel, or a declared-style `prefix/*` wildcard. */
70
+ export function isSubscription(channel) {
71
+ return CHANNEL_DECLARATION_PATTERN.test(channel);
72
+ }
73
+ /** AppSync's channel path for an app channel: `/<namespace>/<channel>`. */
74
+ export function channelPath(namespace, channel) {
75
+ return `/${namespace}/${channel}`;
76
+ }
77
+ /** The app channel inside an AppSync channel path, or undefined if it's in another namespace. */
78
+ export function appChannel(namespace, path) {
79
+ const prefix = `/${namespace}/`;
80
+ return path.startsWith(prefix) ? path.slice(prefix.length) : undefined;
81
+ }
82
+ /**
83
+ * Problems with a stage's realtime declaration, as messages for the
84
+ * `realtime` path of `plat.config.ts`. Shared by manifest validation and tests.
85
+ */
86
+ export function realtimeIssues(r) {
87
+ const issues = [];
88
+ if (r.channels.length === 0)
89
+ issues.push({ path: ['channels'], message: 'declare at least one channel, e.g. `board: channel<T>()`' });
90
+ if (r.subscribe === 'signed-in' && !r.auth)
91
+ issues.push({ path: ['subscribe'], message: "'signed-in' needs `auth: true`" });
92
+ if (r.subscribe === 'signed-in' && !r.server)
93
+ issues.push({
94
+ path: ['subscribe'],
95
+ message: "'signed-in' needs `web.server`: it issues the subscribe tokens",
96
+ });
97
+ for (const c of r.channels) {
98
+ const first = c.split('/')[0];
99
+ if (first !== USER_CHANNEL_PREFIX)
100
+ continue;
101
+ if (c !== `${USER_CHANNEL_PREFIX}/*`)
102
+ issues.push({
103
+ path: ['channels', c],
104
+ message: `"${USER_CHANNEL_PREFIX}" channels are private to one user: declare them as "${USER_CHANNEL_PREFIX}/*"`,
105
+ });
106
+ else if (r.subscribe !== 'signed-in')
107
+ issues.push({
108
+ path: ['channels', c],
109
+ message: `"${USER_CHANNEL_PREFIX}/*" channels are private to one user, so they need subscribe: 'signed-in'`,
110
+ });
111
+ }
112
+ return issues;
113
+ }
114
+ /**
115
+ * Whether a signed-in user may subscribe to an app channel (or wildcard).
116
+ * Channels under `user/<id>` belong to that user alone; a wildcard that could
117
+ * reach another user's channels (`*`, `user/*`) is refused. Every other
118
+ * channel is open to any signed-in user of the app.
119
+ */
120
+ export function canSubscribe(userId, channel) {
121
+ if (!isSubscription(channel))
122
+ return false;
123
+ const [first, second] = channel.split('/');
124
+ if (first !== USER_CHANNEL_PREFIX)
125
+ return true;
126
+ return second === userId;
127
+ }
128
+ const TOKEN_PREFIX = 'pt1';
129
+ /** Lets AppSync refuse malformed tokens before invoking the authorizer (`identityValidationExpression`). */
130
+ export const REALTIME_TOKEN_PATTERN = '^pt1\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$';
131
+ /** How long a subscribe token lasts. Open subscriptions outlive it; new ones need a fresh token. */
132
+ export const REALTIME_TOKEN_TTL_SECONDS = 15 * 60;
133
+ const HKDF_INFO = 'platform:realtime-token:v1';
134
+ const encoder = new TextEncoder();
135
+ /** The HMAC key for a stage's tokens, derived from its stage key (base64url) with HKDF. */
136
+ async function tokenKey(stageKey) {
137
+ const raw = await crypto.subtle.importKey('raw', fromBase64url(stageKey), 'HKDF', false, ['deriveKey']);
138
+ return crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(0), info: encoder.encode(HKDF_INFO) }, raw, { name: 'HMAC', hash: 'SHA-256', length: 256 }, false, ['sign', 'verify']);
139
+ }
140
+ /** A signed subscribe token: `pt1.<claims>.<HMAC-SHA256>`, all base64url. */
141
+ export async function signRealtimeToken(stageKey, claims) {
142
+ const body = `${TOKEN_PREFIX}.${base64url(encoder.encode(JSON.stringify(claims)))}`;
143
+ const sig = await crypto.subtle.sign('HMAC', await tokenKey(stageKey), encoder.encode(body));
144
+ return `${body}.${base64url(new Uint8Array(sig))}`;
145
+ }
146
+ /**
147
+ * The claims of a token, unverified: the authorizer needs `a` and `s` to find
148
+ * the stage key it then verifies with. Undefined when malformed.
149
+ */
150
+ export function peekRealtimeToken(token) {
151
+ const parts = token.split('.');
152
+ if (parts.length !== 3 || parts[0] !== TOKEN_PREFIX)
153
+ return undefined;
154
+ try {
155
+ const c = JSON.parse(new TextDecoder().decode(fromBase64url(parts[1])));
156
+ if (typeof c.a !== 'string' ||
157
+ typeof c.s !== 'string' ||
158
+ typeof c.u !== 'string' ||
159
+ typeof c.e !== 'number')
160
+ return undefined;
161
+ return { a: c.a, s: c.s, u: c.u, e: c.e };
162
+ }
163
+ catch {
164
+ return undefined;
165
+ }
166
+ }
167
+ /** The claims, if the signature is the stage key's and the token hasn't expired. */
168
+ export async function verifyRealtimeToken(stageKey, token, nowSeconds) {
169
+ const claims = peekRealtimeToken(token);
170
+ if (!claims || claims.e <= nowSeconds)
171
+ return undefined;
172
+ const dot = token.lastIndexOf('.');
173
+ let sig;
174
+ try {
175
+ sig = fromBase64url(token.slice(dot + 1));
176
+ }
177
+ catch {
178
+ return undefined;
179
+ }
180
+ const ok = await crypto.subtle.verify('HMAC', await tokenKey(stageKey), sig, encoder.encode(token.slice(0, dot)));
181
+ return ok ? claims : undefined;
182
+ }
183
+ /**
184
+ * The authorizer's decision for a verified token (pure, so it's unit-tested
185
+ * here and the Lambda only adds SSM and AppSync plumbing).
186
+ *
187
+ * - Connect: any valid token.
188
+ * - Subscribe: the stage's own namespace, and `canSubscribe`.
189
+ * - Publish: never; browsers only subscribe (servers publish with IAM).
190
+ */
191
+ export function authorizeRealtime(input) {
192
+ if (input.operation === 'EVENT_CONNECT')
193
+ return true;
194
+ if (input.operation !== 'EVENT_SUBSCRIBE')
195
+ return false;
196
+ if (input.channelNamespace !== input.namespace || !input.channel)
197
+ return false;
198
+ const channel = appChannel(input.namespace, input.channel);
199
+ return channel !== undefined && canSubscribe(input.claims.u, channel);
200
+ }
201
+ //# sourceMappingURL=realtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtime.js","sourceRoot":"","sources":["../src/realtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1D,+GAA+G;AAC/G,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAC;AACpD,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mBAAmB,GAAG,4BAA4B,CAAC;AAChE;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AACtD,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAC7C,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAC;AACvD,iGAAiG;AACjG,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAC1D,oEAAoE;AACpE,MAAM,CAAC,M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EAAE,GAAG,CAAC,CAAC,CACpC,CAAC;IACF,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjC,CAAC;AAMD;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAQjC;IACC,IAAI,KAAK,CAAC,SAAS,KAAK,eAAe;QAAE,OAAO,IAAI,CAAC;IACrD,IAAI,KAAK,CAAC,SAAS,KAAK,iBAAiB;QAAE,OAAO,KAAK,CAAC;IACxD,IAAI,KAAK,CAAC,gBAAgB,KAAK,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC/E,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3D,OAAO,OAAO,KAAK,SAAS,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC"}
@@ -1,5 +1,11 @@
1
1
  import type { RouteRecord } from '../router.ts';
2
2
 
3
- export type RouteDecision = { t: 'server' } | { t: 'static'; key: string } | { t: 'notfound' };
3
+ export type RouteDecision =
4
+ | { t: 'server' }
5
+ | { t: 'static'; key: string }
6
+ | { t: 'health' }
7
+ | { t: 'realtime' }
8
+ | { t: 'storage'; key: string }
9
+ | { t: 'notfound' };
4
10
 
5
11
  export declare function decide(rec: RouteRecord | null | undefined, uri: string): RouteDecision;
@@ -5,16 +5,34 @@
5
5
  // when inlined.
6
6
  //
7
7
  // rec: route record from the KeyValueStore (see RouteRecord in router.ts)
8
- // o - Web Function endpoint domain (server), optional
8
+ // o - the server's domain, optional: a Web Function endpoint, or a function URL when c is 'r'
9
+ // (request mode). Which one only changes how the CloudFront Function calls it (OAC, or
10
+ // the origin secret k in a header); `plat dev` runs the server itself.
9
11
  // s - static key prefix in the sites bucket, e.g. "foo/prod/d01j..." , optional
10
12
  // r - server route prefixes when both o and s exist, e.g. ["/api/"]
11
13
  // spa - 1 to serve index.html for unknown non-file paths
12
- // returns { t: 'server' } | { t: 'static', key: '/<prefix>/<path>' } | { t: 'notfound' }
14
+ // rt - realtime: { n: channel namespace, m: 'p' | 's' }, optional
15
+ // p - public store names, optional
16
+ // returns { t: 'server' } | { t: 'static', key: '/<prefix>/<path>' } | { t: 'health' } | { t: 'realtime' }
17
+ // | { t: 'storage', key: '/<app>/<stage>/<store>/<key>' } | { t: 'notfound' }
18
+ // health - the router answers /__platform/health itself (HealthResponse with rec.d as the
19
+ // revision): a stage without a server has nothing else to report what it serves.
20
+ // realtime - /__platform/realtime is the router's own: it answers the browser's config, or passes
21
+ // a WebSocket to AppSync. Other /__platform/realtime/* paths (the token) are the server's.
22
+ // storage - /__platform/storage/<store>/<key> of a public store, served from the storage bucket
23
+ // (whose origin path adds `_public`); every other path below /__platform/storage/ is
24
+ // not found, so it never reaches the server. The key stays percent-encoded, as S3
25
+ // decodes it, and keys with `.` or `..` segments (also encoded) are refused.
13
26
 
14
27
  export function decide(rec, uri) {
15
- if (!rec || (!rec.o && !rec.s)) return { t: 'notfound' };
16
- if (uri.indexOf('/__platform/') === 0) return rec.o ? { t: 'server' } : { t: 'notfound' };
17
- if (!rec.s) return { t: 'server' };
28
+ if (!rec || (!rec.o && !rec.s && !rec.p)) return { t: 'notfound' };
29
+ if (uri.indexOf('/__platform/') === 0) {
30
+ if (uri.indexOf('/__platform/storage/') === 0) return storage(rec, uri.substring(20));
31
+ if (uri === '/__platform/realtime' && rec.rt) return { t: 'realtime' };
32
+ if (rec.o) return { t: 'server' };
33
+ return uri === '/__platform/health' ? { t: 'health' } : { t: 'notfound' };
34
+ }
35
+ if (!rec.s) return rec.o ? { t: 'server' } : { t: 'notfound' };
18
36
  if (rec.o) {
19
37
  var routes = rec.r || [];
20
38
  for (var i = 0; i < routes.length; i++) {
@@ -30,3 +48,22 @@ export function decide(rec, uri) {
30
48
  var dir = uri.charAt(uri.length - 1) === '/' ? uri : uri + '/';
31
49
  return { t: 'static', key: '/' + rec.s + dir + 'index.html' };
32
50
  }
51
+
52
+ function storage(rec, rest) {
53
+ var slash = rest.indexOf('/');
54
+ if (slash <= 0) return { t: 'notfound' };
55
+ var store = rest.substring(0, slash);
56
+ var key = rest.substring(slash + 1);
57
+ if (!rec.p || rec.p.indexOf(store) === -1 || !servableKey(key)) return { t: 'notfound' };
58
+ return { t: 'storage', key: '/' + rec.app + '/' + rec.stage + '/' + store + '/' + key };
59
+ }
60
+
61
+ // isServableKey in storage.ts. S3 decodes the key once, so an encoded dot or slash counts as one.
62
+ function servableKey(key) {
63
+ if (!key) return false;
64
+ var parts = key.replace(/%2e/gi, '.').replace(/%2f/gi, '/').split('/');
65
+ for (var i = 0; i < parts.length; i++) {
66
+ if (parts[i] === '.' || parts[i] === '..') return false;
67
+ }
68
+ return true;
69
+ }
package/dist/router.d.ts CHANGED
@@ -1,21 +1,43 @@
1
+ import { Schema } from 'effect';
1
2
  export type { RouteDecision } from './router/decide.js';
2
3
  export { decide } from './router/decide.js';
3
4
  /**
4
- * Value stored in the CloudFront KeyValueStore under the public hostname.
5
- * Keys are short because KVS values are capped at 1 KB.
5
+ * Value stored in the CloudFront KeyValueStore under the public hostname, and
6
+ * kept with each deployment for rollbacks. Keys are short because KVS values
7
+ * are capped at 1 KB.
6
8
  */
7
- export interface RouteRecord {
8
- v: 1;
9
- app: string;
10
- stage: string;
9
+ export declare const RouteRecordSchema: Schema.Struct<{
10
+ readonly v: Schema.Literal<1>;
11
+ readonly app: Schema.String;
12
+ readonly stage: Schema.String;
11
13
  /** Deployment id currently live. */
12
- d: string;
13
- /** Web Function endpoint domain. */
14
- o?: string;
14
+ readonly d: Schema.String;
15
+ /** The server's domain: a Web Function endpoint's, or with `c` a function URL's. */
16
+ readonly o: Schema.optional<Schema.String>;
17
+ /**
18
+ * `r`: `o` is a request-mode server (a function URL, `WebCompute`
19
+ * `request`), which the router calls without OAC, sending `k` in
20
+ * `ORIGIN_HEADER`. Absent: a Web Function endpoint, called with OAC.
21
+ */
22
+ readonly c: Schema.optional<Schema.Literal<"r">>;
23
+ /** The request-mode server's `originSecret`. */
24
+ readonly k: Schema.optional<Schema.String>;
15
25
  /** Static prefix in the sites bucket (no leading slash). */
16
- s?: string;
26
+ readonly s: Schema.optional<Schema.String>;
17
27
  /** Server route prefixes (only meaningful when both `o` and `s` exist). */
18
- r?: string[];
19
- spa?: 0 | 1;
20
- }
28
+ readonly r: Schema.optional<Schema.$Array<Schema.String>>;
29
+ readonly spa: Schema.optional<Schema.Literals<readonly [0, 1]>>;
30
+ /**
31
+ * Realtime (`plat.config.ts` `realtime`): the stage's channel namespace and
32
+ * who subscribes (`p` public with the API key, `s` signed-in with a token).
33
+ * The router answers `REALTIME_PATH` only for records that have it.
34
+ */
35
+ readonly rt: Schema.optional<Schema.Struct<{
36
+ readonly n: Schema.String;
37
+ readonly m: Schema.Literals<readonly ["p", "s"]>;
38
+ }>>;
39
+ /** Public stores, which the router serves from the storage bucket at `STORAGE_PATH`. */
40
+ readonly p: Schema.optional<Schema.$Array<Schema.String>>;
41
+ }>;
42
+ export type RouteRecord = typeof RouteRecordSchema.Type;
21
43
  export declare function encodeRouteRecord(rec: RouteRecord): string;
package/dist/router.js CHANGED
@@ -1,4 +1,40 @@
1
+ import { Schema } from 'effect';
1
2
  export { decide } from './router/decide.js';
3
+ /**
4
+ * Value stored in the CloudFront KeyValueStore under the public hostname, and
5
+ * kept with each deployment for rollbacks. Keys are short because KVS values
6
+ * are capped at 1 KB.
7
+ */
8
+ export const RouteRecordSchema = Schema.Struct({
9
+ v: Schema.Literal(1),
10
+ app: Schema.String,
11
+ stage: Schema.String,
12
+ /** Deployment id currently live. */
13
+ d: Schema.String,
14
+ /** The server's domain: a Web Function endpoint's, or with `c` a function URL's. */
15
+ o: Schema.optional(Schema.String),
16
+ /**
17
+ * `r`: `o` is a request-mode server (a function URL, `WebCompute`
18
+ * `request`), which the router calls without OAC, sending `k` in
19
+ * `ORIGIN_HEADER`. Absent: a Web Function endpoint, called with OAC.
20
+ */
21
+ c: Schema.optional(Schema.Literal('r')),
22
+ /** The request-mode server's `originSecret`. */
23
+ k: Schema.optional(Schema.String),
24
+ /** Static prefix in the sites bucket (no leading slash). */
25
+ s: Schema.optional(Schema.String),
26
+ /** Server route prefixes (only meaningful when both `o` and `s` exist). */
27
+ r: Schema.optional(Schema.Array(Schema.String)),
28
+ spa: Schema.optional(Schema.Literals([0, 1])),
29
+ /**
30
+ * Realtime (`plat.config.ts` `realtime`): the stage's channel namespace and
31
+ * who subscribes (`p` public with the API key, `s` signed-in with a token).
32
+ * The router answers `REALTIME_PATH` only for records that have it.
33
+ */
34
+ rt: Schema.optional(Schema.Struct({ n: Schema.String, m: Schema.Literals(['p', 's']) })),
35
+ /** Public stores, which the router serves from the storage bucket at `STORAGE_PATH`. */
36
+ p: Schema.optional(Schema.Array(Schema.String)),
37
+ });
2
38
  export function encodeRouteRecord(rec) {
3
39
  const json = JSON.stringify(rec);
4
40
  if (new TextEncoder().encode(json).length > 1024)
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAqB5C,MAAM,UAAU,iBAAiB,CAAC,GAAgB;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,IAAI;QAC9C,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,eAAe,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,E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AAiB,CAAC,GAAgB;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,IAAI;QAC9C,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,eAAe,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -26,6 +26,8 @@ export interface PlatformRuntimeConfig {
26
26
  kvsArn?: string;
27
27
  /** The router distribution; Web Function resource policies trust only this. */
28
28
  distributionArn?: string;
29
+ /** The edge floor's alarm and trigger; absent without `limits.edgeFloorAt`. */
30
+ edgeFloor?: EdgeFloorRuntimeConfig;
29
31
  /** Shared Cognito user pool for app end users. */
30
32
  userPoolId?: string;
31
33
  /** Hosted login origin, e.g. `https://login.platform.ericminassian.com`. */
@@ -36,7 +38,62 @@ export interface PlatformRuntimeConfig {
36
38
  alertsTopicArn?: string;
37
39
  /** Telemetry processor (account-level log subscription target). */
38
40
  telemetryFunctionArn?: string;
41
+ /** The AppSync Event API stages' channel namespaces live in (absent on platforms that predate it). */
42
+ realtime?: RealtimeRuntimeConfig;
43
+ /** The SES domain every stage sends from (absent on platforms that predate email). */
44
+ email?: EmailRuntimeConfig;
45
+ /** Container compute, ECS on Fargate (absent on platforms that predate it). */
46
+ containers?: ContainersRuntimeConfig;
39
47
  }
48
+ /**
49
+ * Where containers run. Tasks get a public IPv4 address in a public subnet
50
+ * (there is no NAT gateway) and accept no inbound traffic.
51
+ */
52
+ export interface ContainersRuntimeConfig {
53
+ /** ECS cluster name. */
54
+ cluster: string;
55
+ subnets: string[];
56
+ securityGroups: string[];
57
+ /** ECR repository name. */
58
+ repository: string;
59
+ /** `<account>.dkr.ecr.<region>.amazonaws.com/<repository>`. */
60
+ repositoryUri: string;
61
+ /** Pulls images and writes container logs. */
62
+ executionRoleArn: string;
63
+ /** Assumed by EventBridge Scheduler to scale a stage's services (preview stop schedules). */
64
+ schedulerRoleArn: string;
65
+ }
66
+ /**
67
+ * The edge floor (`limits.edgeFloorAt`): a CloudWatch alarm on the router
68
+ * distribution's requests per minute, and an EventBridge rule that invokes
69
+ * the control plane's worker when it goes off. The web ACL itself belongs to
70
+ * the control plane, which creates it only while the floor is on.
71
+ */
72
+ export interface EdgeFloorRuntimeConfig {
73
+ alarmArn: string;
74
+ /** The rule's ARN, which the worker's resource policy names. */
75
+ ruleArn: string;
76
+ }
77
+ export interface EmailRuntimeConfig {
78
+ /** Verified domain identity: `mail.<zone>` (`mail.localhost` in the emulator). */
79
+ domain: string;
80
+ identityArn: string;
81
+ }
82
+ export interface RealtimeRuntimeConfig {
83
+ apiId: string;
84
+ /** HTTP domain (`<id>.appsync-api.<region>.amazonaws.com`; `127.0.0.1:<port>` in the emulator). */
85
+ httpDomain: string;
86
+ /** Realtime (WebSocket) domain. */
87
+ realtimeDomain: string;
88
+ }
89
+ /**
90
+ * Where to publish and connect. AWS serves TLS; the emulator serves plain
91
+ * HTTP and WebSocket on local ports.
92
+ */
93
+ export declare function realtimeEndpoints(cfg: Pick<PlatformRuntimeConfig, 'target'>, rt: RealtimeRuntimeConfig): {
94
+ publishUrl: string;
95
+ websocketUrl: string;
96
+ };
40
97
  export declare function cognitoIssuer(region: string, userPoolId: string): string;
41
98
  export declare function cognitoJwksUri(cfg: Pick<PlatformRuntimeConfig, 'region' | 'jwksBaseUrl'>, userPoolId: string): string;
42
99
  export declare function publicUrl(cfg: Pick<PlatformRuntimeConfig, 'publicScheme' | 'publicPort'>, host: string): string;
@@ -1,3 +1,15 @@
1
+ import { APPSYNC_PUBLISH_PATH, APPSYNC_REALTIME_PATH } from './realtime.js';
2
+ /**
3
+ * Where to publish and connect. AWS serves TLS; the emulator serves plain
4
+ * HTTP and WebSocket on local ports.
5
+ */
6
+ export function realtimeEndpoints(cfg, rt) {
7
+ const tls = cfg.target === 'aws';
8
+ return {
9
+ publishUrl: `${tls ? 'https' : 'http'}://${rt.httpDomain}${APPSYNC_PUBLISH_PATH}`,
10
+ websocketUrl: `${tls ? 'wss' : 'ws'}://${rt.realtimeDomain}${APPSYNC_REALTIME_PATH}`,
11
+ };
12
+ }
1
13
  export function cognitoIssuer(region, userPoolId) {
2
14
  return `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`;
3
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-config.js","sourceRoot":"","sources":["../src/runtime-config.ts"],"names":[],"mappings":"AAwCA,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,UAAkB;IAC9D,OAAO,uBAAuB,MAAM,kBAAkB,UAAU,EAAE,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,GAA0D,EAC1D,UAAkB;IAElB,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,IAAI,uBAAuB,GAAG,CAAC,MAAM,gBAAgB,CAAC;IAClF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,wBAAwB,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,GAA+D,EAC/D,IAAY;IAEZ,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,OAAO,GAAG,GAAG,CAAC,YAAY,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC;AAChD,CAAC"}
1
+ {"version":3,"file":"runtime-config.js","sourceRoot":"","sources":["../src/runtime-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AA+F5E;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,GAA0C,EAC1C,EAAyB;IAEzB,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,KAAK,KAAK,CAAC;IACjC,OAAO;QACL,UAAU,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,UAAU,GAAG,oBAAoB,EAAE;QACjF,YAAY,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,cAAc,GAAG,qBAAqB,EAAE;KACrF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,UAAkB;IAC9D,OAAO,uBAAuB,MAAM,kBAAkB,UAAU,EAAE,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,GAA0D,EAC1D,UAAkB;IAElB,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,IAAI,uBAAuB,GAAG,CAAC,MAAM,gBAAgB,CAAC;IAClF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,wBAAwB,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,GAA+D,EAC/D,IAAY;IAEZ,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,OAAO,GAAG,GAAG,CAAC,YAAY,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * File stores (`storage` in `plat.config.ts`). Every stage's stores share the
3
+ * platform's storage bucket:
4
+ *
5
+ * - a private store is `<app>/<stage>/<store>/` (`names.storagePrefix`);
6
+ * browsers reach its files only through presigned URLs;
7
+ * - a public store is `_public/<app>/<stage>/<store>/`, which the edge serves
8
+ * at `/__platform/storage/<store>/<key>` on the app's own host. The router
9
+ * distribution may read `_public/*` and nothing else, so a routing mistake
10
+ * can't expose a private store. `_` can't start an app name, so no app's
11
+ * prefix collides with it.
12
+ *
13
+ * Isomorphic: the SDK, its browser client, the CLI and the engine share it.
14
+ */
15
+ /** Where the edge serves public stores on every app host: `/__platform/storage/<store>/<key>`. */
16
+ export declare const STORAGE_PATH = "/__platform/storage/";
17
+ /** Top-level prefix of public stores in the storage bucket. */
18
+ export declare const PUBLIC_STORAGE_ROOT = "_public/";
19
+ /**
20
+ * Headers the edge adds to every public-store response (the router
21
+ * distribution's response headers policy; `plat dev` sends the same).
22
+ * `script-src 'none'` keeps an uploaded HTML or SVG file from running script
23
+ * on the app's origin, where its session cookie lives (`sandbox` would also
24
+ * stop PDFs from opening in Chrome).
25
+ */
26
+ export declare const STORAGE_RESPONSE_HEADERS: {
27
+ readonly 'x-content-type-options': 'nosniff';
28
+ readonly 'content-security-policy': "script-src 'none'";
29
+ };
30
+ /**
31
+ * The router's `x-platform-host` for a public store's file, in place of the
32
+ * host. CloudFront's cache key is the rewritten URI plus that header, not the
33
+ * behavior or origin, and an app's server could be asked for the same path
34
+ * (`/<app>/<stage>/<store>/<key>`) on the app's host: with the host in both,
35
+ * its response would be served for the file, and the file for that path. No
36
+ * routed host has this value.
37
+ */
38
+ export declare const STORAGE_CACHE_HOST = "__storage";
39
+ /** `Cache-Control` the edge adds to a public file that carries none: browsers revalidate it. */
40
+ export declare const STORAGE_DEFAULT_CACHE_CONTROL = "no-cache";
41
+ /**
42
+ * Whether the edge serves `key` (as it appears in a URL path, so still
43
+ * percent-encoded): not empty, and without `.` or `..` segments. S3 decodes
44
+ * the key once, so `%2e` counts as a dot and `%2f` as a slash. The router
45
+ * inlines the same check (`router/decide.js`).
46
+ */
47
+ export declare function isServableKey(key: string): boolean;
48
+ /**
49
+ * The path the edge serves a public store's file at, with each key segment
50
+ * percent-encoded: `storagePath('snapshots', 'fires/today 1.json')` →
51
+ * `/__platform/storage/snapshots/fires/today%201.json`.
52
+ */
53
+ export declare function storagePath(store: string, key: string): string;
54
+ /** The content type for a file name (or key), `application/octet-stream` when the extension is unknown. */
55
+ export declare function contentTypeFor(path: string): string;