@ericminassian/platform-core 0.3.0 → 0.4.1

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 (92) hide show
  1. package/dist/api.d.ts +1225 -45
  2. package/dist/api.js +471 -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/explore.d.ts +365 -0
  28. package/dist/explore.js +440 -0
  29. package/dist/explore.js.map +1 -0
  30. package/dist/fingerprint.d.ts +9 -0
  31. package/dist/fingerprint.js +19 -0
  32. package/dist/fingerprint.js.map +1 -0
  33. package/dist/index.d.ts +7 -0
  34. package/dist/index.js +7 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/jobs.d.ts +111 -0
  37. package/dist/jobs.js +214 -0
  38. package/dist/jobs.js.map +1 -0
  39. package/dist/manifest.d.ts +270 -29
  40. package/dist/manifest.js +190 -22
  41. package/dist/manifest.js.map +1 -1
  42. package/dist/naming.d.ts +83 -7
  43. package/dist/naming.js +89 -8
  44. package/dist/naming.js.map +1 -1
  45. package/dist/platform-api.d.ts +5897 -1672
  46. package/dist/platform-api.js +218 -8
  47. package/dist/platform-api.js.map +1 -1
  48. package/dist/realtime.d.ts +139 -0
  49. package/dist/realtime.js +201 -0
  50. package/dist/realtime.js.map +1 -0
  51. package/dist/router/decide.d.ts +2 -0
  52. package/dist/router/decide.js +38 -6
  53. package/dist/router.d.ts +35 -13
  54. package/dist/router.js +36 -0
  55. package/dist/router.js.map +1 -1
  56. package/dist/runtime-config.d.ts +57 -0
  57. package/dist/runtime-config.js +12 -0
  58. package/dist/runtime-config.js.map +1 -1
  59. package/dist/storage.d.ts +65 -0
  60. package/dist/storage.js +122 -0
  61. package/dist/storage.js.map +1 -0
  62. package/dist/telemetry.d.ts +135 -20
  63. package/dist/telemetry.js +108 -22
  64. package/dist/telemetry.js.map +1 -1
  65. package/dist/web-compute.d.ts +191 -0
  66. package/dist/web-compute.js +257 -0
  67. package/dist/web-compute.js.map +1 -0
  68. package/package.json +19 -7
  69. package/src/api.ts +564 -15
  70. package/src/auth.ts +6 -2
  71. package/src/base64url.ts +13 -0
  72. package/src/bindings.ts +67 -6
  73. package/src/cloudfront-function.ts +64 -2
  74. package/src/compute.ts +86 -0
  75. package/src/config.ts +31 -1
  76. package/src/constants.ts +64 -1
  77. package/src/email.ts +168 -0
  78. package/src/explore.ts +504 -0
  79. package/src/fingerprint.ts +20 -0
  80. package/src/index.ts +7 -0
  81. package/src/jobs.ts +281 -0
  82. package/src/manifest.ts +415 -45
  83. package/src/naming.ts +93 -9
  84. package/src/platform-api.ts +249 -8
  85. package/src/realtime.ts +298 -0
  86. package/src/router/decide.d.ts +2 -0
  87. package/src/router/decide.js +38 -6
  88. package/src/router.ts +33 -13
  89. package/src/runtime-config.ts +70 -0
  90. package/src/storage.ts +131 -0
  91. package/src/telemetry.ts +115 -22
  92. package/src/web-compute.ts +342 -0
package/src/api.ts CHANGED
@@ -9,8 +9,10 @@
9
9
  */
10
10
  import { Schema, SchemaGetter } from 'effect';
11
11
  import { MemberRole } from './config.ts';
12
+ import { QueryResolution } from './explore.ts';
12
13
  import { ResolvedManifest } from './manifest.ts';
13
14
  import { Resolution, TelemetryEvent } from './telemetry.ts';
15
+ import { WEB_COMPUTE, WEB_COMPUTE_SETTINGS } from './web-compute.ts';
14
16
 
15
17
  const optional = Schema.optional;
16
18
 
@@ -33,6 +35,27 @@ export type AppRecord = typeof AppRecord.Type;
33
35
  export const StageStatus = Schema.Literals(['active', 'deploying', 'failed', 'destroying', 'destroyed']);
34
36
  export type StageStatus = typeof StageStatus.Type;
35
37
 
