@ericminassian/platform-core 0.3.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 (88) hide show
  1. package/dist/api.d.ts +942 -45
  2. package/dist/api.js +372 -13
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.js +5 -2
  5. package/dist/auth.js.map +1 -1
  6. package/dist/base64url.d.ts +3 -0
  7. package/dist/base64url.js +15 -0
  8. package/dist/base64url.js.map +1 -0
  9. package/dist/bindings.d.ts +62 -12
  10. package/dist/bindings.js +1 -1
  11. package/dist/bindings.js.map +1 -1
  12. package/dist/cloudfront-function.d.ts +5 -1
  13. package/dist/cloudfront-function.js +64 -2
  14. package/dist/cloudfront-function.js.map +1 -1
  15. package/dist/compute.d.ts +52 -0
  16. package/dist/compute.js +65 -0
  17. package/dist/compute.js.map +1 -0
  18. package/dist/config.d.ts +18 -0
  19. package/dist/config.js +9 -0
  20. package/dist/config.js.map +1 -1
  21. package/dist/constants.d.ts +56 -1
  22. package/dist/constants.js +56 -1
  23. package/dist/constants.js.map +1 -1
  24. package/dist/email.d.ts +84 -0
  25. package/dist/email.js +111 -0
  26. package/dist/email.js.map +1 -0
  27. package/dist/fingerprint.d.ts +9 -0
  28. package/dist/fingerprint.js +19 -0
  29. package/dist/fingerprint.js.map +1 -0
  30. package/dist/index.d.ts +6 -0
  31. package/dist/index.js +6 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/jobs.d.ts +111 -0
  34. package/dist/jobs.js +214 -0
  35. package/dist/jobs.js.map +1 -0
  36. package/dist/manifest.d.ts +270 -29
  37. package/dist/manifest.js +190 -22
  38. package/dist/manifest.js.map +1 -1
  39. package/dist/naming.d.ts +83 -7
  40. package/dist/naming.js +89 -8
  41. package/dist/naming.js.map +1 -1
  42. package/dist/platform-api.d.ts +3733 -1278
  43. package/dist/platform-api.js +120 -8
  44. package/dist/platform-api.js.map +1 -1
  45. package/dist/realtime.d.ts +139 -0
  46. package/dist/realtime.js +201 -0
  47. package/dist/realtime.js.map +1 -0
  48. package/dist/router/decide.d.ts +2 -0
  49. package/dist/router/decide.js +38 -6
  50. package/dist/router.d.ts +35 -13
  51. package/dist/router.js +36 -0
  52. package/dist/router.js.map +1 -1
  53. package/dist/runtime-config.d.ts +57 -0
  54. package/dist/runtime-config.js +12 -0
  55. package/dist/runtime-config.js.map +1 -1
  56. package/dist/storage.d.ts +55 -0
  57. package/dist/storage.js +112 -0
  58. package/dist/storage.js.map +1 -0
  59. package/dist/telemetry.d.ts +124 -19
  60. package/dist/telemetry.js +97 -21
  61. package/dist/telemetry.js.map +1 -1
  62. package/dist/web-compute.d.ts +191 -0
  63. package/dist/web-compute.js +257 -0
  64. package/dist/web-compute.js.map +1 -0
  65. package/package.json +19 -7
  66. package/src/api.ts +445 -15
  67. package/src/auth.ts +6 -2
  68. package/src/base64url.ts +13 -0
  69. package/src/bindings.ts +67 -6
  70. package/src/cloudfront-function.ts +64 -2
  71. package/src/compute.ts +86 -0
  72. package/src/config.ts +31 -1
  73. package/src/constants.ts +64 -1
  74. package/src/email.ts +168 -0
  75. package/src/fingerprint.ts +20 -0
  76. package/src/index.ts +6 -0
  77. package/src/jobs.ts +281 -0
  78. package/src/manifest.ts +415 -45
  79. package/src/naming.ts +93 -9
  80. package/src/platform-api.ts +134 -8
  81. package/src/realtime.ts +298 -0
  82. package/src/router/decide.d.ts +2 -0
  83. package/src/router/decide.js +38 -6
  84. package/src/router.ts +33 -13
  85. package/src/runtime-config.ts +70 -0
  86. package/src/storage.ts +120 -0
  87. package/src/telemetry.ts +104 -21
  88. package/src/web-compute.ts +342 -0
package/src/api.ts CHANGED
@@ -11,6 +11,7 @@ import { Schema, SchemaGetter } from 'effect';
11
11
  import { MemberRole } from './config.ts';
12
12
  import { ResolvedManifest } from './manifest.ts';
