@ericminassian/platform-core 0.2.0 → 0.3.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 (44) hide show
  1. package/dist/api.d.ts +947 -209
  2. package/dist/api.js +335 -1
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.d.ts +19 -0
  5. package/dist/auth.js +29 -0
  6. package/dist/auth.js.map +1 -1
  7. package/dist/bindings.d.ts +8 -2
  8. package/dist/bindings.js.map +1 -1
  9. package/dist/cloudfront-function.js +6 -0
  10. package/dist/cloudfront-function.js.map +1 -1
  11. package/dist/config.d.ts +3 -1
  12. package/dist/config.js +7 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/constants.js.map +1 -1
  16. package/dist/manifest.d.ts +96 -92
  17. package/dist/manifest.js +96 -66
  18. package/dist/manifest.js.map +1 -1
  19. package/dist/naming.d.ts +13 -2
  20. package/dist/naming.js +12 -1
  21. package/dist/naming.js.map +1 -1
  22. package/dist/platform-api.d.ts +5337 -0
  23. package/dist/platform-api.js +343 -0
  24. package/dist/platform-api.js.map +1 -0
  25. package/dist/router/decide.d.ts +5 -1
  26. package/dist/router/decide.js +7 -2
  27. package/dist/router.d.ts +1 -1
  28. package/dist/telemetry.d.ts +236 -74
  29. package/dist/telemetry.js +97 -0
  30. package/dist/telemetry.js.map +1 -1
  31. package/package.json +10 -2
  32. package/src/api.ts +427 -231
  33. package/src/auth.ts +33 -0
  34. package/src/bindings.ts +8 -2
  35. package/src/cloudfront-function.ts +6 -0
  36. package/src/config.ts +3 -1
  37. package/src/constants.ts +12 -0
  38. package/src/manifest.ts +145 -87
  39. package/src/naming.ts +13 -2
  40. package/src/platform-api.ts +504 -0
  41. package/src/router/decide.d.ts +5 -1
  42. package/src/router/decide.js +7 -2
  43. package/src/router.ts +1 -1
  44. package/src/telemetry.ts +107 -85
