@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
@@ -0,0 +1,504 @@
1
+ /**
2
+ * The control plane's HTTP API (`/v1`) as an Effect `HttpApi`: the control
3
+ * plane implements it, the console calls it through a client generated from
4
+ * it, and its schemas describe what the CLI sends and reads.
5
+ *
6
+ * Imported from `@ericminassian/platform-core/platform-api`, never from the
7
+ * core index, so app runtimes don't load it.
8
+ *
9
+ * Auth is one of:
10
+ * - `Authorization: Bearer <platform token>` (CLI, from `plat login`)
11
+ * - `Authorization: Bearer <GitHub Actions OIDC token>` (CI deploys only)
12
+ * - the console's session cookie, plus `x-platform-csrf: 1` on writes
13
+ *
14
+ * The wire format predates this definition and published CLIs depend on it:
15
+ * paths, bodies and the `{ error: { code, message } }` error body stay as
16
+ * they are.
17
+ */
18
+ import { Context, Schema, SchemaGetter } from 'effect';
19
+ import { HttpApi, HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema } from 'effect/http-api';
20
+ import {
21
+ AdminOverview,
22
+ ApiErrorBody,
23
+ AppRecord,
24
+ AppSummary,
25
+ CliLoginRequest,
26
+ CliLoginResponse,
27
+ CostResponse,
28
+ CreateAppRequest,
29
+ CreateDeploymentRequest,
30
+ CreateDeploymentResponse,
31
+ CronRunResponse,
32
+ DataCollections,
33
+ DataPage,
34
+ DeploymentRecord,
35
+ ErrorGroup,
36
+ ErrorStatus,
37
+ JobsResponse,
38
+ LogLine,
39
+ LogsResponse,
40
+ MeResponse,
41
+ MetricsResponse,
42
+ PutSecretRequest,
43
+ QueueStats,
44
+ RedriveResponse,
45
+ RollbackRequest,
46
+ RollbackResponse,
47
+ RouteStats,
48
+ SecretsResponse,
49
+ StageDestroyed,
50
+ StageDestroying,
51
+ StageRecord,
52
+ StorageResponse,
53
+ TraceResponse,
54
+ UpdateAppRequest,
55
+ UpdateErrorRequest,
56
+ UptimePoint,
57
+ UrlResponse,
58
+ } from './api.ts';
59
+ import type { MemberRole } from './config.ts';
60
+
61
+ // ---------------------------------------------------------------------------
62
+ // Errors: one class per status, each encoded as `{ error: { code, message } }`
63
+ // ---------------------------------------------------------------------------
64
+
65
+ const errorFields = { code: Schema.String, message: Schema.String };
66
+ type ErrorFields = { readonly code: string; readonly message: string };
67
+
68
+ /** The wire schema for an error class: its `code`/`message` nested under `error`, answered with `status`. */
69
+ const onTheWire = <
70
+ Tag extends string,
71
+ S extends Schema.Codec<ErrorFields, ErrorFields & { readonly _tag: Tag }>,
72
+ >(
73
+ tag: Tag,
74
+ error: S,
75
+ status: number,
76
+ ) =>
77
+ ApiErrorBody.pipe(
78
+ Schema.decodeTo(error, {
79
+ decode: SchemaGetter.transform((body) => ({ _tag: tag, ...body.error })),
80
+ encode: SchemaGetter.transform(({ code, message }) => ({ error: { code, message } })),
81
+ }),
82
+ HttpApiSchema.status(status),
83
+ );
84
+
85
+ /** 400 `bad_request` (also every request that fails its schema). */
86
+ export class BadRequest extends Schema.TaggedError<BadRequest, { readonly brand: unique symbol }>()(
87
+ 'BadRequest',
88
+ errorFields,
89
+ ) {
90
+ static readonly of = (message: string) => new BadRequest({ code: 'bad_request', message });
91
+ }
92
+
93
+ /** 401 `unauthenticated`: no or invalid credentials. */
94
+ export class Unauthenticated extends Schema.TaggedError<Unauthenticated, { readonly brand: unique symbol }>()(
95
+ 'Unauthenticated',
96
+ errorFields,
97
+ ) {
98
+ static readonly of = (message: string) => new Unauthenticated({ code: 'unauthenticated', message });
99
+ }
100
+
101
+ /** 403: `forbidden`, `members_only`, `admins_only`, `not_a_member`, `csrf`. */
102
+ export class Forbidden extends Schema.TaggedError<Forbidden, { readonly brand: unique symbol }>()(
103
+ 'Forbidden',
104
+ errorFields,
105
+ ) {}
106
+
107
+ /** 404 `not_found`. */
108
+ export class NotFound extends Schema.TaggedError<NotFound, { readonly brand: unique symbol }>()(
109
+ 'NotFound',
110
+ errorFields,
111
+ ) {
112
+ static readonly of = (what: string) => new NotFound({ code: 'not_found', message: `${what} not found` });
113
+ }
114
+
115
+ /** 409: `exists`, `dns_conflict`, `has_stages`, `already_started`, `rollback_failed`, `redrive_failed`. */
116
+ export class Conflict extends Schema.TaggedError<Conflict, { readonly brand: unique symbol }>()(
117
+ 'Conflict',
118
+ errorFields,
119
+ ) {}
120
+
121
+ /** 422 `invalid_manifest`: the deployment's `plat.config.ts` doesn't validate. */
122
+ export class InvalidManifest extends Schema.TaggedError<InvalidManifest, { readonly brand: unique symbol }>()(
123
+ 'InvalidManifest',
124
+ errorFields,
125
+ ) {
126
+ static readonly of = (message: string) => new InvalidManifest({ code: 'invalid_manifest', message });
127
+ }
128
+
129
+ /** 429 `limit`: an app or stage limit from `platform.config.ts`. */
130
+ export class LimitReached extends Schema.TaggedError<LimitReached, { readonly brand: unique symbol }>()(
131
+ 'LimitReached',
132
+ errorFields,
133
+ ) {
134
+ static readonly of = (message: string) => new LimitReached({ code: 'limit', message });
135
+ }
136
+
137
+ export const BadRequestError = onTheWire('BadRequest', BadRequest, 400);
138
+ export const UnauthenticatedError = onTheWire('Unauthenticated', Unauthenticated, 401);
139
+ export const ForbiddenError = onTheWire('Forbidden', Forbidden, 403);
140
+ export const NotFoundError = onTheWire('NotFound', NotFound, 404);
141
+ export const ConflictError = onTheWire('Conflict', Conflict, 409);
142
+ export const InvalidManifestError = onTheWire('InvalidManifest', InvalidManifest, 422);
143
+ export const LimitReachedError = onTheWire('LimitReached', LimitReached, 429);
144
+
145
+ /** Every API error; a 500 is a defect, answered by the platform's server wrapper. */
146
+ export type ApiError =
147
+ | BadRequest
148
+ | Unauthenticated
149
+ | Forbidden
150
+ | NotFound
151
+ | Conflict
152
+ | InvalidManifest
153
+ | LimitReached;
154
+
155
+ /** Errors any endpoint may answer with. */
156
+ const errors = [
157
+ BadRequestError,
158
+ UnauthenticatedError,
159
+ ForbiddenError,
160
+ NotFoundError,
161
+ ConflictError,
162
+ InvalidManifestError,
163
+ LimitReachedError,
164
+ ] as const;
165
+
166
+ // ---------------------------------------------------------------------------
167
+ // Who is calling
168
+ // ---------------------------------------------------------------------------
169
+
170
+ export interface MemberPrincipal {
171
+ readonly kind: 'member';
172
+ readonly github: string;
173
+ readonly role: MemberRole;
174
+ }
175
+
176
+ /** A GitHub Actions run, identified by its OIDC token. */
177
+ export interface CiPrincipal {
178
+ readonly kind: 'ci';
179
+ readonly repository: string;
180
+ readonly repositoryOwner: string;
181
+ readonly ref: string;
182
+ readonly eventName: string;
183
+ readonly sha?: string | undefined;
184
+ readonly actor?: string | undefined;
185
+ readonly runId?: string | undefined;
186
+ }
187
+
188
+ export type Principal = MemberPrincipal | CiPrincipal;
189
+
190
+ /** The caller, provided by `Authenticated`. */
191
+ export class CurrentPrincipal extends Context.Service<CurrentPrincipal, Principal>()(
192
+ '@ericminassian/platform-core/CurrentPrincipal',
193
+ ) {}
194
+
195
+ /**
196
+ * Requires a platform token, a GitHub Actions OIDC token or the console
197
+ * cookie (with the CSRF header on writes), and provides `CurrentPrincipal`.
198
+ * Endpoints narrow to members or admins themselves.
199
+ */
200
+ export class Authenticated extends HttpApiMiddleware.Service<Authenticated, { provides: CurrentPrincipal }>()(
201
+ '@ericminassian/platform-core/Authenticated',
202
+ { error: [UnauthenticatedError, ForbiddenError] },
203
+ ) {}
204
+
205
+ /** Header the console sends on every request; cross-site forms can't set it (CSRF guard). */
206
+ export const CSRF_HEADER = 'x-platform-csrf';
207
+
208
+ /**
209
+ * Answers a request whose path, query or body fails its schema with a 400
210
+ * `bad_request` in the API's error body, where Effect would answer an empty
211
+ * 400. Applies to every endpoint.
212
+ */
213
+ export class RequestValidation extends HttpApiMiddleware.Service<RequestValidation>()(
214
+ '@ericminassian/platform-core/RequestValidation',
215
+ { error: BadRequestError },
216
+ ) {}
217
+
218
+ // ---------------------------------------------------------------------------
219
+ // Endpoints
220
+ // ---------------------------------------------------------------------------
221
+
222
+ const app = { app: Schema.String };
223
+ const appStage = { app: Schema.String, stage: Schema.String };
224
+ /** `?stage=` defaults to prod; the server validates the name. */
225
+ const stageQuery = { stage: Schema.optional(Schema.String) };
226
+ /** `?range=1h|24h|7d|30d` or `?from=&to=` (epoch ms or ISO), and `?res=1m|1h|1d`. */
227
+ const rangeQuery = {
228
+ ...stageQuery,
229
+ from: Schema.optional(Schema.String),
230
+ to: Schema.optional(Schema.String),
231
+ range: Schema.optional(Schema.String),
232
+ res: Schema.optional(Schema.String),
233
+ };
234
+ const limit = Schema.optional(Schema.Int);
235
+
236
+ export class SessionApi extends HttpApiGroup.make('session').add(
237
+ /** Exchanges a GitHub token for a platform token (`plat login`). */
238
+ HttpApiEndpoint.post('cliLogin', '/auth/cli', {
239
+ payload: CliLoginRequest,
240
+ success: CliLoginResponse,
241
+ error: errors,
242
+ }),
243
+ HttpApiEndpoint.get('me', '/me', { success: MeResponse, error: errors }).middleware(Authenticated),
244
+ ) {}
245
+
246
+ export class AppsApi extends HttpApiGroup.make('apps')
247
+ .add(
248
+ HttpApiEndpoint.get('list', '/apps', { success: Schema.Array(AppSummary), error: errors }),
249
+ HttpApiEndpoint.post('create', '/apps', {
250
+ payload: CreateAppRequest,
251
+ success: AppRecord.pipe(HttpApiSchema.status(201)),
252
+ error: errors,
253
+ }),
254
+ HttpApiEndpoint.get('get', '/apps/:app', { params: app, success: AppSummary, error: errors }),
255
+ HttpApiEndpoint.patch('update', '/apps/:app', {
256
+ params: app,
257
+ payload: UpdateAppRequest,
258
+ success: AppRecord,
259
+ error: errors,
260
+ }),
261
+ /** Refused (409 `has_stages`) while any stage exists. */
262
+ HttpApiEndpoint.delete('remove', '/apps/:app', {
263
+ params: app,
264
+ success: HttpApiSchema.NoContent,
265
+ error: errors,
266
+ }),
267
+ )
268
+ .middleware(Authenticated) {}
269
+
270
+ export class StagesApi extends HttpApiGroup.make('stages')
271
+ .add(
272
+ HttpApiEndpoint.get('list', '/apps/:app/stages', {
273
+ params: app,
274
+ success: Schema.Array(StageRecord),
275
+ error: errors,
276
+ }),
277
+ /** 202 while destroying; 200 when there was nothing left. Prod needs `?confirm=<app>`. */
278
+ HttpApiEndpoint.delete('destroy', '/apps/:app/stages/:stage', {
279
+ params: appStage,
280
+ query: { confirm: Schema.optional(Schema.String) },
281
+ success: [
282
+ StageDestroying.pipe(HttpApiSchema.status(202)),
283
+ StageDestroyed.pipe(HttpApiSchema.status(200)),
284
+ ],
285
+ error: errors,
286
+ }),
287
+ HttpApiEndpoint.post('rollback', '/apps/:app/stages/:stage/rollback', {
288
+ params: appStage,
289
+ /** No body rolls back to the previous deployment. */
290
+ payload: [RollbackRequest, Schema.Null],
291
+ success: RollbackResponse,
292
+ error: errors,
293
+ }),
294
+ )
295
+ .middleware(Authenticated) {}
296
+
297
+ export class DeploymentsApi extends HttpApiGroup.make('deployments')
298
+ .add(
299
+ /** Newest first, without event logs or manifests. */
300
+ HttpApiEndpoint.get('list', '/apps/:app/deployments', {
301
+ params: app,
302
+ query: { stage: Schema.optional(Schema.String), limit },
303
+ success: Schema.Array(DeploymentRecord),
304
+ error: errors,
305
+ }),
306
+ /** Records the deployment and returns presigned upload forms; `start` runs it. */
307
+ HttpApiEndpoint.post('create', '/apps/:app/deployments', {
308
+ params: app,
309
+ payload: CreateDeploymentRequest,
310
+ success: CreateDeploymentResponse.pipe(HttpApiSchema.status(201)),
311
+ error: errors,
312
+ }),
313
+ HttpApiEndpoint.get('get', '/deployments/:id', {
314
+ params: { id: Schema.String },
315
+ success: DeploymentRecord,
316
+ error: errors,
317
+ }),
318
+ HttpApiEndpoint.post('start', '/deployments/:id/start', {
319
+ params: { id: Schema.String },
320
+ success: DeploymentRecord.pipe(HttpApiSchema.status(202)),
321
+ error: errors,
322
+ }),
323
+ )
324
+ .middleware(Authenticated) {}
325
+
326
+ /** A live log line, or the error that ended the tail. */
327
+ export const TailEvent = Schema.Union([
328
+ Schema.Struct({ event: Schema.Literal('line'), data: Schema.fromJsonString(LogLine) }),
329
+ Schema.Struct({ event: Schema.Literal('error'), data: Schema.String }),
330
+ ]);
331
+
332
+ export class ObserveApi extends HttpApiGroup.make('observe')
333
+ .add(
334
+ HttpApiEndpoint.get('metrics', '/apps/:app/metrics', {
335
+ params: app,
336
+ query: rangeQuery,
337
+ success: MetricsResponse,
338
+ error: errors,
339
+ }),
340
+ HttpApiEndpoint.get('routes', '/apps/:app/routes', {
341
+ params: app,
342
+ query: rangeQuery,
343
+ success: Schema.Array(RouteStats),
344
+ error: errors,
345
+ }),
346
+ HttpApiEndpoint.get('jobs', '/apps/:app/jobs', {
347
+ params: app,
348
+ query: rangeQuery,
349
+ success: JobsResponse,
350
+ error: errors,
351
+ }),
352
+ HttpApiEndpoint.get('queues', '/apps/:app/queues', {
353
+ params: app,
354
+ query: stageQuery,
355
+ success: Schema.Array(QueueStats),
356
+ error: errors,
357
+ }),
358
+ HttpApiEndpoint.get('errors', '/apps/:app/errors', {
359
+ params: app,
360
+ query: { ...stageQuery, status: Schema.optional(ErrorStatus) },
361
+ success: Schema.Array(ErrorGroup),
362
+ error: errors,
363
+ }),
364
+ HttpApiEndpoint.patch('updateError', '/apps/:app/errors/:fingerprint', {
365
+ params: { ...app, fingerprint: Schema.String },
366
+ query: stageQuery,
367
+ payload: UpdateErrorRequest,
368
+ success: UpdateErrorRequest,
369
+ error: errors,
370
+ }),
371
+ HttpApiEndpoint.get('uptime', '/apps/:app/uptime', {
372
+ params: app,
373
+ query: rangeQuery,
374
+ success: Schema.Array(UptimePoint),
375
+ error: errors,
376
+ }),
377
+ HttpApiEndpoint.get('cost', '/apps/:app/cost', {
378
+ params: app,
379
+ query: { days: Schema.optional(Schema.Int) },
380
+ success: CostResponse,
381
+ error: errors,
382
+ }),
383
+ /** Logs Insights search; `next` pages on. */
384
+ HttpApiEndpoint.get('logs', '/apps/:app/logs', {
385
+ params: app,
386
+ query: {
387
+ ...rangeQuery,
388
+ q: Schema.optional(Schema.String),
389
+ stream: Schema.optional(Schema.Literals(['web', 'worker'])),
390
+ limit,
391
+ next: Schema.optional(Schema.String),
392
+ },
393
+ success: LogsResponse,
394
+ error: errors,
395
+ }),
396
+ /**
397
+ * Server-sent events: `line` (a `LogLine` as JSON) as logs arrive, `error` if
398
+ * the tail fails. A comment every 20 s keeps the connection open: CloudFront
399
+ * drops origin connections that stay idle.
400
+ */
401
+ HttpApiEndpoint.get('tail', '/apps/:app/logs/tail', {
402
+ params: app,
403
+ query: { ...stageQuery, q: Schema.optional(Schema.String) },
404
+ success: HttpApiSchema.StreamSse({ events: TailEvent, keepAlive: '20 seconds' }),
405
+ error: errors,
406
+ }),
407
+ HttpApiEndpoint.get('trace', '/apps/:app/traces/:trace', {
408
+ params: { ...app, trace: Schema.String },
409
+ query: rangeQuery,
410
+ success: TraceResponse,
411
+ error: errors,
412
+ }),
413
+ )
414
+ .middleware(Authenticated) {}
415
+
416
+ /** `?scope=shared` targets the app-wide secret; otherwise the stage (`?stage=`, default prod). */
417
+ const secretQuery = { ...stageQuery, scope: Schema.optional(Schema.Literals(['shared', 'stage'])) };
418
+
419
+ export class ManageApi extends HttpApiGroup.make('manage')
420
+ .add(
421
+ HttpApiEndpoint.get('collections', '/apps/:app/data/collections', {
422
+ params: app,
423
+ query: stageQuery,
424
+ success: DataCollections,
425
+ error: errors,
426
+ }),
427
+ HttpApiEndpoint.get('items', '/apps/:app/data/items', {
428
+ params: app,
429
+ query: {
430
+ ...stageQuery,
431
+ collection: Schema.String,
432
+ partition: Schema.optional(Schema.String),
433
+ cursor: Schema.optional(Schema.String),
434
+ limit,
435
+ },
436
+ success: DataPage,
437
+ error: errors,
438
+ }),
439
+ HttpApiEndpoint.get('storage', '/apps/:app/storage', {
440
+ params: app,
441
+ query: {
442
+ ...stageQuery,
443
+ store: Schema.optional(Schema.String),
444
+ prefix: Schema.optional(Schema.String),
445
+ cursor: Schema.optional(Schema.String),
446
+ },
447
+ success: StorageResponse,
448
+ error: errors,
449
+ }),
450
+ HttpApiEndpoint.get('storageUrl', '/apps/:app/storage/url', {
451
+ params: app,
452
+ query: { ...stageQuery, store: Schema.String, key: Schema.String },
453
+ success: UrlResponse,
454
+ error: errors,
455
+ }),
456
+ HttpApiEndpoint.get('secrets', '/apps/:app/secrets', {
457
+ params: app,
458
+ query: stageQuery,
459
+ success: SecretsResponse,
460
+ error: errors,
461
+ }),
462
+ HttpApiEndpoint.put('putSecret', '/apps/:app/secrets/:name', {
463
+ params: { ...app, name: Schema.String },
464
+ query: secretQuery,
465
+ payload: PutSecretRequest,
466
+ success: HttpApiSchema.NoContent,
467
+ error: errors,
468
+ }),
469
+ HttpApiEndpoint.delete('deleteSecret', '/apps/:app/secrets/:name', {
470
+ params: { ...app, name: Schema.String },
471
+ query: secretQuery,
472
+ success: HttpApiSchema.NoContent,
473
+ error: errors,
474
+ }),
475
+ HttpApiEndpoint.post('runCron', '/apps/:app/crons/:name/run', {
476
+ params: { ...app, name: Schema.String },
477
+ query: stageQuery,
478
+ success: CronRunResponse.pipe(HttpApiSchema.status(202)),
479
+ error: errors,
480
+ }),
481
+ HttpApiEndpoint.post('redrive', '/apps/:app/queues/:name/redrive', {
482
+ params: { ...app, name: Schema.String },
483
+ query: stageQuery,
484
+ success: RedriveResponse.pipe(HttpApiSchema.status(202)),
485
+ error: errors,
486
+ }),
487
+ )
488
+ .middleware(Authenticated) {}
489
+
490
+ export class AdminApi extends HttpApiGroup.make('admin')
491
+ .add(HttpApiEndpoint.get('overview', '/admin/overview', { success: AdminOverview, error: errors }))
492
+ .middleware(Authenticated) {}
493
+
494
+ export class PlatformApi extends HttpApi.make('platform')
495
+ .add(SessionApi)
496
+ .add(AppsApi)
497
+ .add(StagesApi)
498
+ .add(DeploymentsApi)
499
+ .add(ObserveApi)
500
+ .add(ManageApi)
501
+ .add(AdminApi)
502
+ .prefix('/v1')
503
+ // After every group: `middleware` only reaches the endpoints added so far.
504
+ .middleware(RequestValidation) {}
@@ -1,5 +1,9 @@
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: 'notfound' };
4
8
 