38
+ /** How a server runs (`WebCompute`). */
39
+ export const WebComputeMode = Schema.Literals(WEB_COMPUTE);
40
+
41
+ /** Days in a row the other mode was cheaper enough to switch to (`ComputeStreak`). */
42
+ export const ComputeStreakSchema = Schema.Struct({
43
+ to: WebComputeMode,
44
+ days: Schema.Finite,
45
+ day: Schema.String,
46
+ });
47
+
48
+ /** A prod stage's monthly cost in each mode, estimated daily from its traffic (`simulateWebCompute`). */
49
+ export const ComputeEstimate = Schema.Struct({
50
+ at: Schema.String,
51
+ request: Schema.Struct({ monthlyUsd: Schema.Finite, coldStartsPerMonth: Schema.Finite }),
52
+ instance: Schema.Struct({ monthlyUsd: Schema.Finite, environmentHoursPerMonth: Schema.Finite }),
53
+ requestsPerMonth: Schema.Finite,
54
+ /** Days of traffic the month is extrapolated from. */
55
+ days: Schema.Finite,
56
+ });
57
+ export type ComputeEstimate = typeof ComputeEstimate.Type;
58
+
36
59
  export const StageRecord = Schema.Struct({
37
60
  app: Schema.String,
38
61
  stage: Schema.String,
@@ -42,9 +65,15 @@ export const StageRecord = Schema.Struct({
42
65
  preview: Schema.Boolean,
43
66
  currentDeployment: optional(Schema.String),
44
67
  previousDeployment: optional(Schema.String),
45
- /** Web Function revision ids, for instant rollback. */
68
+ /** The server builds: Web Function revision ids, or request-mode function versions. */
46
69
  currentRevision: optional(Schema.String),
47
70
  previousRevision: optional(Schema.String),
71
+ /** How the live deployment's server runs. */
72
+ compute: optional(WebComputeMode),
73
+ /** Prod stages with a server: what each mode would cost a month. */
74
+ computeEstimate: optional(ComputeEstimate),
75
+ /** Set while the other mode is cheaper enough; at three days the platform switches. */
76
+ computeStreak: optional(ComputeStreakSchema),
48
77
  createdAt: Schema.String,
49
78
  updatedAt: Schema.String,
50
79
  });
@@ -74,12 +103,21 @@ export const DeploymentRecord = Schema.Struct({
74
103
  app: Schema.String,
75
104
  stage: Schema.String,
76
105
  status: DeploymentStatus,
77
- /** GitHub username, or `ci:<repo>` for OIDC deploys. */
106
+ /** GitHub username, `ci:<repo>` for OIDC deploys, or `platform` for a compute switch. */
78
107
  actor: Schema.String,
79
108
  commit: optional(Schema.String),
80
109
  ref: optional(Schema.String),
81
110
  message: optional(Schema.String),
111
+ /** The `@ericminassian/platform` version its bundles were built with; absent before 0.4.0. */
112
+ sdk: optional(Schema.String),
82
113
  manifest: optional(ResolvedManifest),
114
+ /** How it runs the server. */
115
+ compute: optional(WebComputeMode),
116
+ /**
117
+ * A switch of the server's mode that the platform made (actor `platform`):
118
+ * the deployment whose build this one runs again, in `compute`.
119
+ */
120
+ computeSwitchOf: optional(Schema.String),
83
121
  url: optional(Schema.String),
84
122
  error: optional(Schema.String),
85
123
  events: Schema.Array(DeploymentEventEntry),
@@ -158,6 +196,10 @@ export const AppSummary = Schema.Struct({
158
196
  health: Schema.NullOr(AppHealth),
159
197
  costMonthToDateUsd: optional(Schema.Finite),
160
198
  lastDeployment: optional(DeploymentRecord),
199
+ /** Prod's requests in each of the last 24 hours, oldest first (absent without a prod stage). */
200
+ traffic: optional(Schema.Array(Schema.Finite)),
201
+ /** The app's alert rules on every stage: how many there are and how many are firing. */
202
+ alerts: optional(Schema.Struct({ total: Schema.Finite, alarm: Schema.Finite })),
161
203
  });
162
204
  export type AppSummary = typeof AppSummary.Type;
163
205
 
@@ -165,7 +207,14 @@ export type AppSummary = typeof AppSummary.Type;
165
207
  // Stages and deployments
166
208
  // ---------------------------------------------------------------------------
167
209
 
168
- export const ArtifactFile = Schema.Literals(['manifest.json', 'server.zip', 'worker.zip', 'static.zip']);
210
+ /** `services.zip` holds `<service>/index.mjs` (+ `.map`) for each long-running service. */
211
+ export const ArtifactFile = Schema.Literals([
212
+ 'manifest.json',
213
+ 'server.zip',
214
+ 'worker.zip',
215
+ 'static.zip',
216
+ 'services.zip',
217
+ ]);
169
218
  export type ArtifactFile = typeof ArtifactFile.Type;
170
219
 
171
220
  export const PresignedPost = Schema.Struct({
@@ -186,6 +235,8 @@ export const CreateDeploymentRequest = Schema.Struct({
186
235
  commit: optional(Schema.String),
187
236
  ref: optional(Schema.String),
188
237
  message: optional(Schema.String),
238
+ /** The `@ericminassian/platform` version the bundles were built with (`MIN_SDK_VERSION`). */
239
+ sdk: optional(Schema.String),
189
240
  });
190
241
  export type CreateDeploymentRequest = typeof CreateDeploymentRequest.Encoded;
191
242
 
@@ -197,6 +248,7 @@ export const CreateDeploymentResponse = Schema.Struct({
197
248
  'server.zip': optional(PresignedPost),
198
249
  'worker.zip': optional(PresignedPost),
199
250
  'static.zip': optional(PresignedPost),
251
+ 'services.zip': optional(PresignedPost),
200
252
  }),
201
253
  });
202
254
  export type CreateDeploymentResponse = typeof CreateDeploymentResponse.Type;
@@ -258,7 +310,7 @@ export const RouteStats = Schema.Struct({
258
310
  });
259
311
  export type RouteStats = typeof RouteStats.Type;
260
312
 
261
- export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke']);
313
+ export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke', 'service']);
262
314
  export type JobKind = typeof JobKind.Type;
263
315
 
264
316
  export const JobStats = Schema.Struct({
@@ -277,15 +329,209 @@ export const JobsResponse = Schema.Struct({
277
329
  });
278
330
  export type JobsResponse = typeof JobsResponse.Type;
279
331
 
332
+ /** A queue's jobs that aren't running: waiting for their time, and given up on. */
280
333
  export const QueueStats = Schema.Struct({
281
334
  name: Schema.String,
282
- visible: Schema.Finite,
283
- inFlight: Schema.Finite,
335
+ /** Retries and delayed sends scheduled for later. */
336
+ scheduled: Schema.Finite,
337
+ /** Its messages in the stage's dead-letter queue (of those `deadLetters` reads). */
284
338
  deadLetter: Schema.Finite,
285
- oldestAgeSeconds: Schema.NullOr(Schema.Finite),
286
339
  });
287
340
  export type QueueStats = typeof QueueStats.Type;
288
341
 
342
+ /** One message in the stage's dead-letter queue (core `readDeadLetter`). */
343
+ export const DeadLetterItem = Schema.Struct({
344
+ /** The SQS message id: what redrive and discard take. */
345
+ id: Schema.String,
346
+ /** `unknown`: a message the platform didn't write; it can only be discarded. */
347
+ kind: Schema.Literals(['queue', 'event', 'cron', 'invoke', 'unknown']),
348
+ name: Schema.String,
349
+ attempts: Schema.NullOr(Schema.Finite),
350
+ error: Schema.Struct({ name: Schema.String, message: Schema.String }),
351
+ /** ISO time, when the writer recorded one. */
352
+ failedAt: Schema.NullOr(Schema.String),
353
+ /** Who gave up on it: the SDK, Lambda, Scheduler or EventBridge. */
354
+ source: Schema.Literals(['sdk', 'lambda', 'scheduler', 'eventbridge', 'unknown']),
355
+ /** The message body, event detail or invoke payload, as JSON, cut to a few hundred chars. */
356
+ preview: Schema.String,
357
+ });
358
+ export type DeadLetterItem = typeof DeadLetterItem.Type;
359
+
360
+ export const DeadLettersResponse = Schema.Struct({
361
+ /** Messages in the queue (SQS's approximate count). */
362
+ total: Schema.Finite,
363
+ /** Up to `DEAD_LETTERS_READ` of them. */
364
+ items: Schema.Array(DeadLetterItem),
365
+ });
366
+ export type DeadLettersResponse = typeof DeadLettersResponse.Type;
367
+
368
+ /** How many dead letters the API reads for a list. */
369
+ export const DEAD_LETTERS_READ = 100;
370
+
371
+ /** Redrive or discard: the given dead letters, or (no `ids`) all of them. */
372
+ export const DeadLetterAction = Schema.Struct({ ids: Schema.optional(Schema.Array(Schema.String)) });
373
+ export type DeadLetterAction = typeof DeadLetterAction.Encoded;
374
+
375
+ export const DeadLetterActionResponse = Schema.Struct({ count: Schema.Finite });
376
+ export type DeadLetterActionResponse = typeof DeadLetterActionResponse.Type;
377
+
378
+ /** Per-namespace AppSync Events counts in one bucket (CloudWatch `Sum`s). */
379
+ export const RealtimePoint = Schema.Struct({
380
+ ts: Schema.String,
381
+ /** Events published (`InboundMessages`; each 5 KB counts once). */
382
+ events: Schema.Finite,
383
+ /** Successful publish requests (up to 5 events each). */
384
+ publishes: Schema.Finite,
385
+ /** Successful subscribes. */
386
+ subscribes: Schema.Finite,
387
+ /** Publishes and subscribes refused or failed (client and server errors). */
388
+ errors: Schema.Finite,
389
+ });
390
+ export type RealtimePoint = typeof RealtimePoint.Type;
391
+
392
+ /**
393
+ * A stage's realtime activity. AppSync reports deliveries (`OutboundMessages`)
394
+ * and connections only for the whole Event API, not per namespace, so they
395
+ * can't be shown per app.
396
+ */
397
+ export const RealtimeStatsResponse = Schema.Struct({
398
+ app: Schema.String,
399
+ stage: Schema.String,
400
+ /** False when the live deployment declares no `realtime`; the rest is then empty. */
401
+ enabled: Schema.Boolean,
402
+ subscribe: optional(Schema.Literals(['public', 'signed-in'])),
403
+ channels: Schema.Array(Schema.String),
404
+ res: Resolution,
405
+ totals: Schema.Struct({
406
+ events: Schema.Finite,
407
+ publishes: Schema.Finite,
408
+ subscribes: Schema.Finite,
409
+ errors: Schema.Finite,
410
+ }),
411
+ points: Schema.Array(RealtimePoint),
412
+ });
413
+ export type RealtimeStatsResponse = typeof RealtimeStatsResponse.Type;
414
+
415
+ /** One custom metric (`Metrics.count`/`value`) in one bucket: how many values, and their sum. */
416
+ export const CustomMetricPoint = Schema.Struct({
417
+ ts: Schema.String,
418
+ count: Schema.Finite,
419
+ sum: Schema.Finite,
420
+ });
421
+ export type CustomMetricPoint = typeof CustomMetricPoint.Type;
422
+
423
+ /**
424
+ * A custom metric over the range. `Metrics.count(name, n)` records `n` with
425
+ * unit `count`, so `sum` is the total; for `Metrics.value`, `sum / count` is
426
+ * the average.
427
+ */
428
+ export const CustomMetricStats = Schema.Struct({
429
+ name: Schema.String,
430
+ unit: optional(Schema.String),
431
+ count: Schema.Finite,
432
+ sum: Schema.Finite,
433
+ /** One per bucket in the range, zero-filled. */
434
+ points: Schema.Array(CustomMetricPoint),
435
+ });
436
+ export type CustomMetricStats = typeof CustomMetricStats.Type;
437
+
438
+ /** A stage's custom metrics recorded in the range, by name. */
439
+ export const CustomMetricsResponse = Schema.Struct({
440
+ app: Schema.String,
441
+ stage: Schema.String,
442
+ res: Resolution,
443
+ metrics: Schema.Array(CustomMetricStats),
444
+ });
445
+ export type CustomMetricsResponse = typeof CustomMetricsResponse.Type;
446
+
447
+ /** One rate limit's checks in one bucket. */
448
+ export const LimitPoint = Schema.Struct({
449
+ ts: Schema.String,
450
+ allowed: Schema.Finite,
451
+ denied: Schema.Finite,
452
+ });
453
+ export type LimitPoint = typeof LimitPoint.Type;
454
+
455
+ /** A rate limit's checks over the range, by its name in `RateLimits`. */
456
+ export const LimitStats = Schema.Struct({
457
+ name: Schema.String,
458
+ allowed: Schema.Finite,
459
+ denied: Schema.Finite,
460
+ /** One per bucket in the range, zero-filled. */
461
+ points: Schema.Array(LimitPoint),
462
+ });
463
+ export type LimitStats = typeof LimitStats.Type;
464
+
465
+ /** A stage's rate limits that were checked in the range, most denied first. */
466
+ export const LimitsResponse = Schema.Struct({
467
+ app: Schema.String,
468
+ stage: Schema.String,
469
+ res: Resolution,
470
+ limits: Schema.Array(LimitStats),
471
+ });
472
+ export type LimitsResponse = typeof LimitsResponse.Type;
473
+
474
+ /** Per-tenant SES counts in one bucket (CloudWatch `Sum`s of `AWS/SES` by tenant). */
475
+ export const EmailPoint = Schema.Struct({
476
+ ts: Schema.String,
477
+ sends: Schema.Finite,
478
+ deliveries: Schema.Finite,
479
+ bounces: Schema.Finite,
480
+ complaints: Schema.Finite,
481
+ });
482
+ export type EmailPoint = typeof EmailPoint.Type;
483
+
484
+ /**
485
+ * Whether SES lets a stage send. `paused` comes with who paused it: `policy`
486
+ * (the tenant's reputation policy, after bad bounce or complaint rates),
487
+ * `manual` (someone changed it in SES), or `aws` (only AWS Support can lift
488
+ * that one).
489
+ */
490
+ export const EmailSending = Schema.Struct({
491
+ status: Schema.Literals(['enabled', 'paused']),
492
+ pausedBy: optional(Schema.Literals(['policy', 'manual', 'aws'])),
493
+ /** SES's reason, when paused. */
494
+ cause: optional(Schema.String),
495
+ since: optional(Schema.String),
496
+ });
497
+ export type EmailSending = typeof EmailSending.Type;
498
+
499
+ /** A stage's email: its sender, whether it can send, today's usage and SES's counts over the range. */
500
+ export const EmailStatsResponse = Schema.Struct({
501
+ app: Schema.String,
502
+ stage: Schema.String,
503
+ /** False when the live deployment declares no `email`; the rest is then empty. */
504
+ enabled: Schema.Boolean,
505
+ /** `"Todo" <todo@mail…>`. */
506
+ from: optional(Schema.String),
507
+ sending: optional(EmailSending),
508
+ /** Recipients sent today (UTC) and the stage's daily limit. */
509
+ today: optional(Schema.Struct({ sent: Schema.Finite, limit: Schema.Finite })),
510
+ res: Resolution,
511
+ totals: Schema.Struct({
512
+ sends: Schema.Finite,
513
+ deliveries: Schema.Finite,
514
+ bounces: Schema.Finite,
515
+ complaints: Schema.Finite,
516
+ }),
517
+ points: Schema.Array(EmailPoint),
518
+ });
519
+ export type EmailStatsResponse = typeof EmailStatsResponse.Type;
520
+
521
+ /** An address on a stage's suppression list: SES no longer sends to it from this stage. */
522
+ export const SuppressedAddress = Schema.Struct({
523
+ address: Schema.String,
524
+ reason: Schema.Literals(['bounce', 'complaint']),
525
+ since: Schema.String,
526
+ });
527
+ export type SuppressedAddress = typeof SuppressedAddress.Type;
528
+
529
+ export const SuppressedResponse = Schema.Struct({
530
+ items: Schema.Array(SuppressedAddress),
531
+ next: optional(Schema.String),
532
+ });
533
+ export type SuppressedResponse = typeof SuppressedResponse.Type;
534
+
289
535
  export const ErrorStatus = Schema.Literals(['open', 'resolved', 'ignored']);
290
536
  export type ErrorStatus = typeof ErrorStatus.Type;
291
537
 
@@ -312,9 +558,13 @@ export type ErrorGroup = typeof ErrorGroup.Type;
312
558
  export const UpdateErrorRequest = Schema.Struct({ status: ErrorStatus });
313
559
  export type UpdateErrorRequest = typeof UpdateErrorRequest.Type;
314
560
 
561
+ /** Log stream of a line: `web`, `worker`, or `service:<name>` for a long-running service. */
562
+ export const LogStream = Schema.String;
563
+ export type LogStream = typeof LogStream.Type;
564
+
315
565
  export const LogLine = Schema.Struct({
316
566
  ts: Schema.String,
317
- stream: Schema.Literals(['web', 'worker']),
567
+ stream: LogStream,
318
568
  level: optional(Schema.String),
319
569
  message: Schema.String,
320
570
  trace: optional(Schema.String),
@@ -334,19 +584,186 @@ export const TraceResponse = Schema.Struct({
334
584
  });
335
585
  export type TraceResponse = typeof TraceResponse.Type;
336
586
 
337
- export const UptimePoint = Schema.Struct({
587
+ /** Lines around one line of a stream, oldest first; `anchor` is that line's index. */
588
+ export const LogContextResponse = Schema.Struct({
589
+ lines: Schema.Array(LogLine),
590
+ anchor: Schema.Finite,
591
+ });
592
+ export type LogContextResponse = typeof LogContextResponse.Type;
593
+
594
+ /** How many lines of a range have a value of a field. */
595
+ export const FacetCount = Schema.Struct({ value: Schema.String, count: Schema.Finite });
596
+ export type FacetCount = typeof FacetCount.Type;
597
+
598
+ /** Lines per bucket by level, and counts of each field's commonest values, for the range and filters. */
599
+ export const LogStatsResponse = Schema.Struct({
600
+ res: QueryResolution,
601
+ timestamps: Schema.Array(Schema.String),
602
+ levels: Schema.Struct({
603
+ error: Schema.Array(Schema.Finite),
604
+ warn: Schema.Array(Schema.Finite),
605
+ info: Schema.Array(Schema.Finite),
606
+ debug: Schema.Array(Schema.Finite),
607
+ system: Schema.Array(Schema.Finite),
608
+ }),
609
+ total: Schema.Finite,
610
+ facets: Schema.Struct({
611
+ level: Schema.Array(FacetCount),
612
+ stream: Schema.Array(FacetCount),
613
+ route: Schema.Array(FacetCount),
614
+ status: Schema.Array(FacetCount),
615
+ rev: Schema.Array(FacetCount),
616
+ }),
617
+ });
618
+ export type LogStatsResponse = typeof LogStatsResponse.Type;
619
+
620
+ /** A request or job that started a trace (its root line). */
621
+ export const TraceSummary = Schema.Struct({
622
+ trace: Schema.String,
623
+ /** When it started, ISO. */
624
+ ts: Schema.String,
625
+ kind: Schema.Literals(['req', 'job']),
626
+ /** `GET /api/items/:id` or `queue refresh`. */
627
+ name: Schema.String,
628
+ /** The HTTP status of a request. */
629
+ status: optional(Schema.Finite),
630
+ /** A 5xx request or a failed job. */
631
+ failed: Schema.Boolean,
632
+ dur: Schema.Finite,
633
+ /** Its spans were written (it failed, was slow, or its trace was sampled). */
634
+ recorded: Schema.Boolean,
635
+ /** Calls it made that weren't written. */
636
+ calls: optional(Schema.Finite),
637
+ rev: optional(Schema.String),
638
+ });
639
+ export type TraceSummary = typeof TraceSummary.Type;
640
+
641
+ export const TracesResponse = Schema.Struct({
642
+ traces: Schema.Array(TraceSummary),
643
+ /** More matched than `limit`; narrow the range or filters to see the rest. */
644
+ truncated: Schema.Boolean,
645
+ });
646
+ export type TracesResponse = typeof TracesResponse.Type;
647
+
648
+ export const InsightsRequest = Schema.Struct({
649
+ stage: optional(Schema.String),
650
+ /**
651
+ * A Logs Insights query (the Logs Insights language only). It runs on the
652
+ * stage's own log groups; one that picks its own (`SOURCE`) is refused.
653
+ */
654
+ query: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(10_000)),
655
+ from: optional(Schema.String),
656
+ to: optional(Schema.String),
657
+ range: optional(Schema.String),
658
+ });
659
+ export type InsightsRequest = typeof InsightsRequest.Type;
660
+
661
+ export const InsightsResponse = Schema.Struct({
662
+ /** Result fields in the order the query produced them (hidden `@ptr` left out). */
663
+ columns: Schema.Array(Schema.String),
664
+ rows: Schema.Array(Schema.Array(Schema.NullOr(Schema.String))),
665
+ recordsMatched: Schema.Finite,
666
+ recordsScanned: Schema.Finite,
667
+ bytesScanned: Schema.Finite,
668
+ });
669
+ export type InsightsResponse = typeof InsightsResponse.Type;
670
+
671
+ /** An error group's events per bucket, and the deployments they happened on (Logs Insights). */
672
+ export const ErrorOccurrencesResponse = Schema.Struct({
673
+ res: QueryResolution,
674
+ timestamps: Schema.Array(Schema.String),
675
+ counts: Schema.Array(Schema.Finite),
676
+ revs: Schema.Array(FacetCount),
677
+ });
678
+ export type ErrorOccurrencesResponse = typeof ErrorOccurrencesResponse.Type;
679
+
680
+ /** One line of a series answer: a group's values (key `all` when ungrouped), one per timestamp. */
681
+ export const SeriesLine = Schema.Struct({
682
+ key: Schema.String,
683
+ values: Schema.Array(Schema.NullOr(Schema.Finite)),
684
+ });
685
+ export type SeriesLine = typeof SeriesLine.Type;
686
+
687
+ export const SeriesResponse = Schema.Struct({
688
+ res: QueryResolution,
689
+ /** Bucket start times, ISO, oldest first. */
690
+ timestamps: Schema.Array(Schema.String),
691
+ /** `count`, `per_second`, `percent`, `ms`, or a custom metric's own unit. */
692
+ unit: Schema.String,
693
+ series: Schema.Array(SeriesLine),
694
+ /** `stat: histogram`: per timestamp, the count in each latency bucket (`LATENCY_BUCKETS_MS`, then the overflow). */
695
+ histogram: optional(Schema.Array(Schema.Array(Schema.Finite))),
696
+ /** Why the answer differs from what was asked (coarser buckets past minute data's 3 days, groups cut to the top 10). */
697
+ note: optional(Schema.String),
698
+ });
699
+ export type SeriesResponse = typeof SeriesResponse.Type;
700
+
701
+ /** A GET of the stage's health path, for a stage that served nothing lately or has no server. */
702
+ export const UptimeCheck = Schema.Struct({
338
703
  ts: Schema.String,
339
704
  ok: Schema.Boolean,
705
+ source: Schema.Literal('check'),
706
+ /** The HTTP status; 0 when nothing answered within 10 s. */
340
707
  status: Schema.Finite,
341
708
  ms: Schema.Finite,
342
709
  });
710
+ export type UptimeCheck = typeof UptimeCheck.Type;
711
+
712
+ /** The stage's own requests in the 10 minutes before `ts`: down when at least 3, half of them 5xx. */
713
+ export const UptimeTraffic = Schema.Struct({
714
+ ts: Schema.String,
715
+ ok: Schema.Boolean,
716
+ source: Schema.Literal('traffic'),
717
+ req: Schema.Finite,
718
+ s5xx: Schema.Finite,
719
+ });
720
+ export type UptimeTraffic = typeof UptimeTraffic.Type;
721
+
722
+ export const UptimePoint = Schema.Union([UptimeCheck, UptimeTraffic]);
343
723
  export type UptimePoint = typeof UptimePoint.Type;
344
724
 
725
+ /** Monthly cost of one container if it runs all month (`estimateContainerCost`). */
726
+ export const MonthlyContainerCost = Schema.Struct({
727
+ computeUsd: Schema.Finite,
728
+ publicIpv4Usd: Schema.Finite,
729
+ totalUsd: Schema.Finite,
730
+ });
731
+
732
+ /**
733
+ * Something billed for as long as it runs, estimated from its size because
734
+ * Cost Explorer lags a day and doesn't attribute every part of it to the
735
+ * app (a container's public IPv4 address).
736
+ */
737
+ export const AlwaysOnCost = Schema.Struct({
738
+ stage: Schema.String,
739
+ kind: Schema.Literal('service'),
740
+ name: Schema.String,
741
+ /** `0.25 vCPU · 512 MB · Spot`. */
742
+ detail: Schema.String,
743
+ monthly: MonthlyContainerCost,
744
+ });
745
+ export type AlwaysOnCost = typeof AlwaysOnCost.Type;
746
+
747
+ /** A non-preview stage's server: how it runs, and (prod) what each mode would cost. */
748
+ export const StageCompute = Schema.Struct({
749
+ stage: Schema.String,
750
+ /** `web.compute` of the live deployment. */
751
+ setting: Schema.Literals(WEB_COMPUTE_SETTINGS),
752
+ compute: WebComputeMode,
753
+ estimate: optional(ComputeEstimate),
754
+ streak: optional(ComputeStreakSchema),
755
+ });
756
+ export type StageCompute = typeof StageCompute.Type;
757
+
345
758
  export const CostResponse = Schema.Struct({
346
759
  app: Schema.String,
347
760
  currency: Schema.Literal('USD'),
348
761
  days: Schema.Array(Schema.Struct({ date: Schema.String, usd: Schema.Finite })),
349
762
  monthToDateUsd: Schema.Finite,
763
+ /** Services of the app's non-preview stages (previews run theirs for minutes after a deploy). */
764
+ alwaysOn: optional(Schema.Array(AlwaysOnCost)),
765
+ /** Servers of the app's non-preview stages (previews run request mode). */
766
+ compute: optional(Schema.Array(StageCompute)),
350
767
  });
351
768
  export type CostResponse = typeof CostResponse.Type;
352
769
 
@@ -403,9 +820,12 @@ export const StoredObjectInfo = Schema.Struct({
403
820
  });
404
821
  export type StoredObjectInfo = typeof StoredObjectInfo.Type;
405
822
 
406
- /** `GET /v1/apps/:app/storage`: the declared stores without `?store=`, a listing with it. */
823
+ /**
824
+ * `GET /v1/apps/:app/storage`: the declared stores (and which of them the
825
+ * edge serves) without `?store=`, a listing with it.
826
+ */
407
827
  export const StorageResponse = Schema.Union([
408
- Schema.Struct({ stores: Schema.Array(Schema.String) }),
828
+ Schema.Struct({ stores: Schema.Array(Schema.String), public: optional(Schema.Array(Schema.String)) }),
409
829
  Schema.Struct({ objects: Schema.Array(StoredObjectInfo), cursor: optional(Schema.String) }),
410
830
  ]);
411
831
  export type StorageResponse = typeof StorageResponse.Type;
@@ -414,10 +834,81 @@ export const UrlResponse = Schema.Struct({ url: Schema.String });
414
834
  export type UrlResponse = typeof UrlResponse.Type;
415
835
 
416
836
  export const CronRunResponse = Schema.Struct({ started: Schema.String });
417
- export type CronRunResponse = typeof CronRunResponse.Type;
418
837
 
419
- export const RedriveResponse = Schema.Struct({ taskHandle: Schema.String });
420
- export type RedriveResponse = typeof RedriveResponse.Type;
838
+ // ---------------------------------------------------------------------------
839
+ // Long-running services
840
+ // ---------------------------------------------------------------------------
841
+
842
+ /**
843
+ * - `running`: every desired task is up and the latest rollout finished
844
+ * - `starting`: a rollout or replacement is under way
845
+ * - `failing`: tasks keep stopping before they settle, or the last rollout failed
846
+ * - `stopped`: scaled to zero (a preview past its minutes, or `plat services stop`)
847
+ */
848
+ export const ServiceState = Schema.Literals(['running', 'starting', 'failing', 'stopped']);
849
+ export type ServiceState = typeof ServiceState.Type;
850
+
851
+ export const ServiceInfo = Schema.Struct({
852
+ name: Schema.String,
853
+ /** Size and capacity the live deployment declares. */
854
+ cpu: Schema.Finite,
855
+ memoryMb: Schema.Finite,
856
+ spot: Schema.Boolean,
857
+ state: ServiceState,
858
+ desired: Schema.Finite,
859
+ running: Schema.Finite,
860
+ pending: Schema.Finite,
861
+ /** Deployment whose build the service runs. */
862
+ deployment: optional(Schema.String),
863
+ /** When the current task started. */
864
+ startedAt: optional(Schema.String),
865
+ /** When a preview's stop schedule scales it to zero. */
866
+ stopsAt: optional(Schema.String),
867
+ /** The task that stopped most recently (ECS keeps stopped tasks for about an hour). */
868
+ lastStop: optional(
869
+ Schema.Struct({ at: Schema.String, reason: Schema.String, exitCode: optional(Schema.Finite) }),
870
+ ),
871
+ /** Recent ECS service events, newest first. */
872
+ events: Schema.Array(Schema.Struct({ at: Schema.String, message: Schema.String })),
873
+ /** Containers started in the range: deploys, crashes, Spot replacements. */
874
+ starts: Schema.Finite,
875
+ /** Runs of `run` that failed and were rerun in the same container, in the range. */
876
+ failedRuns: Schema.Finite,
877
+ /** CPU and memory use, % of the task's size (ECS's per-service CloudWatch metrics). */
878
+ points: Schema.Array(
879
+ Schema.Struct({
880
+ ts: Schema.String,
881
+ cpu: Schema.NullOr(Schema.Finite),
882
+ memory: Schema.NullOr(Schema.Finite),
883
+ }),
884
+ ),
885
+ /** If it ran all month. */
886
+ monthly: MonthlyContainerCost,
887
+ });
888
+ export type ServiceInfo = typeof ServiceInfo.Type;
889
+
890
+ export const ServicesResponse = Schema.Struct({
891
+ app: Schema.String,
892
+ stage: Schema.String,
893
+ res: Resolution,
894
+ services: Schema.Array(ServiceInfo),
895
+ });
896
+ export type ServicesResponse = typeof ServicesResponse.Type;
897
+
898
+ export const StartServiceRequest = Schema.Struct({
899
+ /** Stop it again after this many minutes. Previews default to the service's `previewMinutes`. */
900
+ minutes: optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1440 }))),
901
+ });
902
+ export type StartServiceRequest = typeof StartServiceRequest.Encoded;
903
+
904
+ export const ServiceActionResponse = Schema.Struct({
905
+ name: Schema.String,
906
+ /** Tasks the service now asks for (1 running, 0 stopped). */
907
+ desired: Schema.Finite,
908
+ stopsAt: optional(Schema.String),
909
+ });
910
+ export type ServiceActionResponse = typeof ServiceActionResponse.Type;
911
+ export type CronRunResponse = typeof CronRunResponse.Type;
421
912
 
422
913
  // ---------------------------------------------------------------------------
423
914
  // Admin
@@ -425,7 +916,14 @@ export type RedriveResponse = typeof RedriveResponse.Type;
425
916
 
426
917
  export const AdminOverview = Schema.Struct({
427
918
  members: Schema.Array(Schema.Struct({ github: Schema.String, role: MemberRole })),
428
- limits: Schema.Struct({ appsPerMember: Schema.Finite, stagesPerApp: Schema.Finite }),
919
+ limits: Schema.Struct({
920
+ appsPerMember: Schema.Finite,
921
+ stagesPerApp: Schema.Finite,
922
+ emailsPerDay: Schema.Finite,
923
+ edgeRequestsPerMinute: optional(Schema.Finite),
924
+ edgeFloorAt: optional(Schema.Finite),
925
+ servicesPerApp: Schema.Finite,
926
+ }),
429
927
  apps: Schema.Finite,
430
928
  stages: Schema.Finite,
431
929
  previews: Schema.Finite,
@@ -435,6 +933,57 @@ export const AdminOverview = Schema.Struct({
435
933
  });
436
934
  export type AdminOverview = typeof AdminOverview.Type;
437
935
 
936
+ /** Requests the edge's web ACL handled in one bucket (CloudWatch `Sum`s). */
937
+ export const EdgeFloorPoint = Schema.Struct({
938
+ ts: Schema.String,
939
+ /** Blocked by the per-client floor. */
940
+ blocked: Schema.Finite,
941
+ /** Let through (every request the web ACL saw and allowed). */
942
+ allowed: Schema.Finite,
943
+ });
944
+ export type EdgeFloorPoint = typeof EdgeFloorPoint.Type;
945
+
946
+ /** A request the floor blocked, from WAF's sample of the last three hours. */
947
+ export const EdgeFloorSample = Schema.Struct({
948
+ at: Schema.String,
949
+ host: Schema.String,
950
+ client: Schema.String,
951
+ country: optional(Schema.String),
952
+ method: Schema.String,
953
+ path: Schema.String,
954
+ });
955
+ export type EdgeFloorSample = typeof EdgeFloorSample.Type;
956
+
957
+ /** Whether the edge floor is on, since when, and why it turned on or off. */
958
+ export const EdgeFloorState = Schema.Struct({
959
+ on: Schema.Boolean,
960
+ /** Absent until it first turns on. */
961
+ since: optional(Schema.String),
962
+ why: optional(Schema.String),
963
+ });
964
+ export type EdgeFloorState = typeof EdgeFloorState.Type;
965
+
966
+ /**
967
+ * The edge's per-client request floor across every app: on only while the
968
+ * whole edge is busy (`limits.edgeFloorAt`), then `limits.edgeRequestsPerMinute`
969
+ * per client and host. Counts cover the range whether or not it was on then.
970
+ */
971
+ export const EdgeFloorResponse = Schema.Struct({
972
+ /** False when the platform has no floor; the rest is then empty. */
973
+ enabled: Schema.Boolean,
974
+ state: EdgeFloorState,
975
+ /** Requests per client per host per minute while it's on. */
976
+ limit: optional(Schema.Finite),
977
+ /** Requests per minute across the edge that turn it on. */
978
+ threshold: optional(Schema.Finite),
979
+ res: Resolution,
980
+ totals: Schema.Struct({ blocked: Schema.Finite, allowed: Schema.Finite }),
981
+ points: Schema.Array(EdgeFloorPoint),
982
+ /** Newest first. WAF samples a share of requests, so counts here undercount. */
983
+ samples: Schema.Array(EdgeFloorSample),
984
+ });
985
+ export type EdgeFloorResponse = typeof EdgeFloorResponse.Type;
986
+
438
987
  // ---------------------------------------------------------------------------
439
988
  // Errors
440
989
  // ---------------------------------------------------------------------------