package/src/auth.ts CHANGED
@@ -21,6 +21,39 @@ export const AUTH_COOKIES = {
21
21
 
22
22
  export const AUTH_SCOPES = ['openid', 'email', 'profile'] as const;
23
23
 
24
+ /** Backslashes, spaces, and ASCII control characters (`<= ' '` covers C0 and space). */
25
+ const unsafeInRedirect = (c: string) => c === '\\' || c <= ' ' || c === '\u007f';
26
+
27
+ /**
28
+ * Only same-origin absolute paths are allowed as post-login destinations.
29
+ * Browsers drop tabs and newlines from URLs (`/\t/evil.com` becomes
30
+ * `//evil.com`), so control characters and spaces are refused too.
31
+ */
32
+ export function safeRedirect(target: string | null | undefined): string {
33
+ if (!target?.startsWith('/') || target.startsWith('//') || [...target].some(unsafeInRedirect)) return '/';
34
+ return target;
35
+ }
36
+
37
+ /** Path that starts sign-in and returns to `redirect` afterwards. */
38
+ export function loginPath(redirect = '/'): string {
39
+ return `${AUTH_ROUTES.login}?redirect=${encodeURIComponent(safeRedirect(redirect))}`;
40
+ }
41
+
42
+ /** Path that signs out and then goes to `redirect`. */
43
+ export function logoutPath(redirect = '/'): string {
44
+ return `${AUTH_ROUTES.logout}?redirect=${encodeURIComponent(safeRedirect(redirect))}`;
45
+ }
46
+
47
+ /**
48
+ * Body of every platform 401 (the `auth.required` gate and the SDK's
49
+ * `Unauthorized` error), so clients decode one shape.
50
+ */
51
+ export const UNAUTHORIZED_BODY = {
52
+ _tag: 'Unauthorized',
53
+ message: 'Sign in required',
54
+ loginUrl: AUTH_ROUTES.login,
55
+ } as const;
56
+
24
57
  /** The user object apps see. */
25
58
  export interface PlatformUser {
26
59
  /** Stable user id (Cognito `sub`). Same across all platform apps. */
package/src/bindings.ts CHANGED
@@ -22,11 +22,17 @@ export interface Bindings {
22
22
  queues: Record<string, { url: string; arn: string }>;
23
23
  bus?: { name: string; arn: string };
24
24
  /** Shared storage bucket; each named store is `prefix + <name>/`. */
25
- storage?: { bucket: string; prefix: string; stores: string[] };
26
- secrets: { path: string; sharedPath: string; names: string[] };
25
+ storage?: { bucket: string; prefix: string; stores: readonly string[] };
26
+ secrets: { path: string; sharedPath: string; names: readonly string[] };
27
27
  auth?: AuthBindings;
28
28
  /** Worker function name, for direct `invoke` jobs. */
29
29
  worker?: string;
30
+ /**
31
+ * The stage's secret (32 random bytes, base64url), kept in SSM at
32
+ * `names.stageKeyParameter`. The SDK derives a key per purpose from it, e.g.
33
+ * to seal `db` query cursors. Absent on stages deployed before it existed.
34
+ */
35
+ stageKey?: string;
30
36
  }
31
37
 
32
38
  export interface AuthBindings {
@@ -18,6 +18,11 @@ const kvs = cf.kvs(${JSON.stringify(opts.kvsId)});
18
18
 
19
19
  ${decideSrc}
20
20
 
21
+ function health(rec) {
22
+ var body = JSON.stringify({ ok: true, app: rec.app, stage: rec.stage, revision: rec.d });
23
+ return { statusCode: 200, statusDescription: 'OK', headers: { 'content-type': { value: 'application/json' }, 'cache-control': { value: 'no-store' } }, body: body };
24
+ }
25
+
21
26
  function notFound() {
22
27
  return { statusCode: 404, statusDescription: 'Not Found', headers: { 'content-type': { value: 'text/plain' }, 'cache-control': { value: 'no-store' } }, body: 'Nothing is deployed here.' };
23
28
  }
@@ -32,6 +37,7 @@ async function handler(event) {
32
37
  try { rec = JSON.parse(raw); } catch (e) { return notFound(); }
33
38
  var d = decide(rec, req.uri);
34
39
  if (d.t === 'notfound') return notFound();
40
+ if (d.t === 'health') return health(rec);
35
41
  req.headers[${JSON.stringify(HOST_HEADER)}] = { value: host };
36
42
  if (d.t === 'static') {
37
43
  req.uri = d.key;
package/src/config.ts CHANGED
@@ -3,7 +3,9 @@
3
3
  * member allowlist. Members are GitHub usernames; inviting someone is a PR
4
4
  * plus a platform deploy. No emails or account ids here (the repo is public).
5
5
  */
6
- export type MemberRole = 'admin' | 'member';
6
+ import { Schema } from 'effect';
7
+ export const MemberRole = Schema.Literals(['admin', 'member']);
8
+ export type MemberRole = typeof MemberRole.Type;
7
9
 
8
10
  export interface Member {
9
11
  github: string;
package/src/constants.ts CHANGED
@@ -20,6 +20,18 @@ export const PLATFORM_DEFAULTS = {
20
20
  export const PLATFORM_PATH_PREFIX = '/__platform/';
21
21
  export const HEALTH_PATH = '/__platform/health';
22
22
 
23
+ /**
24
+ * Body served at `HEALTH_PATH`: by the SDK when the stage has a server, else
25
+ * by the edge router from its route record. `revision` is the deployment id,
26
+ * so a poller can tell which deployment answered.
27
+ */
28
+ export interface HealthResponse {
29
+ ok: true;
30
+ app: string;
31
+ stage: string;
32
+ revision: string;
33
+ }
34
+
23
35
  /** Header the router sets so apps (and the cache key) see the public host. */
24
36
  export const HOST_HEADER = 'x-platform-host';
25
37
  /** Trace propagation header (W3C traceparent is also honored). */
package/src/manifest.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import { Effect, Schema } from 'effect';
2
2
  import { validateCron } from './cron.ts';
3
3
  import { APP_NAME_PATTERN, ENV_NAME_PATTERN, EVENT_TYPE_PATTERN, RESOURCE_KEY_PATTERN } from './naming.ts';
4
4
 
@@ -17,70 +17,102 @@ export const APP_CONFIG_FILE = 'plat.config.ts';
17
17
  * below is the same shape written for authors. `test/manifest-types.test.ts`
18
18
  * keeps the two in step.
19
19
  */
20
- const resourceKey = z.string().regex(RESOURCE_KEY_PATTERN, 'must be 1-20 chars of a-z, 0-9, hyphens');
21
- const eventType = z.string().regex(EVENT_TYPE_PATTERN);
20
+ const RESOURCE_KEY_MESSAGE = 'must be 1-20 chars of a-z, 0-9, hyphens';
21
+ const resourceKey = Schema.String.check(
22
+ Schema.isPattern(RESOURCE_KEY_PATTERN, { message: RESOURCE_KEY_MESSAGE }),
23
+ );
24
+ const eventType = Schema.String.check(Schema.isPattern(EVENT_TYPE_PATTERN));
25
+ const envName = Schema.String.check(Schema.isPattern(ENV_NAME_PATTERN));
22
26
 
23
- const WebSchema = z
24
- .object({
25
- server: z.string().optional(),
26
- static: z.string().optional(),
27
- build: z.string().optional(),
28
- dev: z.object({ command: z.string(), port: z.number().int().positive() }).optional(),
29
- spa: z.boolean().default(true),
30
- serverRoutes: z.array(z.string().startsWith('/')).default(['/api/']),
31
- timeoutSeconds: z.number().int().min(3).max(900).default(30),
32
- concurrency: z.number().int().min(1).max(128).default(64),
33
- })
34
- .refine((w) => w.server || w.static, { message: 'web needs a server, a static directory, or both' });
27
+ /**
28
+ * A record whose keys must match `pattern`. `Schema.Record` drops keys that fail
29
+ * its key schema, which would make a misnamed queue silently disappear, so
30
+ * keys are checked here and reported at their path instead.
31
+ */
32
+ const recordOf = <V extends Schema.Top>(pattern: RegExp, value: V, message = `must match ${pattern}`) =>
33
+ Schema.Record(Schema.String, value).check(
34
+ Schema.makeFilter((record) =>
35
+ Object.keys(record)
36
+ .filter((key) => !pattern.test(key))
37
+ .map((key) => ({ path: [key], issue: message })),
38
+ ),
39
+ );
40
+ const intBetween = (minimum: number, maximum: number) =>
41
+ Schema.Int.check(Schema.isBetween({ minimum, maximum }));
42
+ /** Absent (or `undefined`) decodes to `value`. */
43
+ const orElse =
44
+ <S extends Schema.Top>(value: S['Encoded']) =>
45
+ (schema: S) =>
46
+ schema.pipe(Schema.withDecodingDefault(Effect.succeed(value)));
47
+
48
+ const WebSchema = Schema.Struct({
49
+ server: Schema.optional(Schema.String),
50
+ static: Schema.optional(Schema.String),
51
+ build: Schema.optional(Schema.String),
52
+ dev: Schema.optional(
53
+ Schema.Struct({ command: Schema.String, port: Schema.optional(intBetween(1, 65535)) }),
54
+ ),
55
+ spa: Schema.Boolean.pipe(orElse(true)),
56
+ serverRoutes: Schema.Array(Schema.String.check(Schema.isStartingWith('/'))).pipe(orElse(['/api/'])),
57
+ timeoutSeconds: intBetween(3, 900).pipe(orElse(30)),
58
+ concurrency: intBetween(1, 128).pipe(orElse(64)),
59
+ }).check(
60
+ Schema.makeFilter((w) =>
61
+ w.server || w.static ? undefined : 'web needs a server, a static directory, or both',
62
+ ),
63
+ );
35
64
 
36
- const WorkerSchema = z.object({
37
- entry: z.string().default('src/worker.ts'),
38
- timeoutSeconds: z.number().int().min(1).max(900).default(60),
39
- memoryMb: z.number().int().min(128).max(10240).default(512),
65
+ const WorkerSchema = Schema.Struct({
66
+ entry: Schema.String.pipe(orElse('src/worker.ts')),
67
+ timeoutSeconds: intBetween(1, 900).pipe(orElse(60)),
68
+ memoryMb: intBetween(128, 10240).pipe(orElse(512)),
40
69
  });
41
70
 
42
- const QueueSchema = z.object({
43
- batchSize: z.number().int().min(1).max(10).default(10),
44
- visibilityTimeoutSeconds: z.number().int().min(0).max(43200).optional(),
45
- maxReceiveCount: z.number().int().min(1).max(1000).default(5),
46
- concurrency: z.number().int().min(2).max(1000).optional(),
71
+ const QueueSchema = Schema.Struct({
72
+ batchSize: intBetween(1, 10).pipe(orElse(10)),
73
+ visibilityTimeoutSeconds: Schema.optional(intBetween(0, 43200)),
74
+ maxReceiveCount: intBetween(1, 1000).pipe(orElse(5)),
75
+ concurrency: Schema.optional(intBetween(2, 1000)),
47
76
  });
48
77
 
49
- const CronSchema = z.union([z.string(), z.object({ schedule: z.string(), timezone: z.string().optional() })]);
78
+ const CronSchema = Schema.Union([
79
+ Schema.String,
80
+ Schema.Struct({ schedule: Schema.String, timezone: Schema.optional(Schema.String) }),
81
+ ]).check(
82
+ Schema.makeFilter((cron) => validateCron(typeof cron === 'string' ? cron : cron.schedule) ?? undefined),
83
+ );
50
84
 
51
- const AuthSchema = z.union([z.boolean(), z.object({ required: z.boolean().default(false) })]);
85
+ const AuthSchema = Schema.Union([
86
+ Schema.Boolean,
87
+ Schema.Struct({ required: Schema.Boolean.pipe(orElse(false)) }),
88
+ ]);
52
89
 
53
- export const ManifestSchema = z
54
- .object({
55
- name: z
56
- .string()
57
- // Reserved names are enforced when an app is registered (API), not here:
58
- // the control plane itself is the app named `platform`.
59
- .regex(APP_NAME_PATTERN, 'must be 3-30 chars of a-z, 0-9, single hyphens'),
60
- description: z.string().max(200).optional(),
61
- web: WebSchema.optional(),
62
- worker: WorkerSchema.optional(),
63
- auth: AuthSchema.default(false),
64
- db: z.boolean().default(false),
65
- queues: z.record(resourceKey, QueueSchema).default({}),
66
- // The array form predates typed event payloads; deployments recorded
67
- // before then still store it.
68
- events: z.union([z.array(eventType), z.record(eventType, z.object({}))]).default([]),
69
- crons: z.record(resourceKey, CronSchema).default({}),
70
- storage: z.array(resourceKey).default([]),
71
- secrets: z.array(z.string().regex(ENV_NAME_PATTERN)).default([]),
72
- env: z.record(z.string().regex(ENV_NAME_PATTERN), z.string()).default({}),
73
- })
74
- .superRefine((m, ctx) => {
75
- for (const [key, cron] of Object.entries(m.crons)) {
76
- const err = validateCron(typeof cron === 'string' ? cron : cron.schedule);
77
- if (err) ctx.addIssue({ code: 'custom', path: ['crons', key], message: err });
78
- }
79
- });
90
+ export const ManifestSchema = Schema.Struct({
91
+ // Reserved names are enforced when an app is registered (API), not here:
92
+ // the control plane itself is the app named `platform`.
93
+ name: Schema.String.check(
94
+ Schema.isPattern(APP_NAME_PATTERN, { message: 'must be 3-30 chars of a-z, 0-9, single hyphens' }),
95
+ ),
96
+ description: Schema.optional(Schema.String.check(Schema.isMaxLength(200))),
97
+ web: Schema.optional(WebSchema),
98
+ worker: Schema.optional(WorkerSchema),
99
+ auth: AuthSchema.pipe(orElse(false)),
100
+ db: Schema.Boolean.pipe(orElse(false)),
101
+ queues: recordOf(RESOURCE_KEY_PATTERN, QueueSchema, RESOURCE_KEY_MESSAGE).pipe(orElse({})),
102
+ // The array form predates typed event payloads; deployments recorded
103
+ // before then still store it.
104
+ events: Schema.Union([Schema.Array(eventType), recordOf(EVENT_TYPE_PATTERN, Schema.Struct({}))]).pipe(
105
+ orElse([]),
106
+ ),
107
+ crons: recordOf(RESOURCE_KEY_PATTERN, CronSchema, RESOURCE_KEY_MESSAGE).pipe(orElse({})),
108
+ storage: Schema.Array(resourceKey).pipe(orElse([])),
109
+ secrets: Schema.Array(envName).pipe(orElse([])),
110
+ env: recordOf(ENV_NAME_PATTERN, Schema.String).pipe(orElse({})),
111
+ });
80
112
 
81
113
  /** The evaluated config as JSON: what the CLI sends and deployments store. */
82
- export type ManifestInput = z.input<typeof ManifestSchema>;
83
- export type Manifest = z.output<typeof ManifestSchema>;
114
+ export type ManifestInput = typeof ManifestSchema.Encoded;
115
+ export type Manifest = typeof ManifestSchema.Type;
84
116
 
85
117
  // ---------------------------------------------------------------------------
86
118
  // Authoring types. Arrays are readonly so `defineApp` can keep literal names.
@@ -95,14 +127,18 @@ type Payload<T> = { readonly [payloadType]?: T };
95
127
  export type PayloadOf<D> = D extends Payload<infer T> ? (unknown extends T ? unknown : T) : unknown;
96
128
 
97
129
  export interface WebConfig {
98
- /** Entry module whose default export is a fetch handler (`{ fetch }`, a function, or a Hono app). */
130
+ /** Entry module whose default export is `toFetchHandler(...)` from `@ericminassian/platform`. */
99
131
  server?: string;
100
132
  /** Directory of built static assets, served from the edge. */
101
133
  static?: string;
102
134
  /** Shell command that builds `static` (run by `plat build`). */
103
135
  build?: string;
104
- /** Dev server for the frontend, proxied by `plat dev` (e.g. Vite). */
105
- dev?: { command: string; port: number };
136
+ /**
137
+ * Dev server for the frontend, proxied by `plat dev` (e.g. Vite). The command
138
+ * listens on the port `plat dev` passes in `PLATFORM_DEV_WEB_PORT` (and `PORT`):
139
+ * `port` when it is free, otherwise any free port.
140
+ */
141
+ dev?: { command: string; port?: number };
106
142
  /** Serve `index.html` for unknown non-file paths (client-side routing). Default `true`. */
107
143
  spa?: boolean;
108
144
  /** When both `server` and `static` exist, path prefixes handled by the server. Default `['/api/']`. */
@@ -201,22 +237,33 @@ export function event<Detail>(): EventConfig<Detail> {
201
237
 
202
238
  // ---------------------------------------------------------------------------
203
239
 
204
- /** Manifest with defaults applied and derived fields normalized. */
205
- export interface ResolvedManifest {
206
- name: string;
207
- description?: string;
208
- web?: z.output<typeof WebSchema>;
240
+ /**
241
+ * Manifest with defaults applied and derived fields normalized: what
242
+ * deployments store. Decoding fills defaults for fields added since a stored
243
+ * manifest was written, so earlier deployments keep decoding.
244
+ */
245
+ export const ResolvedManifest = Schema.Struct({
246
+ name: Schema.String,
247
+ description: Schema.optional(Schema.String),
248
+ web: Schema.optional(WebSchema),
209
249
  /** Present when any queue, event subscription or cron exists. */
210
- worker?: z.output<typeof WorkerSchema>;
211
- auth: { enabled: boolean; required: boolean };
212
- db: boolean;
213
- queues: Record<string, z.output<typeof QueueSchema> & { visibilityTimeoutSeconds: number }>;
214
- events: string[];
215
- crons: Record<string, { schedule: string; timezone?: string }>;
216
- storage: string[];
217
- secrets: string[];
218
- env: Record<string, string>;
219
- }
250
+ worker: Schema.optional(WorkerSchema),
251
+ auth: Schema.Struct({ enabled: Schema.Boolean, required: Schema.Boolean }),
252
+ db: Schema.Boolean,
253
+ queues: Schema.Record(
254
+ Schema.String,
255
+ Schema.Struct({ ...QueueSchema.fields, visibilityTimeoutSeconds: Schema.Finite }),
256
+ ),
257
+ events: Schema.Array(Schema.String),
258
+ crons: Schema.Record(
259
+ Schema.String,
260
+ Schema.Struct({ schedule: Schema.String, timezone: Schema.optional(Schema.String) }),
261
+ ),
262
+ storage: Schema.Array(Schema.String),
263
+ secrets: Schema.Array(Schema.String),
264
+ env: Schema.Record(Schema.String, Schema.String),
265
+ });
266
+ export type ResolvedManifest = typeof ResolvedManifest.Type;
220
267
 
221
268
  export class ManifestError extends Error {
222
269
  readonly issues: string[];
@@ -226,32 +273,43 @@ export class ManifestError extends Error {
226
273
  }
227
274
  }
228
275
 
276
+ const validateManifest = Schema.toStandardSchemaV1(ManifestSchema, { parseOptions: { errors: 'all' } })[
277
+ '~standard'
278
+ ].validate;
279
+
229
280
  export function parseManifest(input: unknown): ResolvedManifest {
230
- const parsed = ManifestSchema.safeParse(input);
231
- if (!parsed.success) {
232
- throw new ManifestError(parsed.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`));
281
+ const result = validateManifest(input);
282
+ // The schema has no asynchronous checks, so validation is synchronous.
283
+ if (result instanceof Promise) throw new Error('manifest validation must be synchronous');
284
+ if (result.issues) {
285
+ throw new ManifestError(
286
+ result.issues.map((i) => {
287
+ const path = (i.path ?? []).map((p) => String(typeof p === 'object' ? p.key : p)).join('.');
288
+ return `${path || '(root)'}: ${i.message}`;
289
+ }),
290
+ );
233
291
  }
234
- return resolveManifest(parsed.data);
292
+ return resolveManifest(result.value);
235
293
  }
236
294
 
237
295
  export function resolveManifest(m: Manifest): ResolvedManifest {
238
296
  const events = Array.isArray(m.events) ? m.events : Object.keys(m.events);
239
297
  const needsWorker =
240
298
  Object.keys(m.queues).length > 0 || events.length > 0 || Object.keys(m.crons).length > 0;
241
- const worker = m.worker ?? (needsWorker ? WorkerSchema.parse({}) : undefined);
299
+ const worker = m.worker ?? (needsWorker ? Schema.decodeUnknownSync(WorkerSchema)({}) : undefined);
242
300
  const auth =
243
301
  typeof m.auth === 'boolean'
244
302
  ? { enabled: m.auth, required: false }
245
303
  : { enabled: true, required: m.auth.required };
246
- const queues: ResolvedManifest['queues'] = {};
247
- for (const [key, q] of Object.entries(m.queues)) {
248
- queues[key] = {
249
- ...q,
250
- visibilityTimeoutSeconds: q.visibilityTimeoutSeconds ?? (worker?.timeoutSeconds ?? 60) * 6,
251
- };
252
- }
253
- const crons: ResolvedManifest['crons'] = {};
254
- for (const [key, c] of Object.entries(m.crons)) crons[key] = typeof c === 'string' ? { schedule: c } : c;
304
+ const queues: ResolvedManifest['queues'] = Object.fromEntries(
305
+ Object.entries(m.queues).map(([key, q]) => [
306
+ key,
307
+ { ...q, visibilityTimeoutSeconds: q.visibilityTimeoutSeconds ?? (worker?.timeoutSeconds ?? 60) * 6 },
308
+ ]),
309
+ );
310
+ const crons: ResolvedManifest['crons'] = Object.fromEntries(
311
+ Object.entries(m.crons).map(([key, c]) => [key, typeof c === 'string' ? { schedule: c } : c]),
312
+ );
255
313
  return {
256
314
  name: m.name,
257
315
  ...(m.description ? { description: m.description } : {}),
package/src/naming.ts CHANGED
@@ -94,7 +94,12 @@ export const names = {
94
94
  base: (app: string, stage: string) => `${app}--${stage}`,
95
95
  table: (app: string, stage: string) => `${app}--${stage}`,
96
96
  webFunction: (app: string, stage: string) => `${app}--${stage}`,
97
- webEndpoint: () => 'live',
97
+ /**
98
+ * The Web Function's two endpoints, each pinned to one revision. Neither
99
+ * name means "current": a deploy uses whichever the live route doesn't
100
+ * (`live` predates the second one).
101
+ */
102
+ webEndpoints: () => ['live', 'live-b'] as const,
98
103
  workerFunction: (app: string, stage: string) => `${app}--${stage}--worker`,
99
104
  /** IAM role name; created under {@link IAM_APP_PATH}. */
100
105
  role: (app: string, stage: string) => `${app}--${stage}`,
@@ -107,12 +112,18 @@ export const names = {
107
112
  scheduleGroup: (app: string, stage: string) => `${app}--${stage}`,
108
113
  schedule: (cronKey: string) => cronKey,
109
114
  userPoolClient: (app: string, stage: string) => `${app}--${stage}`,
110
- logGroup: (app: string, stage: string, component: 'web' | 'worker') =>
115
+ /**
116
+ * A stage's log groups. Lambda also writes a Web Function's environments to
117
+ * `<web group>.local`, so the engine creates that one too.
118
+ */
119
+ logGroup: (app: string, stage: string, component: 'web' | 'web.local' | 'worker') =>
111
120
  `/platform/apps/${app}/${stage}/${component}`,
112
121
  logGroupPrefix: (app: string, stage?: string) =>
113
122
  stage ? `/platform/apps/${app}/${stage}/` : `/platform/apps/${app}/`,
114
123
  secretsPath: (app: string, stage: string) => `/platform/apps/${app}/${stage}/secrets/`,
115
124
  sharedSecretsPath: (app: string) => `/platform/apps/${app}/_shared/secrets/`,
125
+ /** SSM SecureString holding the stage key (see `Bindings.stageKey`); outside the secrets path. */
126
+ stageKeyParameter: (app: string, stage: string) => `/platform/apps/${app}/${stage}/stage-key`,
116
127
  /** Prefix inside the shared storage bucket: `<app>/<stage>/<bucket>/`. */
117
128
  storagePrefix: (app: string, stage: string, bucket?: string) =>
118
129
  bucket ? `${app}/${stage}/${bucket}/` : `${app}/${stage}/`,