5
9
  export declare function decide(rec: RouteRecord | null | undefined, uri: string): RouteDecision;
@@ -9,11 +9,16 @@
9
9
  // s - static key prefix in the sites bucket, e.g. "foo/prod/d01j..." , optional
10
10
  // r - server route prefixes when both o and s exist, e.g. ["/api/"]
11
11
  // spa - 1 to serve index.html for unknown non-file paths
12
- // returns { t: 'server' } | { t: 'static', key: '/<prefix>/<path>' } | { t: 'notfound' }
12
+ // returns { t: 'server' } | { t: 'static', key: '/<prefix>/<path>' } | { t: 'health' } | { t: 'notfound' }
13
+ // health - the router answers /__platform/health itself (HealthResponse with rec.d as the
14
+ // revision): a stage without a server has nothing else to report what it serves.
13
15
 
14
16
  export function decide(rec, uri) {
15
17
  if (!rec || (!rec.o && !rec.s)) return { t: 'notfound' };
16
- if (uri.indexOf('/__platform/') === 0) return rec.o ? { t: 'server' } : { t: 'notfound' };
18
+ if (uri.indexOf('/__platform/') === 0) {
19
+ if (rec.o) return { t: 'server' };
20
+ return uri === '/__platform/health' ? { t: 'health' } : { t: 'notfound' };
21
+ }
17
22
  if (!rec.s) return { t: 'server' };
18
23
  if (rec.o) {
19
24
  var routes = rec.r || [];
package/src/router.ts CHANGED
@@ -16,7 +16,7 @@ export interface RouteRecord {
16
16
  /** Static prefix in the sites bucket (no leading slash). */
17
17
  s?: string;
18
18
  /** Server route prefixes (only meaningful when both `o` and `s` exist). */
19
- r?: string[];
19
+ r?: readonly string[];
20
20
  spa?: 0 | 1;
21
21
  }
22
22