@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/dist/api.js CHANGED
@@ -9,8 +9,10 @@
9
9
  */
10
10
  import { Schema, SchemaGetter } from 'effect';
11
11
  import { MemberRole } from './config.js';
12
+ import { QueryResolution } from './explore.js';
12
13
  import { ResolvedManifest } from './manifest.js';
13
14
  import { Resolution, TelemetryEvent } from './telemetry.js';
15
+ import { WEB_COMPUTE, WEB_COMPUTE_SETTINGS } from './web-compute.js';
14
16
  const optional = Schema.optional;
15
17
  // ---------------------------------------------------------------------------
16
18
  // Records
@@ -26,6 +28,23 @@ export const AppRecord = Schema.Struct({
26
28
  createdAt: Schema.String,
27
29
  });
28
30
  export const StageStatus = Schema.Literals(['active', 'deploying', 'failed', 'destroying', 'destroyed']);
31
+ /** How a server runs (`WebCompute`). */
32
+ export const WebComputeMode = Schema.Literals(WEB_COMPUTE);
33
+ /** Days in a row the other mode was cheaper enough to switch to (`ComputeStreak`). */
34
+ export const ComputeStreakSchema = Schema.Struct({
35
+ to: WebComputeMode,
36
+ days: Schema.Finite,
37
+ day: Schema.String,
38
+ });
39
+ /** A prod stage's monthly cost in each mode, estimated daily from its traffic (`simulateWebCompute`). */
40
+ export const ComputeEstimate = Schema.Struct({
41
+ at: Schema.String,
42
+ request: Schema.Struct({ monthlyUsd: Schema.Finite, coldStartsPerMonth: Schema.Finite }),
43
+ instance: Schema.Struct({ monthlyUsd: Schema.Finite, environmentHoursPerMonth: Schema.Finite }),
44
+ requestsPerMonth: Schema.Finite,
45
+ /** Days of traffic the month is extrapolated from. */
46
+ days: Schema.Finite,
47
+ });
29
48
  export const StageRecord = Schema.Struct({
30
49
  app: Schema.String,
31
50
  stage: Schema.String,
@@ -35,9 +54,15 @@ export const StageRecord = Schema.Struct({
35
54
  preview: Schema.Boolean,
36
55
  currentDeployment: optional(Schema.String),
37
56
  previousDeployment: optional(Schema.String),
38
- /** Web Function revision ids, for instant rollback. */
57
+ /** The server builds: Web Function revision ids, or request-mode function versions. */
39
58
  currentRevision: optional(Schema.String),
40
59
  previousRevision: optional(Schema.String),
60
+ /** How the live deployment's server runs. */
61
+ compute: optional(WebComputeMode),
62
+ /** Prod stages with a server: what each mode would cost a month. */
63
+ computeEstimate: optional(ComputeEstimate),
64
+ /** Set while the other mode is cheaper enough; at three days the platform switches. */
65
+ computeStreak: optional(ComputeStreakSchema),
41
66
  createdAt: Schema.String,
42
67
  updatedAt: Schema.String,
43
68
  });
@@ -61,12 +86,21 @@ export const DeploymentRecord = Schema.Struct({
61
86
  app: Schema.String,
62
87
  stage: Schema.String,
63
88
  status: DeploymentStatus,
64
- /** GitHub username, or `ci:<repo>` for OIDC deploys. */
89
+ /** GitHub username, `ci:<repo>` for OIDC deploys, or `platform` for a compute switch. */
65
90
  actor: Schema.String,
66
91
  commit: optional(Schema.String),
67
92
  ref: optional(Schema.String),
68
93
  message: optional(Schema.String),
94
+ /** The `@ericminassian/platform` version its bundles were built with; absent before 0.4.0. */
95
+ sdk: optional(Schema.String),
69
96
  manifest: optional(ResolvedManifest),
97
+ /** How it runs the server. */
98
+ compute: optional(WebComputeMode),
99
+ /**
100
+ * A switch of the server's mode that the platform made (actor `platform`):
101
+ * the deployment whose build this one runs again, in `compute`.
102
+ */
103
+ computeSwitchOf: optional(Schema.String),
70
104
  url: optional(Schema.String),
71
105
  error: optional(Schema.String),
72
106
  events: Schema.Array(DeploymentEventEntry),
@@ -124,11 +158,22 @@ export const AppSummary = Schema.Struct({
124
158
  health: Schema.NullOr(AppHealth),
125
159
  costMonthToDateUsd: optional(Schema.Finite),
126
160
  lastDeployment: optional(DeploymentRecord),
161
+ /** Prod's requests in each of the last 24 hours, oldest first (absent without a prod stage). */
162
+ traffic: optional(Schema.Array(Schema.Finite)),
163
+ /** The app's alert rules on every stage: how many there are and how many are firing. */
164
+ alerts: optional(Schema.Struct({ total: Schema.Finite, alarm: Schema.Finite })),
127
165
  });
128
166
  // ---------------------------------------------------------------------------
129
167
  // Stages and deployments
130
168
  // ---------------------------------------------------------------------------
131
- export const ArtifactFile = Schema.Literals(['manifest.json', 'server.zip', 'worker.zip', 'static.zip']);
169
+ /** `services.zip` holds `<service>/index.mjs` (+ `.map`) for each long-running service. */
170
+ export const ArtifactFile = Schema.Literals([
171
+ 'manifest.json',
172
+ 'server.zip',
173
+ 'worker.zip',
174
+ 'static.zip',
175
+ 'services.zip',
176
+ ]);
132
177
  export const PresignedPost = Schema.Struct({
133
178
  url: Schema.String,
134
179
  fields: Schema.Record(Schema.String, Schema.String),
@@ -145,6 +190,8 @@ export const CreateDeploymentRequest = Schema.Struct({
145
190
  commit: optional(Schema.String),
146
191
  ref: optional(Schema.String),
147
192
  message: optional(Schema.String),
193
+ /** The `@ericminassian/platform` version the bundles were built with (`MIN_SDK_VERSION`). */
194
+ sdk: optional(Schema.String),
148
195
  });
149
196
  export const CreateDeploymentResponse = Schema.Struct({
150
197
  deployment: DeploymentRecord,
@@ -154,6 +201,7 @@ export const CreateDeploymentResponse = Schema.Struct({
154
201
  'server.zip': optional(PresignedPost),
155
202
  'worker.zip': optional(PresignedPost),
156
203
  'static.zip': optional(PresignedPost),
204
+ 'services.zip': optional(PresignedPost),
157
205
  }),
158
206
  });
159
207
  export const RollbackRequest = Schema.Struct({
@@ -200,7 +248,7 @@ export const RouteStats = Schema.Struct({
200
248
  p50: Schema.NullOr(Schema.Finite),
201
249
  p95: Schema.NullOr(Schema.Finite),
202
250
  });
203
- export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke']);
251
+ export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke', 'service']);
204
252
  export const JobStats = Schema.Struct({
205
253
  kind: JobKind,
206
254
  name: Schema.String,
@@ -213,12 +261,171 @@ export const JobsResponse = Schema.Struct({
213
261
  jobs: Schema.Array(JobStats),
214
262
  crons: Schema.Array(Schema.Struct({ name: Schema.String, schedule: Schema.String })),
215
263
  });
264
+ /** A queue's jobs that aren't running: waiting for their time, and given up on. */
216
265
  export const QueueStats = Schema.Struct({
217
266
  name: Schema.String,
218
- visible: Schema.Finite,
219
- inFlight: Schema.Finite,
267
+ /** Retries and delayed sends scheduled for later. */
268
+ scheduled: Schema.Finite,
269
+ /** Its messages in the stage's dead-letter queue (of those `deadLetters` reads). */
220
270
  deadLetter: Schema.Finite,
221
- oldestAgeSeconds: Schema.NullOr(Schema.Finite),
271
+ });
272
+ /** One message in the stage's dead-letter queue (core `readDeadLetter`). */
273
+ export const DeadLetterItem = Schema.Struct({
274
+ /** The SQS message id: what redrive and discard take. */
275
+ id: Schema.String,
276
+ /** `unknown`: a message the platform didn't write; it can only be discarded. */
277
+ kind: Schema.Literals(['queue', 'event', 'cron', 'invoke', 'unknown']),
278
+ name: Schema.String,
279
+ attempts: Schema.NullOr(Schema.Finite),
280
+ error: Schema.Struct({ name: Schema.String, message: Schema.String }),
281
+ /** ISO time, when the writer recorded one. */
282
+ failedAt: Schema.NullOr(Schema.String),
283
+ /** Who gave up on it: the SDK, Lambda, Scheduler or EventBridge. */
284
+ source: Schema.Literals(['sdk', 'lambda', 'scheduler', 'eventbridge', 'unknown']),
285
+ /** The message body, event detail or invoke payload, as JSON, cut to a few hundred chars. */
286
+ preview: Schema.String,
287
+ });
288
+ export const DeadLettersResponse = Schema.Struct({
289
+ /** Messages in the queue (SQS's approximate count). */
290
+ total: Schema.Finite,
291
+ /** Up to `DEAD_LETTERS_READ` of them. */
292
+ items: Schema.Array(DeadLetterItem),
293
+ });
294
+ /** How many dead letters the API reads for a list. */
295
+ export const DEAD_LETTERS_READ = 100;
296
+ /** Redrive or discard: the given dead letters, or (no `ids`) all of them. */
297
+ export const DeadLetterAction = Schema.Struct({ ids: Schema.optional(Schema.Array(Schema.String)) });
298
+ export const DeadLetterActionResponse = Schema.Struct({ count: Schema.Finite });
299
+ /** Per-namespace AppSync Events counts in one bucket (CloudWatch `Sum`s). */
300
+ export const RealtimePoint = Schema.Struct({
301
+ ts: Schema.String,
302
+ /** Events published (`InboundMessages`; each 5 KB counts once). */
303
+ events: Schema.Finite,
304
+ /** Successful publish requests (up to 5 events each). */
305
+ publishes: Schema.Finite,
306
+ /** Successful subscribes. */
307
+ subscribes: Schema.Finite,
308
+ /** Publishes and subscribes refused or failed (client and server errors). */
309
+ errors: Schema.Finite,
310
+ });
311
+ /**
312
+ * A stage's realtime activity. AppSync reports deliveries (`OutboundMessages`)
313
+ * and connections only for the whole Event API, not per namespace, so they
314
+ * can't be shown per app.
315
+ */
316
+ export const RealtimeStatsResponse = Schema.Struct({
317
+ app: Schema.String,
318
+ stage: Schema.String,
319
+ /** False when the live deployment declares no `realtime`; the rest is then empty. */
320
+ enabled: Schema.Boolean,
321
+ subscribe: optional(Schema.Literals(['public', 'signed-in'])),
322
+ channels: Schema.Array(Schema.String),
323
+ res: Resolution,
324
+ totals: Schema.Struct({
325
+ events: Schema.Finite,
326
+ publishes: Schema.Finite,
327
+ subscribes: Schema.Finite,
328
+ errors: Schema.Finite,
329
+ }),
330
+ points: Schema.Array(RealtimePoint),
331
+ });
332
+ /** One custom metric (`Metrics.count`/`value`) in one bucket: how many values, and their sum. */
333
+ export const CustomMetricPoint = Schema.Struct({
334
+ ts: Schema.String,
335
+ count: Schema.Finite,
336
+ sum: Schema.Finite,
337
+ });
338
+ /**
339
+ * A custom metric over the range. `Metrics.count(name, n)` records `n` with
340
+ * unit `count`, so `sum` is the total; for `Metrics.value`, `sum / count` is
341
+ * the average.
342
+ */
343
+ export const CustomMetricStats = Schema.Struct({
344
+ name: Schema.String,
345
+ unit: optional(Schema.String),
346
+ count: Schema.Finite,
347
+ sum: Schema.Finite,
348
+ /** One per bucket in the range, zero-filled. */
349
+ points: Schema.Array(CustomMetricPoint),
350
+ });
351
+ /** A stage's custom metrics recorded in the range, by name. */
352
+ export const CustomMetricsResponse = Schema.Struct({
353
+ app: Schema.String,
354
+ stage: Schema.String,
355
+ res: Resolution,
356
+ metrics: Schema.Array(CustomMetricStats),
357
+ });
358
+ /** One rate limit's checks in one bucket. */
359
+ export const LimitPoint = Schema.Struct({
360
+ ts: Schema.String,
361
+ allowed: Schema.Finite,
362
+ denied: Schema.Finite,
363
+ });
364
+ /** A rate limit's checks over the range, by its name in `RateLimits`. */
365
+ export const LimitStats = Schema.Struct({
366
+ name: Schema.String,
367
+ allowed: Schema.Finite,
368
+ denied: Schema.Finite,
369
+ /** One per bucket in the range, zero-filled. */
370
+ points: Schema.Array(LimitPoint),
371
+ });
372
+ /** A stage's rate limits that were checked in the range, most denied first. */
373
+ export const LimitsResponse = Schema.Struct({
374
+ app: Schema.String,
375
+ stage: Schema.String,
376
+ res: Resolution,
377
+ limits: Schema.Array(LimitStats),
378
+ });
379
+ /** Per-tenant SES counts in one bucket (CloudWatch `Sum`s of `AWS/SES` by tenant). */
380
+ export const EmailPoint = Schema.Struct({
381
+ ts: Schema.String,
382
+ sends: Schema.Finite,
383
+ deliveries: Schema.Finite,
384
+ bounces: Schema.Finite,
385
+ complaints: Schema.Finite,
386
+ });
387
+ /**
388
+ * Whether SES lets a stage send. `paused` comes with who paused it: `policy`
389
+ * (the tenant's reputation policy, after bad bounce or complaint rates),
390
+ * `manual` (someone changed it in SES), or `aws` (only AWS Support can lift
391
+ * that one).
392
+ */
393
+ export const EmailSending = Schema.Struct({
394
+ status: Schema.Literals(['enabled', 'paused']),
395
+ pausedBy: optional(Schema.Literals(['policy', 'manual', 'aws'])),
396
+ /** SES's reason, when paused. */
397
+ cause: optional(Schema.String),
398
+ since: optional(Schema.String),
399
+ });
400
+ /** A stage's email: its sender, whether it can send, today's usage and SES's counts over the range. */
401
+ export const EmailStatsResponse = Schema.Struct({
402
+ app: Schema.String,
403
+ stage: Schema.String,
404
+ /** False when the live deployment declares no `email`; the rest is then empty. */
405
+ enabled: Schema.Boolean,
406
+ /** `"Todo" <todo@mail…>`. */
407
+ from: optional(Schema.String),
408
+ sending: optional(EmailSending),
409
+ /** Recipients sent today (UTC) and the stage's daily limit. */
410
+ today: optional(Schema.Struct({ sent: Schema.Finite, limit: Schema.Finite })),
411
+ res: Resolution,
412
+ totals: Schema.Struct({
413
+ sends: Schema.Finite,
414
+ deliveries: Schema.Finite,
415
+ bounces: Schema.Finite,
416
+ complaints: Schema.Finite,
417
+ }),
418
+ points: Schema.Array(EmailPoint),
419
+ });
420
+ /** An address on a stage's suppression list: SES no longer sends to it from this stage. */
421
+ export const SuppressedAddress = Schema.Struct({
422
+ address: Schema.String,
423
+ reason: Schema.Literals(['bounce', 'complaint']),
424
+ since: Schema.String,
425
+ });
426
+ export const SuppressedResponse = Schema.Struct({
427
+ items: Schema.Array(SuppressedAddress),
428
+ next: optional(Schema.String),
222
429
  });
223
430
  export const ErrorStatus = Schema.Literals(['open', 'resolved', 'ignored']);
224
431
  export const ErrorGroup = Schema.Struct({
@@ -240,9 +447,11 @@ export const ErrorGroup = Schema.Struct({
240
447
  }),
241
448
  });
242
449
  export const UpdateErrorRequest = Schema.Struct({ status: ErrorStatus });
450
+ /** Log stream of a line: `web`, `worker`, or `service:<name>` for a long-running service. */
451
+ export const LogStream = Schema.String;
243
452
  export const LogLine = Schema.Struct({
244
453
  ts: Schema.String,
245
- stream: Schema.Literals(['web', 'worker']),
454
+ stream: LogStream,
246
455
  level: optional(Schema.String),
247
456
  message: Schema.String,
248
457
  trace: optional(Schema.String),
@@ -256,17 +465,155 @@ export const TraceResponse = Schema.Struct({
256
465
  trace: Schema.String,
257
466
  events: Schema.Array(TelemetryEvent),
258
467
  });
259
- export const UptimePoint = Schema.Struct({
468
+ /** Lines around one line of a stream, oldest first; `anchor` is that line's index. */
469
+ export const LogContextResponse = Schema.Struct({
470
+ lines: Schema.Array(LogLine),
471
+ anchor: Schema.Finite,
472
+ });
473
+ /** How many lines of a range have a value of a field. */
474
+ export const FacetCount = Schema.Struct({ value: Schema.String, count: Schema.Finite });
475
+ /** Lines per bucket by level, and counts of each field's commonest values, for the range and filters. */
476
+ export const LogStatsResponse = Schema.Struct({
477
+ res: QueryResolution,
478
+ timestamps: Schema.Array(Schema.String),
479
+ levels: Schema.Struct({
480
+ error: Schema.Array(Schema.Finite),
481
+ warn: Schema.Array(Schema.Finite),
482
+ info: Schema.Array(Schema.Finite),
483
+ debug: Schema.Array(Schema.Finite),
484
+ system: Schema.Array(Schema.Finite),
485
+ }),
486
+ total: Schema.Finite,
487
+ facets: Schema.Struct({
488
+ level: Schema.Array(FacetCount),
489
+ stream: Schema.Array(FacetCount),
490
+ route: Schema.Array(FacetCount),
491
+ status: Schema.Array(FacetCount),
492
+ rev: Schema.Array(FacetCount),
493
+ }),
494
+ });
495
+ /** A request or job that started a trace (its root line). */
496
+ export const TraceSummary = Schema.Struct({
497
+ trace: Schema.String,
498
+ /** When it started, ISO. */
499
+ ts: Schema.String,
500
+ kind: Schema.Literals(['req', 'job']),
501
+ /** `GET /api/items/:id` or `queue refresh`. */
502
+ name: Schema.String,
503
+ /** The HTTP status of a request. */
504
+ status: optional(Schema.Finite),
505
+ /** A 5xx request or a failed job. */
506
+ failed: Schema.Boolean,
507
+ dur: Schema.Finite,
508
+ /** Its spans were written (it failed, was slow, or its trace was sampled). */
509
+ recorded: Schema.Boolean,
510
+ /** Calls it made that weren't written. */
511
+ calls: optional(Schema.Finite),
512
+ rev: optional(Schema.String),
513
+ });
514
+ export const TracesResponse = Schema.Struct({
515
+ traces: Schema.Array(TraceSummary),
516
+ /** More matched than `limit`; narrow the range or filters to see the rest. */
517
+ truncated: Schema.Boolean,
518
+ });
519
+ export const InsightsRequest = Schema.Struct({
520
+ stage: optional(Schema.String),
521
+ /**
522
+ * A Logs Insights query (the Logs Insights language only). It runs on the
523
+ * stage's own log groups; one that picks its own (`SOURCE`) is refused.
524
+ */
525
+ query: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(10_000)),
526
+ from: optional(Schema.String),
527
+ to: optional(Schema.String),
528
+ range: optional(Schema.String),
529
+ });
530
+ export const InsightsResponse = Schema.Struct({
531
+ /** Result fields in the order the query produced them (hidden `@ptr` left out). */
532
+ columns: Schema.Array(Schema.String),
533
+ rows: Schema.Array(Schema.Array(Schema.NullOr(Schema.String))),
534
+ recordsMatched: Schema.Finite,
535
+ recordsScanned: Schema.Finite,
536
+ bytesScanned: Schema.Finite,
537
+ });
538
+ /** An error group's events per bucket, and the deployments they happened on (Logs Insights). */
539
+ export const ErrorOccurrencesResponse = Schema.Struct({
540
+ res: QueryResolution,
541
+ timestamps: Schema.Array(Schema.String),
542
+ counts: Schema.Array(Schema.Finite),
543
+ revs: Schema.Array(FacetCount),
544
+ });
545
+ /** One line of a series answer: a group's values (key `all` when ungrouped), one per timestamp. */
546
+ export const SeriesLine = Schema.Struct({
547
+ key: Schema.String,
548
+ values: Schema.Array(Schema.NullOr(Schema.Finite)),
549
+ });
550
+ export const SeriesResponse = Schema.Struct({
551
+ res: QueryResolution,
552
+ /** Bucket start times, ISO, oldest first. */
553
+ timestamps: Schema.Array(Schema.String),
554
+ /** `count`, `per_second`, `percent`, `ms`, or a custom metric's own unit. */
555
+ unit: Schema.String,
556
+ series: Schema.Array(SeriesLine),
557
+ /** `stat: histogram`: per timestamp, the count in each latency bucket (`LATENCY_BUCKETS_MS`, then the overflow). */
558
+ histogram: optional(Schema.Array(Schema.Array(Schema.Finite))),
559
+ /** Why the answer differs from what was asked (coarser buckets past minute data's 3 days, groups cut to the top 10). */
560
+ note: optional(Schema.String),
561
+ });
562
+ /** A GET of the stage's health path, for a stage that served nothing lately or has no server. */
563
+ export const UptimeCheck = Schema.Struct({
260
564
  ts: Schema.String,
261
565
  ok: Schema.Boolean,
566
+ source: Schema.Literal('check'),
567
+ /** The HTTP status; 0 when nothing answered within 10 s. */
262
568
  status: Schema.Finite,
263
569
  ms: Schema.Finite,
264
570
  });
571
+ /** The stage's own requests in the 10 minutes before `ts`: down when at least 3, half of them 5xx. */
572
+ export const UptimeTraffic = Schema.Struct({
573
+ ts: Schema.String,
574
+ ok: Schema.Boolean,
575
+ source: Schema.Literal('traffic'),
576
+ req: Schema.Finite,
577
+ s5xx: Schema.Finite,
578
+ });
579
+ export const UptimePoint = Schema.Union([UptimeCheck, UptimeTraffic]);
580
+ /** Monthly cost of one container if it runs all month (`estimateContainerCost`). */
581
+ export const MonthlyContainerCost = Schema.Struct({
582
+ computeUsd: Schema.Finite,
583
+ publicIpv4Usd: Schema.Finite,
584
+ totalUsd: Schema.Finite,
585
+ });
586
+ /**
587
+ * Something billed for as long as it runs, estimated from its size because
588
+ * Cost Explorer lags a day and doesn't attribute every part of it to the
589
+ * app (a container's public IPv4 address).
590
+ */
591
+ export const AlwaysOnCost = Schema.Struct({
592
+ stage: Schema.String,
593
+ kind: Schema.Literal('service'),
594
+ name: Schema.String,
595
+ /** `0.25 vCPU · 512 MB · Spot`. */
596
+ detail: Schema.String,
597
+ monthly: MonthlyContainerCost,
598
+ });
599
+ /** A non-preview stage's server: how it runs, and (prod) what each mode would cost. */
600
+ export const StageCompute = Schema.Struct({
601
+ stage: Schema.String,
602
+ /** `web.compute` of the live deployment. */
603
+ setting: Schema.Literals(WEB_COMPUTE_SETTINGS),
604
+ compute: WebComputeMode,
605
+ estimate: optional(ComputeEstimate),
606
+ streak: optional(ComputeStreakSchema),
607
+ });
265
608
  export const CostResponse = Schema.Struct({
266
609
  app: Schema.String,
267
610
  currency: Schema.Literal('USD'),
268
611
  days: Schema.Array(Schema.Struct({ date: Schema.String, usd: Schema.Finite })),
269
612
  monthToDateUsd: Schema.Finite,
613
+ /** Services of the app's non-preview stages (previews run theirs for minutes after a deploy). */
614
+ alwaysOn: optional(Schema.Array(AlwaysOnCost)),
615
+ /** Servers of the app's non-preview stages (previews run request mode). */
616
+ compute: optional(Schema.Array(StageCompute)),
270
617
  });
271
618
  // ---------------------------------------------------------------------------
272
619
  // Data, storage, secrets, job controls
@@ -305,20 +652,88 @@ export const StoredObjectInfo = Schema.Struct({
305
652
  size: Schema.Finite,
306
653
  lastModified: optional(Schema.String),
307
654
  });
308
- /** `GET /v1/apps/:app/storage`: the declared stores without `?store=`, a listing with it. */
655
+ /**
656
+ * `GET /v1/apps/:app/storage`: the declared stores (and which of them the
657
+ * edge serves) without `?store=`, a listing with it.
658
+ */
309
659
  export const StorageResponse = Schema.Union([
310
- Schema.Struct({ stores: Schema.Array(Schema.String) }),
660
+ Schema.Struct({ stores: Schema.Array(Schema.String), public: optional(Schema.Array(Schema.String)) }),
311
661
  Schema.Struct({ objects: Schema.Array(StoredObjectInfo), cursor: optional(Schema.String) }),
312
662
  ]);
313
663
  export const UrlResponse = Schema.Struct({ url: Schema.String });
314
664
  export const CronRunResponse = Schema.Struct({ started: Schema.String });
315
- export const RedriveResponse = Schema.Struct({ taskHandle: Schema.String });
665
+ // ---------------------------------------------------------------------------
666
+ // Long-running services
667
+ // ---------------------------------------------------------------------------
668
+ /**
669
+ * - `running`: every desired task is up and the latest rollout finished
670
+ * - `starting`: a rollout or replacement is under way
671
+ * - `failing`: tasks keep stopping before they settle, or the last rollout failed
672
+ * - `stopped`: scaled to zero (a preview past its minutes, or `plat services stop`)
673
+ */
674
+ export const ServiceState = Schema.Literals(['running', 'starting', 'failing', 'stopped']);
675
+ export const ServiceInfo = Schema.Struct({
676
+ name: Schema.String,
677
+ /** Size and capacity the live deployment declares. */
678
+ cpu: Schema.Finite,
679
+ memoryMb: Schema.Finite,
680
+ spot: Schema.Boolean,
681
+ state: ServiceState,
682
+ desired: Schema.Finite,
683
+ running: Schema.Finite,
684
+ pending: Schema.Finite,
685
+ /** Deployment whose build the service runs. */
686
+ deployment: optional(Schema.String),
687
+ /** When the current task started. */
688
+ startedAt: optional(Schema.String),
689
+ /** When a preview's stop schedule scales it to zero. */
690
+ stopsAt: optional(Schema.String),
691
+ /** The task that stopped most recently (ECS keeps stopped tasks for about an hour). */
692
+ lastStop: optional(Schema.Struct({ at: Schema.String, reason: Schema.String, exitCode: optional(Schema.Finite) })),
693
+ /** Recent ECS service events, newest first. */
694
+ events: Schema.Array(Schema.Struct({ at: Schema.String, message: Schema.String })),
695
+ /** Containers started in the range: deploys, crashes, Spot replacements. */
696
+ starts: Schema.Finite,
697
+ /** Runs of `run` that failed and were rerun in the same container, in the range. */
698
+ failedRuns: Schema.Finite,
699
+ /** CPU and memory use, % of the task's size (ECS's per-service CloudWatch metrics). */
700
+ points: Schema.Array(Schema.Struct({
701
+ ts: Schema.String,
702
+ cpu: Schema.NullOr(Schema.Finite),
703
+ memory: Schema.NullOr(Schema.Finite),
704
+ })),
705
+ /** If it ran all month. */
706
+ monthly: MonthlyContainerCost,
707
+ });
708
+ export const ServicesResponse = Schema.Struct({
709
+ app: Schema.String,
710
+ stage: Schema.String,
711
+ res: Resolution,
712
+ services: Schema.Array(ServiceInfo),
713
+ });
714
+ export const StartServiceRequest = Schema.Struct({
715
+ /** Stop it again after this many minutes. Previews default to the service's `previewMinutes`. */
716
+ minutes: optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1440 }))),
717
+ });
718
+ export const ServiceActionResponse = Schema.Struct({
719
+ name: Schema.String,
720
+ /** Tasks the service now asks for (1 running, 0 stopped). */
721
+ desired: Schema.Finite,
722
+ stopsAt: optional(Schema.String),
723
+ });
316
724
  // ---------------------------------------------------------------------------
317
725
  // Admin
318
726
  // ---------------------------------------------------------------------------
319
727
  export const AdminOverview = Schema.Struct({
320
728
  members: Schema.Array(Schema.Struct({ github: Schema.String, role: MemberRole })),
321
- limits: Schema.Struct({ appsPerMember: Schema.Finite, stagesPerApp: Schema.Finite }),
729
+ limits: Schema.Struct({
730
+ appsPerMember: Schema.Finite,
731
+ stagesPerApp: Schema.Finite,
732
+ emailsPerDay: Schema.Finite,
733
+ edgeRequestsPerMinute: optional(Schema.Finite),
734
+ edgeFloorAt: optional(Schema.Finite),
735
+ servicesPerApp: Schema.Finite,
736
+ }),
322
737
  apps: Schema.Finite,
323
738
  stages: Schema.Finite,
324
739
  previews: Schema.Finite,
@@ -326,6 +741,49 @@ export const AdminOverview = Schema.Struct({
326
741
  down: Schema.Array(Schema.String),
327
742
  cost: Schema.Struct({ total: Schema.NullOr(CostResponse), shared: Schema.NullOr(CostResponse) }),
328
743
  });
744
+ /** Requests the edge's web ACL handled in one bucket (CloudWatch `Sum`s). */
745
+ export const EdgeFloorPoint = Schema.Struct({
746
+ ts: Schema.String,
747
+ /** Blocked by the per-client floor. */
748
+ blocked: Schema.Finite,
749
+ /** Let through (every request the web ACL saw and allowed). */
750
+ allowed: Schema.Finite,
751
+ });
752
+ /** A request the floor blocked, from WAF's sample of the last three hours. */
753
+ export const EdgeFloorSample = Schema.Struct({
754
+ at: Schema.String,
755
+ host: Schema.String,
756
+ client: Schema.String,
757
+ country: optional(Schema.String),
758
+ method: Schema.String,
759
+ path: Schema.String,
760
+ });
761
+ /** Whether the edge floor is on, since when, and why it turned on or off. */
762
+ export const EdgeFloorState = Schema.Struct({
763
+ on: Schema.Boolean,
764
+ /** Absent until it first turns on. */
765
+ since: optional(Schema.String),
766
+ why: optional(Schema.String),
767
+ });
768
+ /**
769
+ * The edge's per-client request floor across every app: on only while the
770
+ * whole edge is busy (`limits.edgeFloorAt`), then `limits.edgeRequestsPerMinute`
771
+ * per client and host. Counts cover the range whether or not it was on then.
772
+ */
773
+ export const EdgeFloorResponse = Schema.Struct({
774
+ /** False when the platform has no floor; the rest is then empty. */
775
+ enabled: Schema.Boolean,
776
+ state: EdgeFloorState,
777
+ /** Requests per client per host per minute while it's on. */
778
+ limit: optional(Schema.Finite),
779
+ /** Requests per minute across the edge that turn it on. */
780
+ threshold: optional(Schema.Finite),
781
+ res: Resolution,
782
+ totals: Schema.Struct({ blocked: Schema.Finite, allowed: Schema.Finite }),
783
+ points: Schema.Array(EdgeFloorPoint),
784
+ /** Newest first. WAF samples a share of requests, so counts here undercount. */
785
+ samples: Schema.Array(EdgeFloorSample),
786
+ });
329
787
  // ---------------------------------------------------------------------------
330
788
  // Errors
331
789
  // ---------------------------------------------------------------------------