13
13
  import { Resolution, TelemetryEvent } from './telemetry.ts';
14
+ import { WEB_COMPUTE, WEB_COMPUTE_SETTINGS } from './web-compute.ts';
14
15
 
15
16
  const optional = Schema.optional;
16
17
 
@@ -33,6 +34,27 @@ export type AppRecord = typeof AppRecord.Type;
33
34
  export const StageStatus = Schema.Literals(['active', 'deploying', 'failed', 'destroying', 'destroyed']);
34
35
  export type StageStatus = typeof StageStatus.Type;
35
36
 
37
+ /** How a server runs (`WebCompute`). */
38
+ export const WebComputeMode = Schema.Literals(WEB_COMPUTE);
39
+
40
+ /** Days in a row the other mode was cheaper enough to switch to (`ComputeStreak`). */
41
+ export const ComputeStreakSchema = Schema.Struct({
42
+ to: WebComputeMode,
43
+ days: Schema.Finite,
44
+ day: Schema.String,
45
+ });
46
+
47
+ /** A prod stage's monthly cost in each mode, estimated daily from its traffic (`simulateWebCompute`). */
48
+ export const ComputeEstimate = Schema.Struct({
49
+ at: Schema.String,
50
+ request: Schema.Struct({ monthlyUsd: Schema.Finite, coldStartsPerMonth: Schema.Finite }),
51
+ instance: Schema.Struct({ monthlyUsd: Schema.Finite, environmentHoursPerMonth: Schema.Finite }),
52
+ requestsPerMonth: Schema.Finite,
53
+ /** Days of traffic the month is extrapolated from. */
54
+ days: Schema.Finite,
55
+ });
56
+ export type ComputeEstimate = typeof ComputeEstimate.Type;
57
+
36
58
  export const StageRecord = Schema.Struct({
37
59
  app: Schema.String,
38
60
  stage: Schema.String,
@@ -42,9 +64,15 @@ export const StageRecord = Schema.Struct({
42
64
  preview: Schema.Boolean,
43
65
  currentDeployment: optional(Schema.String),
44
66
  previousDeployment: optional(Schema.String),
45
- /** Web Function revision ids, for instant rollback. */
67
+ /** The server builds: Web Function revision ids, or request-mode function versions. */
46
68
  currentRevision: optional(Schema.String),
47
69
  previousRevision: optional(Schema.String),
70
+ /** How the live deployment's server runs. */
71
+ compute: optional(WebComputeMode),
72
+ /** Prod stages with a server: what each mode would cost a month. */
73
+ computeEstimate: optional(ComputeEstimate),
74
+ /** Set while the other mode is cheaper enough; at three days the platform switches. */
75
+ computeStreak: optional(ComputeStreakSchema),
48
76
  createdAt: Schema.String,
49
77
  updatedAt: Schema.String,
50
78
  });
@@ -74,12 +102,21 @@ export const DeploymentRecord = Schema.Struct({
74
102
  app: Schema.String,
75
103
  stage: Schema.String,
76
104
  status: DeploymentStatus,
77
- /** GitHub username, or `ci:<repo>` for OIDC deploys. */
105
+ /** GitHub username, `ci:<repo>` for OIDC deploys, or `platform` for a compute switch. */
78
106
  actor: Schema.String,
79
107
  commit: optional(Schema.String),
80
108
  ref: optional(Schema.String),
81
109
  message: optional(Schema.String),
110
+ /** The `@ericminassian/platform` version its bundles were built with; absent before 0.4.0. */
111
+ sdk: optional(Schema.String),
82
112
  manifest: optional(ResolvedManifest),
113
+ /** How it runs the server. */
114
+ compute: optional(WebComputeMode),
115
+ /**
116
+ * A switch of the server's mode that the platform made (actor `platform`):
117
+ * the deployment whose build this one runs again, in `compute`.
118
+ */
119
+ computeSwitchOf: optional(Schema.String),
83
120
  url: optional(Schema.String),
84
121
  error: optional(Schema.String),
85
122
  events: Schema.Array(DeploymentEventEntry),
@@ -165,7 +202,14 @@ export type AppSummary = typeof AppSummary.Type;
165
202
  // Stages and deployments
166
203
  // ---------------------------------------------------------------------------
167
204
 
168
- export const ArtifactFile = Schema.Literals(['manifest.json', 'server.zip', 'worker.zip', 'static.zip']);
205
+ /** `services.zip` holds `<service>/index.mjs` (+ `.map`) for each long-running service. */
206
+ export const ArtifactFile = Schema.Literals([
207
+ 'manifest.json',
208
+ 'server.zip',
209
+ 'worker.zip',
210
+ 'static.zip',
211
+ 'services.zip',
212
+ ]);
169
213
  export type ArtifactFile = typeof ArtifactFile.Type;
170
214
 
171
215
  export const PresignedPost = Schema.Struct({
@@ -186,6 +230,8 @@ export const CreateDeploymentRequest = Schema.Struct({
186
230
  commit: optional(Schema.String),
187
231
  ref: optional(Schema.String),
188
232
  message: optional(Schema.String),
233
+ /** The `@ericminassian/platform` version the bundles were built with (`MIN_SDK_VERSION`). */
234
+ sdk: optional(Schema.String),
189
235
  });
190
236
  export type CreateDeploymentRequest = typeof CreateDeploymentRequest.Encoded;
191
237
 
@@ -197,6 +243,7 @@ export const CreateDeploymentResponse = Schema.Struct({
197
243
  'server.zip': optional(PresignedPost),
198
244
  'worker.zip': optional(PresignedPost),
199
245
  'static.zip': optional(PresignedPost),
246
+ 'services.zip': optional(PresignedPost),
200
247
  }),
201
248
  });
202
249
  export type CreateDeploymentResponse = typeof CreateDeploymentResponse.Type;
@@ -258,7 +305,7 @@ export const RouteStats = Schema.Struct({
258
305
  });
259
306
  export type RouteStats = typeof RouteStats.Type;
260
307
 
261
- export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke']);
308
+ export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke', 'service']);
262
309
  export type JobKind = typeof JobKind.Type;
263
310
 
264
311
  export const JobStats = Schema.Struct({
@@ -277,15 +324,209 @@ export const JobsResponse = Schema.Struct({
277
324
  });
278
325
  export type JobsResponse = typeof JobsResponse.Type;
279
326
 
327
+ /** A queue's jobs that aren't running: waiting for their time, and given up on. */
280
328
  export const QueueStats = Schema.Struct({
281
329
  name: Schema.String,
282
- visible: Schema.Finite,
283
- inFlight: Schema.Finite,
330
+ /** Retries and delayed sends scheduled for later. */
331
+ scheduled: Schema.Finite,
332
+ /** Its messages in the stage's dead-letter queue (of those `deadLetters` reads). */
284
333
  deadLetter: Schema.Finite,
285
- oldestAgeSeconds: Schema.NullOr(Schema.Finite),
286
334
  });
287
335
  export type QueueStats = typeof QueueStats.Type;
288
336
 
337
+ /** One message in the stage's dead-letter queue (core `readDeadLetter`). */
338
+ export const DeadLetterItem = Schema.Struct({
339
+ /** The SQS message id: what redrive and discard take. */
340
+ id: Schema.String,
341
+ /** `unknown`: a message the platform didn't write; it can only be discarded. */
342
+ kind: Schema.Literals(['queue', 'event', 'cron', 'invoke', 'unknown']),
343
+ name: Schema.String,
344
+ attempts: Schema.NullOr(Schema.Finite),
345
+ error: Schema.Struct({ name: Schema.String, message: Schema.String }),
346
+ /** ISO time, when the writer recorded one. */
347
+ failedAt: Schema.NullOr(Schema.String),
348
+ /** Who gave up on it: the SDK, Lambda, Scheduler or EventBridge. */
349
+ source: Schema.Literals(['sdk', 'lambda', 'scheduler', 'eventbridge', 'unknown']),
350
+ /** The message body, event detail or invoke payload, as JSON, cut to a few hundred chars. */
351
+ preview: Schema.String,
352
+ });
353
+ export type DeadLetterItem = typeof DeadLetterItem.Type;
354
+
355
+ export const DeadLettersResponse = Schema.Struct({
356
+ /** Messages in the queue (SQS's approximate count). */
357
+ total: Schema.Finite,
358
+ /** Up to `DEAD_LETTERS_READ` of them. */
359
+ items: Schema.Array(DeadLetterItem),
360
+ });
361
+ export type DeadLettersResponse = typeof DeadLettersResponse.Type;
362
+
363
+ /** How many dead letters the API reads for a list. */
364
+ export const DEAD_LETTERS_READ = 100;
365
+
366
+ /** Redrive or discard: the given dead letters, or (no `ids`) all of them. */
367
+ export const DeadLetterAction = Schema.Struct({ ids: Schema.optional(Schema.Array(Schema.String)) });
368
+ export type DeadLetterAction = typeof DeadLetterAction.Encoded;
369
+
370
+ export const DeadLetterActionResponse = Schema.Struct({ count: Schema.Finite });
371
+ export type DeadLetterActionResponse = typeof DeadLetterActionResponse.Type;
372
+
373
+ /** Per-namespace AppSync Events counts in one bucket (CloudWatch `Sum`s). */
374
+ export const RealtimePoint = Schema.Struct({
375
+ ts: Schema.String,
376
+ /** Events published (`InboundMessages`; each 5 KB counts once). */
377
+ events: Schema.Finite,
378
+ /** Successful publish requests (up to 5 events each). */
379
+ publishes: Schema.Finite,
380
+ /** Successful subscribes. */
381
+ subscribes: Schema.Finite,
382
+ /** Publishes and subscribes refused or failed (client and server errors). */
383
+ errors: Schema.Finite,
384
+ });
385
+ export type RealtimePoint = typeof RealtimePoint.Type;
386
+
387
+ /**
388
+ * A stage's realtime activity. AppSync reports deliveries (`OutboundMessages`)
389
+ * and connections only for the whole Event API, not per namespace, so they
390
+ * can't be shown per app.
391
+ */
392
+ export const RealtimeStatsResponse = Schema.Struct({
393
+ app: Schema.String,
394
+ stage: Schema.String,
395
+ /** False when the live deployment declares no `realtime`; the rest is then empty. */
396
+ enabled: Schema.Boolean,
397
+ subscribe: optional(Schema.Literals(['public', 'signed-in'])),
398
+ channels: Schema.Array(Schema.String),
399
+ res: Resolution,
400
+ totals: Schema.Struct({
401
+ events: Schema.Finite,
402
+ publishes: Schema.Finite,
403
+ subscribes: Schema.Finite,
404
+ errors: Schema.Finite,
405
+ }),
406
+ points: Schema.Array(RealtimePoint),
407
+ });
408
+ export type RealtimeStatsResponse = typeof RealtimeStatsResponse.Type;
409
+
410
+ /** One custom metric (`Metrics.count`/`value`) in one bucket: how many values, and their sum. */
411
+ export const CustomMetricPoint = Schema.Struct({
412
+ ts: Schema.String,
413
+ count: Schema.Finite,
414
+ sum: Schema.Finite,
415
+ });
416
+ export type CustomMetricPoint = typeof CustomMetricPoint.Type;
417
+
418
+ /**
419
+ * A custom metric over the range. `Metrics.count(name, n)` records `n` with
420
+ * unit `count`, so `sum` is the total; for `Metrics.value`, `sum / count` is
421
+ * the average.
422
+ */
423
+ export const CustomMetricStats = Schema.Struct({
424
+ name: Schema.String,
425
+ unit: optional(Schema.String),
426
+ count: Schema.Finite,
427
+ sum: Schema.Finite,
428
+ /** One per bucket in the range, zero-filled. */
429
+ points: Schema.Array(CustomMetricPoint),
430
+ });
431
+ export type CustomMetricStats = typeof CustomMetricStats.Type;
432
+
433
+ /** A stage's custom metrics recorded in the range, by name. */
434
+ export const CustomMetricsResponse = Schema.Struct({
435
+ app: Schema.String,
436
+ stage: Schema.String,
437
+ res: Resolution,
438
+ metrics: Schema.Array(CustomMetricStats),
439
+ });
440
+ export type CustomMetricsResponse = typeof CustomMetricsResponse.Type;
441
+
442
+ /** One rate limit's checks in one bucket. */
443
+ export const LimitPoint = Schema.Struct({
444
+ ts: Schema.String,
445
+ allowed: Schema.Finite,
446
+ denied: Schema.Finite,
447
+ });
448
+ export type LimitPoint = typeof LimitPoint.Type;
449
+
450
+ /** A rate limit's checks over the range, by its name in `RateLimits`. */
451
+ export const LimitStats = Schema.Struct({
452
+ name: Schema.String,
453
+ allowed: Schema.Finite,
454
+ denied: Schema.Finite,
455
+ /** One per bucket in the range, zero-filled. */
456
+ points: Schema.Array(LimitPoint),
457
+ });
458
+ export type LimitStats = typeof LimitStats.Type;
459
+
460
+ /** A stage's rate limits that were checked in the range, most denied first. */
461
+ export const LimitsResponse = Schema.Struct({
462
+ app: Schema.String,
463
+ stage: Schema.String,
464
+ res: Resolution,
465
+ limits: Schema.Array(LimitStats),
466
+ });
467
+ export type LimitsResponse = typeof LimitsResponse.Type;
468
+
469
+ /** Per-tenant SES counts in one bucket (CloudWatch `Sum`s of `AWS/SES` by tenant). */
470
+ export const EmailPoint = Schema.Struct({
471
+ ts: Schema.String,
472
+ sends: Schema.Finite,
473
+ deliveries: Schema.Finite,
474
+ bounces: Schema.Finite,
475
+ complaints: Schema.Finite,
476
+ });
477
+ export type EmailPoint = typeof EmailPoint.Type;
478
+
479
+ /**
480
+ * Whether SES lets a stage send. `paused` comes with who paused it: `policy`
481
+ * (the tenant's reputation policy, after bad bounce or complaint rates),
482
+ * `manual` (someone changed it in SES), or `aws` (only AWS Support can lift
483
+ * that one).
484
+ */
485
+ export const EmailSending = Schema.Struct({
486
+ status: Schema.Literals(['enabled', 'paused']),
487
+ pausedBy: optional(Schema.Literals(['policy', 'manual', 'aws'])),
488
+ /** SES's reason, when paused. */
489
+ cause: optional(Schema.String),
490
+ since: optional(Schema.String),
491
+ });
492
+ export type EmailSending = typeof EmailSending.Type;
493
+
494
+ /** A stage's email: its sender, whether it can send, today's usage and SES's counts over the range. */
495
+ export const EmailStatsResponse = Schema.Struct({
496
+ app: Schema.String,
497
+ stage: Schema.String,
498
+ /** False when the live deployment declares no `email`; the rest is then empty. */
499
+ enabled: Schema.Boolean,
500
+ /** `"Todo" <todo@mail…>`. */
501
+ from: optional(Schema.String),
502
+ sending: optional(EmailSending),
503
+ /** Recipients sent today (UTC) and the stage's daily limit. */
504
+ today: optional(Schema.Struct({ sent: Schema.Finite, limit: Schema.Finite })),
505
+ res: Resolution,
506
+ totals: Schema.Struct({
507
+ sends: Schema.Finite,
508
+ deliveries: Schema.Finite,
509
+ bounces: Schema.Finite,
510
+ complaints: Schema.Finite,
511
+ }),
512
+ points: Schema.Array(EmailPoint),
513
+ });
514
+ export type EmailStatsResponse = typeof EmailStatsResponse.Type;
515
+
516
+ /** An address on a stage's suppression list: SES no longer sends to it from this stage. */
517
+ export const SuppressedAddress = Schema.Struct({
518
+ address: Schema.String,
519
+ reason: Schema.Literals(['bounce', 'complaint']),
520
+ since: Schema.String,
521
+ });
522
+ export type SuppressedAddress = typeof SuppressedAddress.Type;
523
+
524
+ export const SuppressedResponse = Schema.Struct({
525
+ items: Schema.Array(SuppressedAddress),
526
+ next: optional(Schema.String),
527
+ });
528
+ export type SuppressedResponse = typeof SuppressedResponse.Type;
529
+
289
530
  export const ErrorStatus = Schema.Literals(['open', 'resolved', 'ignored']);
290
531
  export type ErrorStatus = typeof ErrorStatus.Type;
291
532
 
@@ -312,9 +553,13 @@ export type ErrorGroup = typeof ErrorGroup.Type;
312
553
  export const UpdateErrorRequest = Schema.Struct({ status: ErrorStatus });
313
554
  export type UpdateErrorRequest = typeof UpdateErrorRequest.Type;
314
555
 
556
+ /** Log stream of a line: `web`, `worker`, or `service:<name>` for a long-running service. */
557
+ export const LogStream = Schema.String;
558
+ export type LogStream = typeof LogStream.Type;
559
+
315
560
  export const LogLine = Schema.Struct({
316
561
  ts: Schema.String,
317
- stream: Schema.Literals(['web', 'worker']),
562
+ stream: LogStream,
318
563
  level: optional(Schema.String),
319
564
  message: Schema.String,
320
565
  trace: optional(Schema.String),
@@ -334,19 +579,72 @@ export const TraceResponse = Schema.Struct({
334
579
  });
335
580
  export type TraceResponse = typeof TraceResponse.Type;
336
581
 
337
- export const UptimePoint = Schema.Struct({
582
+ /** A GET of the stage's health path, for a stage that served nothing lately or has no server. */
583
+ export const UptimeCheck = Schema.Struct({
338
584
  ts: Schema.String,
339
585
  ok: Schema.Boolean,
586
+ source: Schema.Literal('check'),
587
+ /** The HTTP status; 0 when nothing answered within 10 s. */
340
588
  status: Schema.Finite,
341
589
  ms: Schema.Finite,
342
590
  });
591
+ export type UptimeCheck = typeof UptimeCheck.Type;
592
+
593
+ /** The stage's own requests in the 10 minutes before `ts`: down when at least 3, half of them 5xx. */
594
+ export const UptimeTraffic = Schema.Struct({
595
+ ts: Schema.String,
596
+ ok: Schema.Boolean,
597
+ source: Schema.Literal('traffic'),
598
+ req: Schema.Finite,
599
+ s5xx: Schema.Finite,
600
+ });
601
+ export type UptimeTraffic = typeof UptimeTraffic.Type;
602
+
603
+ export const UptimePoint = Schema.Union([UptimeCheck, UptimeTraffic]);
343
604
  export type UptimePoint = typeof UptimePoint.Type;
344
605
 
606
+ /** Monthly cost of one container if it runs all month (`estimateContainerCost`). */
607
+ export const MonthlyContainerCost = Schema.Struct({
608
+ computeUsd: Schema.Finite,
609
+ publicIpv4Usd: Schema.Finite,
610
+ totalUsd: Schema.Finite,
611
+ });
612
+
613
+ /**
614
+ * Something billed for as long as it runs, estimated from its size because
615
+ * Cost Explorer lags a day and doesn't attribute every part of it to the
616
+ * app (a container's public IPv4 address).
617
+ */
618
+ export const AlwaysOnCost = Schema.Struct({
619
+ stage: Schema.String,
620
+ kind: Schema.Literal('service'),
621
+ name: Schema.String,
622
+ /** `0.25 vCPU · 512 MB · Spot`. */
623
+ detail: Schema.String,
624
+ monthly: MonthlyContainerCost,
625
+ });
626
+ export type AlwaysOnCost = typeof AlwaysOnCost.Type;
627
+
628
+ /** A non-preview stage's server: how it runs, and (prod) what each mode would cost. */
629
+ export const StageCompute = Schema.Struct({
630
+ stage: Schema.String,
631
+ /** `web.compute` of the live deployment. */
632
+ setting: Schema.Literals(WEB_COMPUTE_SETTINGS),
633
+ compute: WebComputeMode,
634
+ estimate: optional(ComputeEstimate),
635
+ streak: optional(ComputeStreakSchema),
636
+ });
637
+ export type StageCompute = typeof StageCompute.Type;
638
+
345
639
  export const CostResponse = Schema.Struct({
346
640
  app: Schema.String,
347
641
  currency: Schema.Literal('USD'),
348
642
  days: Schema.Array(Schema.Struct({ date: Schema.String, usd: Schema.Finite })),
349
643
  monthToDateUsd: Schema.Finite,
644
+ /** Services of the app's non-preview stages (previews run theirs for minutes after a deploy). */
645
+ alwaysOn: optional(Schema.Array(AlwaysOnCost)),
646
+ /** Servers of the app's non-preview stages (previews run request mode). */
647
+ compute: optional(Schema.Array(StageCompute)),
350
648
  });
351
649
  export type CostResponse = typeof CostResponse.Type;
352
650
 
@@ -403,9 +701,12 @@ export const StoredObjectInfo = Schema.Struct({
403
701
  });
404
702
  export type StoredObjectInfo = typeof StoredObjectInfo.Type;
405
703
 
406
- /** `GET /v1/apps/:app/storage`: the declared stores without `?store=`, a listing with it. */
704
+ /**
705
+ * `GET /v1/apps/:app/storage`: the declared stores (and which of them the
706
+ * edge serves) without `?store=`, a listing with it.
707
+ */
407
708
  export const StorageResponse = Schema.Union([
408
- Schema.Struct({ stores: Schema.Array(Schema.String) }),
709
+ Schema.Struct({ stores: Schema.Array(Schema.String), public: optional(Schema.Array(Schema.String)) }),
409
710
  Schema.Struct({ objects: Schema.Array(StoredObjectInfo), cursor: optional(Schema.String) }),
410
711
  ]);
411
712
  export type StorageResponse = typeof StorageResponse.Type;
@@ -414,10 +715,81 @@ export const UrlResponse = Schema.Struct({ url: Schema.String });
414
715
  export type UrlResponse = typeof UrlResponse.Type;
415
716
 
416
717
  export const CronRunResponse = Schema.Struct({ started: Schema.String });
417
- export type CronRunResponse = typeof CronRunResponse.Type;
418
718
 
419
- export const RedriveResponse = Schema.Struct({ taskHandle: Schema.String });
420
- export type RedriveResponse = typeof RedriveResponse.Type;
719
+ // ---------------------------------------------------------------------------
720
+ // Long-running services
721
+ // ---------------------------------------------------------------------------
722
+
723
+ /**
724
+ * - `running`: every desired task is up and the latest rollout finished
725
+ * - `starting`: a rollout or replacement is under way
726
+ * - `failing`: tasks keep stopping before they settle, or the last rollout failed
727
+ * - `stopped`: scaled to zero (a preview past its minutes, or `plat services stop`)
728
+ */
729
+ export const ServiceState = Schema.Literals(['running', 'starting', 'failing', 'stopped']);
730
+ export type ServiceState = typeof ServiceState.Type;
731
+
732
+ export const ServiceInfo = Schema.Struct({
733
+ name: Schema.String,
734
+ /** Size and capacity the live deployment declares. */
735
+ cpu: Schema.Finite,
736
+ memoryMb: Schema.Finite,
737
+ spot: Schema.Boolean,
738
+ state: ServiceState,
739
+ desired: Schema.Finite,
740
+ running: Schema.Finite,
741
+ pending: Schema.Finite,
742
+ /** Deployment whose build the service runs. */
743
+ deployment: optional(Schema.String),
744
+ /** When the current task started. */
745
+ startedAt: optional(Schema.String),
746
+ /** When a preview's stop schedule scales it to zero. */
747
+ stopsAt: optional(Schema.String),
748
+ /** The task that stopped most recently (ECS keeps stopped tasks for about an hour). */
749
+ lastStop: optional(
750
+ Schema.Struct({ at: Schema.String, reason: Schema.String, exitCode: optional(Schema.Finite) }),
751
+ ),
752
+ /** Recent ECS service events, newest first. */
753
+ events: Schema.Array(Schema.Struct({ at: Schema.String, message: Schema.String })),
754
+ /** Containers started in the range: deploys, crashes, Spot replacements. */
755
+ starts: Schema.Finite,
756
+ /** Runs of `run` that failed and were rerun in the same container, in the range. */
757
+ failedRuns: Schema.Finite,
758
+ /** CPU and memory use, % of the task's size (ECS's per-service CloudWatch metrics). */
759
+ points: Schema.Array(
760
+ Schema.Struct({
761
+ ts: Schema.String,
762
+ cpu: Schema.NullOr(Schema.Finite),
763
+ memory: Schema.NullOr(Schema.Finite),
764
+ }),
765
+ ),
766
+ /** If it ran all month. */
767
+ monthly: MonthlyContainerCost,
768
+ });
769
+ export type ServiceInfo = typeof ServiceInfo.Type;
770
+
771
+ export const ServicesResponse = Schema.Struct({
772
+ app: Schema.String,
773
+ stage: Schema.String,
774
+ res: Resolution,
775
+ services: Schema.Array(ServiceInfo),
776
+ });
777
+ export type ServicesResponse = typeof ServicesResponse.Type;
778
+
779
+ export const StartServiceRequest = Schema.Struct({
780
+ /** Stop it again after this many minutes. Previews default to the service's `previewMinutes`. */
781
+ minutes: optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1440 }))),
782
+ });
783
+ export type StartServiceRequest = typeof StartServiceRequest.Encoded;
784
+
785
+ export const ServiceActionResponse = Schema.Struct({
786
+ name: Schema.String,
787
+ /** Tasks the service now asks for (1 running, 0 stopped). */
788
+ desired: Schema.Finite,
789
+ stopsAt: optional(Schema.String),
790
+ });
791
+ export type ServiceActionResponse = typeof ServiceActionResponse.Type;
792
+ export type CronRunResponse = typeof CronRunResponse.Type;
421
793
 
422
794
  // ---------------------------------------------------------------------------
423
795
  // Admin
@@ -425,7 +797,14 @@ export type RedriveResponse = typeof RedriveResponse.Type;
425
797
 
426
798
  export const AdminOverview = Schema.Struct({
427
799
  members: Schema.Array(Schema.Struct({ github: Schema.String, role: MemberRole })),
428
- limits: Schema.Struct({ appsPerMember: Schema.Finite, stagesPerApp: Schema.Finite }),
800
+ limits: Schema.Struct({
801
+ appsPerMember: Schema.Finite,
802
+ stagesPerApp: Schema.Finite,
803
+ emailsPerDay: Schema.Finite,
804
+ edgeRequestsPerMinute: optional(Schema.Finite),
805
+ edgeFloorAt: optional(Schema.Finite),
806
+ servicesPerApp: Schema.Finite,
807
+ }),
429
808
  apps: Schema.Finite,
430
809
  stages: Schema.Finite,
431
810
  previews: Schema.Finite,
@@ -435,6 +814,57 @@ export const AdminOverview = Schema.Struct({
435
814
  });
436
815
  export type AdminOverview = typeof AdminOverview.Type;
437
816
 
817
+ /** Requests the edge's web ACL handled in one bucket (CloudWatch `Sum`s). */
818
+ export const EdgeFloorPoint = Schema.Struct({
819
+ ts: Schema.String,
820
+ /** Blocked by the per-client floor. */
821
+ blocked: Schema.Finite,
822
+ /** Let through (every request the web ACL saw and allowed). */
823
+ allowed: Schema.Finite,
824
+ });
825
+ export type EdgeFloorPoint = typeof EdgeFloorPoint.Type;
826
+
827
+ /** A request the floor blocked, from WAF's sample of the last three hours. */
828
+ export const EdgeFloorSample = Schema.Struct({
829
+ at: Schema.String,
830
+ host: Schema.String,
831
+ client: Schema.String,
832
+ country: optional(Schema.String),
833
+ method: Schema.String,
834
+ path: Schema.String,
835
+ });
836
+ export type EdgeFloorSample = typeof EdgeFloorSample.Type;
837
+
838
+ /** Whether the edge floor is on, since when, and why it turned on or off. */
839
+ export const EdgeFloorState = Schema.Struct({
840
+ on: Schema.Boolean,
841
+ /** Absent until it first turns on. */
842
+ since: optional(Schema.String),
843
+ why: optional(Schema.String),
844
+ });
845
+ export type EdgeFloorState = typeof EdgeFloorState.Type;
846
+
847
+ /**
848
+ * The edge's per-client request floor across every app: on only while the
849
+ * whole edge is busy (`limits.edgeFloorAt`), then `limits.edgeRequestsPerMinute`
850
+ * per client and host. Counts cover the range whether or not it was on then.
851
+ */
852
+ export const EdgeFloorResponse = Schema.Struct({
853
+ /** False when the platform has no floor; the rest is then empty. */
854
+ enabled: Schema.Boolean,
855
+ state: EdgeFloorState,
856
+ /** Requests per client per host per minute while it's on. */
857
+ limit: optional(Schema.Finite),
858
+ /** Requests per minute across the edge that turn it on. */
859
+ threshold: optional(Schema.Finite),
860
+ res: Resolution,
861
+ totals: Schema.Struct({ blocked: Schema.Finite, allowed: Schema.Finite }),
862
+ points: Schema.Array(EdgeFloorPoint),
863
+ /** Newest first. WAF samples a share of requests, so counts here undercount. */
864
+ samples: Schema.Array(EdgeFloorSample),
865
+ });
866
+ export type EdgeFloorResponse = typeof EdgeFloorResponse.Type;
867
+
438
868
  // ---------------------------------------------------------------------------
439
869
  // Errors
440
870
  // ---------------------------------------------------------------------------
package/src/auth.ts CHANGED
@@ -21,7 +21,10 @@ 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). */
24
+ /**
25
+ * Backslashes, spaces, and ASCII control characters (`<= ' '` covers C0 and space).
26
+ * All of them are ASCII, so checking UTF-16 code units one by one is exact.
27
+ */
25
28
  const unsafeInRedirect = (c: string) => c === '\\' || c <= ' ' || c === '\u007f';
26
29
 
27
30
  /**
@@ -30,7 +33,8 @@ const unsafeInRedirect = (c: string) => c === '\\' || c <= ' ' || c === '\u007f'
30
33
  * `//evil.com`), so control characters and spaces are refused too.
31
34
  */
32
35
  export function safeRedirect(target: string | null | undefined): string {
33
- if (!target?.startsWith('/') || target.startsWith('//') || [...target].some(unsafeInRedirect)) return '/';
36
+ if (!target?.startsWith('/') || target.startsWith('//') || target.split('').some(unsafeInRedirect))
37
+ return '/';
34
38
  return target;
35
39
  }
36
40
 
@@ -0,0 +1,13 @@
1
+ /** Unpadded base64url (RFC 4648 §5), without Node's Buffer so it runs anywhere. */
2
+ export function base64url(bytes: Uint8Array): string {
3
+ let bin = '';
4
+ for (const b of bytes) bin += String.fromCharCode(b);
5
+ return btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
6
+ }
7
+
8
+ export function fromBase64url(s: string): Uint8Array<ArrayBuffer> {
9
+ const bin = atob(s.replace(/-/g, '+').replace(/_/g, '/'));
10
+ const out = new Uint8Array(bin.length);
11
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
12
+ return out;
13
+ }