@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/naming.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { PROD_STAGE } from './constants.ts';
2
- import { fingerprint } from './telemetry.ts';
2
+ import { fingerprint } from './fingerprint.ts';
3
+ import { PUBLIC_STORAGE_ROOT } from './storage.ts';
3
4
 
4
5
  /**
5
6
  * App names: 3-30 chars, lowercase letters/digits/single hyphens, starting with
@@ -93,25 +94,73 @@ export function parseStageHost(host: string, domain: string): { app: string; sta
93
94
  export const names = {
94
95
  base: (app: string, stage: string) => `${app}--${stage}`,
95
96
  table: (app: string, stage: string) => `${app}--${stage}`,
97
+ /** The server's Lambda Web Function (instance mode). */
96
98
  webFunction: (app: string, stage: string) => `${app}--${stage}`,
97
99
  /**
98
- * The Web Function's two endpoints, each pinned to one revision. Neither
99
- * name means "current": a deploy uses whichever the live route doesn't
100
- * (`live` predates the second one).
100
+ * The server's Lambda function in request mode. Not a worker function,
101
+ * though it shares their `<app>--<stage>--` prefix: a handler's own
102
+ * function is `…--worker--…`, or a cut of that ending in `-<hash>`.
103
+ */
104
+ requestFunction: (app: string, stage: string) => `${app}--${stage}--web`,
105
+ /**
106
+ * The Web Function's two endpoints, and the request-mode function's two
107
+ * aliases (each with a function URL), each pinned to one revision or
108
+ * version. Neither name means "current": a deploy uses whichever the live
109
+ * route doesn't (`live` predates the second one).
101
110
  */
102
111
  webEndpoints: () => ['live', 'live-b'] as const,
103
112
  workerFunction: (app: string, stage: string) => `${app}--${stage}--worker`,
113
+ /**
114
+ * The function a queue, event or cron handler with its own memory or timeout
115
+ * runs in, from the worker's bundle. Function names are ≤ 64 chars of
116
+ * A-Z, a-z, 0-9, `-` and `_`: long names are hashed, and an event type's
117
+ * `.` becomes `_` (which no event type contains). `:` has no such stand-in,
118
+ * so a type with one always carries a hash of the type.
119
+ */
120
+ handlerFunction: (app: string, stage: string, kind: 'queue' | 'event' | 'cron', name: string) => {
121
+ const full = `${app}--${stage}--worker--${kind}-${name}`;
122
+ const safe = full.replaceAll('.', '_').replaceAll(':', '_');
123
+ return name.includes(':') ? `${safe.slice(0, 55)}-${fingerprint([full])}` : fit(safe, 64);
124
+ },
104
125
  /** IAM role name; created under {@link IAM_APP_PATH}. */
105
126
  role: (app: string, stage: string) => `${app}--${stage}`,
106
- queue: (app: string, stage: string, key: string) => `${app}--${stage}--${key}`,
107
- deadLetterQueue: (app: string, stage: string, key: string) => `${app}--${stage}--${key}--dlq`,
127
+ /**
128
+ * The stage's dead-letter queue (SQS, never polled): every job that failed
129
+ * its last attempt. Queue keys can't contain `--` and the old dead-letter
130
+ * queues end in `--dlq`, so this can't be a pre-0.4.0 queue's name.
131
+ */
132
+ deadLetters: (app: string, stage: string) => `${app}--${stage}--jobs--dead`,
133
+ /** The SQS queue `plat dev` points the stage's event rules at, to run events in the local worker. */
134
+ devEventTap: (app: string, stage: string) => `${app}--${stage}--plat-dev-events`,
135
+ /** A queue's SQS queue and its dead-letter queue, before queues were pushed (0.4.0). */
136
+ legacyQueue: (app: string, stage: string, key: string) => `${app}--${stage}--${key}`,
137
+ legacyDeadLetterQueue: (app: string, stage: string, key: string) => `${app}--${stage}--${key}--dlq`,
108
138
  eventBus: (app: string, stage: string) => `${app}--${stage}`,
109
139
  /** EventBridge rule names are ≤ 64 chars; long event types are hashed. */
110
140
  eventRule: (app: string, stage: string, eventType: string) =>
111
141
  fit(`${app}--${stage}--${eventType.replace(/[^A-Za-z0-9._-]/g, '_')}`, 64),
112
142
  scheduleGroup: (app: string, stage: string) => `${app}--${stage}`,
113
143
  schedule: (cronKey: string) => cronKey,
144
+ /**
145
+ * A long-running service's ECS service and task definition family (ECS
146
+ * names are their own namespace, so `worker` can't clash with the Lambda).
147
+ */
148
+ service: (app: string, stage: string, key: string) => `${app}--${stage}--${key}`,
149
+ serviceLogGroup: (app: string, stage: string, key: string) =>
150
+ `/platform/apps/${app}/${stage}/services/${key}`,
151
+ /** Tag of a service's image for one deployment in the container repository (≤ 103 of ECR's 128 chars). */
152
+ serviceImageTag: (app: string, stage: string, key: string, deploymentId: string) =>
153
+ `${app}--${stage}--${key}--${deploymentId}`,
154
+ /**
155
+ * One-shot schedule, in the stage's schedule group, that stops a preview's
156
+ * service. Cron keys can't contain `--`, so it never clashes with a cron.
157
+ */
158
+ serviceStopSchedule: (key: string) => `${key}--stop`,
114
159
  userPoolClient: (app: string, stage: string) => `${app}--${stage}`,
160
+ /** SES tenant and its configuration set (≤ 64 chars each; the base is ≤ 52). */
161
+ emailTenant: (app: string, stage: string) => `${app}--${stage}`,
162
+ /** AppSync Events channel namespace; names are ≤ 50 chars, so long ones are hashed. */
163
+ realtimeNamespace: (app: string, stage: string) => fit(`${app}--${stage}`, 50),
115
164
  /**
116
165
  * A stage's log groups. Lambda also writes a Web Function's environments to
117
166
  * `<web group>.local`, so the engine creates that one too.
@@ -124,9 +173,12 @@ export const names = {
124
173
  sharedSecretsPath: (app: string) => `/platform/apps/${app}/_shared/secrets/`,
125
174
  /** SSM SecureString holding the stage key (see `Bindings.stageKey`); outside the secrets path. */
126
175
  stageKeyParameter: (app: string, stage: string) => `/platform/apps/${app}/${stage}/stage-key`,
127
- /** Prefix inside the shared storage bucket: `<app>/<stage>/<bucket>/`. */
128
- storagePrefix: (app: string, stage: string, bucket?: string) =>
129
- bucket ? `${app}/${stage}/${bucket}/` : `${app}/${stage}/`,
176
+ /** A private store's prefix in the shared storage bucket: `<app>/<stage>/<store>/`. */
177
+ storagePrefix: (app: string, stage: string, store?: string) =>
178
+ store ? `${app}/${stage}/${store}/` : `${app}/${stage}/`,
179
+ /** A public store's prefix in the shared storage bucket: `_public/<app>/<stage>/<store>/` (see `storage.ts`). */
180
+ publicStoragePrefix: (app: string, stage: string, store?: string) =>
181
+ `${PUBLIC_STORAGE_ROOT}${names.storagePrefix(app, stage, store)}`,
130
182
  /** Prefix inside the shared sites bucket for one deployment's static files. */
131
183
  sitePrefix: (app: string, stage: string, deploymentId: string) => `${app}/${stage}/${deploymentId}`,
132
184
  artifactKey: (app: string, stage: string, deploymentId: string, file: string) =>
@@ -147,9 +199,41 @@ export const platformNames = {
147
199
  routerFunction: 'platform-router',
148
200
  userPool: 'platform-users',
149
201
  boundaryPolicy: 'platform-app-boundary',
202
+ /** The AppSync Event API every stage's channel namespace lives in. */
203
+ realtimeApi: 'platform-realtime',
204
+ /** Its Lambda authorizer (signed-in subscribe tokens). */
205
+ realtimeAuthorizer: 'platform-realtime-authorizer',
206
+ /** ECS cluster every stage's containers run in (long-running services). */
207
+ containerCluster: 'platform',
208
+ /** VPC and security group containers run in: public subnets, no NAT, egress only. */
209
+ containerNetwork: 'platform-containers',
210
+ /** ECR repository of every container image the platform builds; tags name app, stage and deployment. */
211
+ containerRepository: 'platform-containers',
212
+ /** Role ECS uses to pull images and ship container logs (the app's code runs as its stage role). */
213
+ containerExecutionRole: 'platform-container-execution',
214
+ /** Role EventBridge Scheduler uses to scale containers (a preview's stop schedule). */
215
+ containerSchedulerRole: 'platform-container-scheduler',
216
+ /** Description of the API's subscribe-only key for `public` stages (how the control plane finds it). */
217
+ realtimePublicKey: 'platform-public-subscribe',
218
+ /** The control plane's own app name (services/control-plane/plat.config.ts), stage prod. */
219
+ controlPlaneApp: 'platform',
150
220
  controlPlaneRole: 'platform-control-plane',
151
221
  ciRole: 'platform-ci',
152
222
  alertsTopic: 'platform-alerts',
223
+ /**
224
+ * The edge floor's AWS WAF web ACL, which the control plane creates and attaches to the router
225
+ * while the floor is on; also its CloudWatch metric name. Not `platform-edge`, the always-on web
226
+ * ACL the foundation stack used to own: the stack deletes that one only after updating the
227
+ * distribution, so the two names can't collide while it goes.
228
+ */
229
+ edgeWebAcl: 'platform-edge-floor',
230
+ /** Its rate-based rule, and that rule's metric name. */
231
+ edgeFloorRule: 'requests-per-client',
232
+ /**
233
+ * The CloudWatch alarm on the router's requests per minute (`limits.edgeFloorAt`) that turns the
234
+ * floor on, and the EventBridge rule that tells the control plane when it goes off.
235
+ */
236
+ edgeFloorAlarm: 'platform-edge-floor',
153
237
  runtimeConfigParameter: '/platform/config/runtime',
154
238
  sessionKeyParameter: '/platform/config/session-key',
155
239
  githubAppParameterPrefix: '/platform/config/github-app/',
@@ -29,34 +29,61 @@ import {
29
29
  CreateDeploymentRequest,
30
30
  CreateDeploymentResponse,
31
31
  CronRunResponse,
32
+ DeadLetterAction,
33
+ DeadLetterActionResponse,
34
+ DeadLettersResponse,
35
+ CustomMetricsResponse,
32
36
  DataCollections,
33
37
  DataPage,
34
38
  DeploymentRecord,
39
+ EmailSending,
40
+ EdgeFloorResponse,
41
+ EmailStatsResponse,
35
42
  ErrorGroup,
43
+ ErrorOccurrencesResponse,
36
44
  ErrorStatus,
45
+ InsightsRequest,
46
+ InsightsResponse,
37
47
  JobsResponse,
48
+ LimitsResponse,
49
+ LogContextResponse,
38
50
  LogLine,
39
51
  LogsResponse,
52
+ LogStatsResponse,
40
53
  MeResponse,
41
54
  MetricsResponse,
42
55
  PutSecretRequest,
43
56
  QueueStats,
44
- RedriveResponse,
57
+ RealtimeStatsResponse,
45
58
  RollbackRequest,
46
59
  RollbackResponse,
47
60
  RouteStats,
48
61
  SecretsResponse,
62
+ SeriesResponse,
63
+ ServiceActionResponse,
64
+ ServicesResponse,
49
65
  StageDestroyed,
50
66
  StageDestroying,
51
67
  StageRecord,
68
+ StartServiceRequest,
52
69
  StorageResponse,
70
+ SuppressedResponse,
53
71
  TraceResponse,
72
+ TracesResponse,
54
73
  UpdateAppRequest,
55
74
  UpdateErrorRequest,
56
75
  UptimePoint,
57
76
  UrlResponse,
58
77
  } from './api.ts';
59
78
  import type { MemberRole } from './config.ts';
79
+ import {
80
+ AlertHistoryResponse,
81
+ AlertRule,
82
+ AlertRuleInput,
83
+ LogFilters,
84
+ SeriesQuery,
85
+ TraceFilters,
86
+ } from './explore.ts';
60
87
 
61
88
  // ---------------------------------------------------------------------------
62
89
  // Errors: one class per status, each encoded as `{ error: { code, message } }`
@@ -112,7 +139,10 @@ export class NotFound extends Schema.TaggedError<NotFound, { readonly brand: uni
112
139
  static readonly of = (what: string) => new NotFound({ code: 'not_found', message: `${what} not found` });
113
140
  }
114
141
 
115
- /** 409: `exists`, `dns_conflict`, `has_stages`, `already_started`, `rollback_failed`, `redrive_failed`. */
142
+ /**
143
+ * 409: `exists`, `dns_conflict`, `has_stages`, `already_started`, `rollback_failed`,
144
+ * `redrive_failed`, `discard_failed`, `paused_by_aws`, `service_action_failed`.
145
+ */
116
146
  export class Conflict extends Schema.TaggedError<Conflict, { readonly brand: unique symbol }>()(
117
147
  'Conflict',
118
148
  errorFields,
@@ -224,13 +254,13 @@ const appStage = { app: Schema.String, stage: Schema.String };
224
254
  /** `?stage=` defaults to prod; the server validates the name. */
225
255
  const stageQuery = { stage: Schema.optional(Schema.String) };
226
256
  /** `?range=1h|24h|7d|30d` or `?from=&to=` (epoch ms or ISO), and `?res=1m|1h|1d`. */
227
- const rangeQuery = {
228
- ...stageQuery,
257
+ const timeQuery = {
229
258
  from: Schema.optional(Schema.String),
230
259
  to: Schema.optional(Schema.String),
231
260
  range: Schema.optional(Schema.String),
232
261
  res: Schema.optional(Schema.String),
233
262
  };
263
+ const rangeQuery = { ...stageQuery, ...timeQuery };
234
264
  const limit = Schema.optional(Schema.Int);
235
265
 
236
266
  export class SessionApi extends HttpApiGroup.make('session').add(
@@ -355,6 +385,48 @@ export class ObserveApi extends HttpApiGroup.make('observe')
355
385
  success: Schema.Array(QueueStats),
356
386
  error: errors,
357
387
  }),
388
+ /** The stage's dead-letter queue: every job that failed its last attempt. */
389
+ HttpApiEndpoint.get('deadLetters', '/apps/:app/dead-letters', {
390
+ params: app,
391
+ query: stageQuery,
392
+ success: DeadLettersResponse,
393
+ error: errors,
394
+ }),
395
+ /** AppSync Events activity of the stage's channel namespace, from CloudWatch. */
396
+ HttpApiEndpoint.get('realtime', '/apps/:app/realtime', {
397
+ params: app,
398
+ query: rangeQuery,
399
+ success: RealtimeStatsResponse,
400
+ error: errors,
401
+ }),
402
+ /** The stage's sender, SES sending status, today's usage, and SES counts for its tenant. */
403
+ HttpApiEndpoint.get('email', '/apps/:app/email', {
404
+ params: app,
405
+ query: rangeQuery,
406
+ success: EmailStatsResponse,
407
+ error: errors,
408
+ }),
409
+ /** `Metrics.count`/`value` series per name, at 1h or 1d. */
410
+ HttpApiEndpoint.get('customMetrics', '/apps/:app/custom-metrics', {
411
+ params: app,
412
+ query: rangeQuery,
413
+ success: CustomMetricsResponse,
414
+ error: errors,
415
+ }),
416
+ /** `RateLimits` checks per limit: allowed and denied, at 1h or 1d. */
417
+ HttpApiEndpoint.get('limits', '/apps/:app/limits', {
418
+ params: app,
419
+ query: rangeQuery,
420
+ success: LimitsResponse,
421
+ error: errors,
422
+ }),
423
+ /** The stage's long-running services: ECS state, CPU and memory, starts and failed runs. */
424
+ HttpApiEndpoint.get('services', '/apps/:app/services', {
425
+ params: app,
426
+ query: rangeQuery,
427
+ success: ServicesResponse,
428
+ error: errors,
429
+ }),
358
430
  HttpApiEndpoint.get('errors', '/apps/:app/errors', {
359
431
  params: app,
360
432
  query: { ...stageQuery, status: Schema.optional(ErrorStatus) },
@@ -386,7 +458,10 @@ export class ObserveApi extends HttpApiGroup.make('observe')
386
458
  query: {
387
459
  ...rangeQuery,
388
460
  q: Schema.optional(Schema.String),
389
- stream: Schema.optional(Schema.Literals(['web', 'worker'])),
461
+ /** `web`, `worker` or `service:<name>`. */
462
+ stream: Schema.optional(Schema.String),
463
+ /** Structured filters as JSON (`LogFilters`); any of them runs the search on Logs Insights. */
464
+ f: Schema.optional(Schema.fromJsonString(LogFilters)),
390
465
  limit,
391
466
  next: Schema.optional(Schema.String),
392
467
  },
@@ -400,7 +475,14 @@ export class ObserveApi extends HttpApiGroup.make('observe')
400
475
  */
401
476
  HttpApiEndpoint.get('tail', '/apps/:app/logs/tail', {
402
477
  params: app,
403
- query: { ...stageQuery, q: Schema.optional(Schema.String) },
478
+ query: {
479
+ ...stageQuery,
480
+ q: Schema.optional(Schema.String),
481
+ /** `web`, `worker` or `service:<name>`. */
482
+ stream: Schema.optional(Schema.String),
483
+ /** Structured filters as JSON (`LogFilters`), applied to the live lines. */
484
+ f: Schema.optional(Schema.fromJsonString(LogFilters)),
485
+ },
404
486
  success: HttpApiSchema.StreamSse({ events: TailEvent, keepAlive: '20 seconds' }),
405
487
  error: errors,
406
488
  }),
@@ -410,6 +492,101 @@ export class ObserveApi extends HttpApiGroup.make('observe')
410
492
  success: TraceResponse,
411
493
  error: errors,
412
494
  }),
495
+ /**
496
+ * The explorer's query (`SeriesQuery`, as JSON in `q`) over the range. `res`
497
+ * may also be `5m`, `10m`, `15m` or `30m` (sums of minute rollups); by
498
+ * default about 150 buckets.
499
+ */
500
+ HttpApiEndpoint.get('series', '/apps/:app/series', {
501
+ params: app,
502
+ query: { ...rangeQuery, q: Schema.fromJsonString(SeriesQuery) },
503
+ success: SeriesResponse,
504
+ error: errors,
505
+ }),
506
+ /** Requests and jobs that started traces, newest first (Logs Insights over their root lines). */
507
+ HttpApiEndpoint.get('traces', '/apps/:app/traces', {
508
+ params: app,
509
+ query: { ...rangeQuery, f: Schema.optional(Schema.fromJsonString(TraceFilters)), limit },
510
+ success: TracesResponse,
511
+ error: errors,
512
+ }),
513
+ /** Lines per bucket by level and the commonest field values, for the same search as `logs` (Logs Insights). */
514
+ HttpApiEndpoint.get('logStats', '/apps/:app/logs/stats', {
515
+ params: app,
516
+ query: {
517
+ ...rangeQuery,
518
+ q: Schema.optional(Schema.String),
519
+ stream: Schema.optional(Schema.String),
520
+ f: Schema.optional(Schema.fromJsonString(LogFilters)),
521
+ },
522
+ success: LogStatsResponse,
523
+ error: errors,
524
+ }),
525
+ /** The lines just before and after one line (`ts`, epoch ms) of one stream. */
526
+ HttpApiEndpoint.get('logContext', '/apps/:app/logs/context', {
527
+ params: app,
528
+ query: {
529
+ ...stageQuery,
530
+ stream: Schema.String,
531
+ ts: Schema.String,
532
+ before: limit,
533
+ after: limit,
534
+ },
535
+ success: LogContextResponse,
536
+ error: errors,
537
+ }),
538
+ /** Runs a Logs Insights query on the stage's log groups and waits for it (up to 25 s). */
539
+ HttpApiEndpoint.post('insights', '/apps/:app/insights', {
540
+ params: app,
541
+ payload: InsightsRequest,
542
+ success: InsightsResponse,
543
+ error: errors,
544
+ }),
545
+ /** An error group's events over the range (Logs Insights). */
546
+ HttpApiEndpoint.get('errorOccurrences', '/apps/:app/errors/:fingerprint/occurrences', {
547
+ params: { ...app, fingerprint: Schema.String },
548
+ query: rangeQuery,
549
+ success: ErrorOccurrencesResponse,
550
+ error: errors,
551
+ }),
552
+ )
553
+ .middleware(Authenticated) {}
554
+
555
+ /** Alert rules on an app's stages, evaluated every minute by the control plane. */
556
+ export class AlertsApi extends HttpApiGroup.make('alerts')
557
+ .add(
558
+ /** Every stage's rules, or `?stage=`'s. */
559
+ HttpApiEndpoint.get('list', '/apps/:app/alerts', {
560
+ params: app,
561
+ query: { stage: Schema.optional(Schema.String) },
562
+ success: Schema.Array(AlertRule),
563
+ error: errors,
564
+ }),
565
+ HttpApiEndpoint.post('create', '/apps/:app/alerts', {
566
+ params: app,
567
+ payload: AlertRuleInput,
568
+ success: AlertRule.pipe(HttpApiSchema.status(201)),
569
+ error: errors,
570
+ }),
571
+ /** Replaces the rule's settings; a changed query or condition starts it over in `no_data`. */
572
+ HttpApiEndpoint.put('update', '/apps/:app/alerts/:id', {
573
+ params: { ...app, id: Schema.String },
574
+ payload: AlertRuleInput,
575
+ success: AlertRule,
576
+ error: errors,
577
+ }),
578
+ HttpApiEndpoint.delete('remove', '/apps/:app/alerts/:id', {
579
+ params: { ...app, id: Schema.String },
580
+ success: HttpApiSchema.NoContent,
581
+ error: errors,
582
+ }),
583
+ /** State changes of the app's rules (or `?stage=`'s) in the range, newest first. */
584
+ HttpApiEndpoint.get('history', '/apps/:app/alerts/history', {
585
+ params: app,
586
+ query: { stage: Schema.optional(Schema.String), ...timeQuery },
587
+ success: AlertHistoryResponse,
588
+ error: errors,
589
+ }),
413
590
  )
414
591
  .middleware(Authenticated) {}
415
592
 
@@ -478,10 +655,65 @@ export class ManageApi extends HttpApiGroup.make('manage')
478
655
  success: CronRunResponse.pipe(HttpApiSchema.status(202)),
479
656
  error: errors,
480
657
  }),
481
- HttpApiEndpoint.post('redrive', '/apps/:app/queues/:name/redrive', {
658
+ /** The stage's suppression list (its SES tenant's), in SES's order; `next` pages on. */
659
+ HttpApiEndpoint.get('suppressed', '/apps/:app/email/suppressed', {
660
+ params: app,
661
+ query: { ...stageQuery, next: Schema.optional(Schema.String) },
662
+ success: SuppressedResponse,
663
+ error: errors,
664
+ }),
665
+ /** Lets SES send to `address` from this stage again. */
666
+ HttpApiEndpoint.delete('unsuppress', '/apps/:app/email/suppressed/:address', {
667
+ params: { ...app, address: Schema.String },
668
+ query: stageQuery,
669
+ success: HttpApiSchema.NoContent,
670
+ error: errors,
671
+ }),
672
+ /** Resumes sending after a pause by the reputation policy or by hand (not one by AWS). */
673
+ HttpApiEndpoint.post('resumeEmail', '/apps/:app/email/resume', {
674
+ params: app,
675
+ query: stageQuery,
676
+ success: EmailSending,
677
+ error: errors,
678
+ }),
679
+ /** Replaces the service's task with a fresh one on the same build. */
680
+ HttpApiEndpoint.post('restartService', '/apps/:app/services/:name/restart', {
681
+ params: { ...app, name: Schema.String },
682
+ query: stageQuery,
683
+ success: ServiceActionResponse.pipe(HttpApiSchema.status(202)),
684
+ error: errors,
685
+ }),
686
+ /**
687
+ * Runs it (desired 1). It stops again after `minutes` when given; on
688
+ * previews always, by default after its `previewMinutes` (30 when that is 0).
689
+ */
690
+ HttpApiEndpoint.post('startService', '/apps/:app/services/:name/start', {
482
691
  params: { ...app, name: Schema.String },
483
692
  query: stageQuery,
484
- success: RedriveResponse.pipe(HttpApiSchema.status(202)),
693
+ payload: StartServiceRequest,
694
+ success: ServiceActionResponse.pipe(HttpApiSchema.status(202)),
695
+ error: errors,
696
+ }),
697
+ /** Scales it to zero until it is started again or the stage is redeployed. */
698
+ HttpApiEndpoint.post('stopService', '/apps/:app/services/:name/stop', {
699
+ params: { ...app, name: Schema.String },
700
+ query: stageQuery,
701
+ success: ServiceActionResponse.pipe(HttpApiSchema.status(202)),
702
+ error: errors,
703
+ }),
704
+ /** Runs dead letters again from their first attempt, on the function their handler runs in now. */
705
+ HttpApiEndpoint.post('redrive', '/apps/:app/dead-letters/redrive', {
706
+ params: app,
707
+ query: stageQuery,
708
+ payload: DeadLetterAction,
709
+ success: DeadLetterActionResponse,
710
+ error: errors,
711
+ }),
712
+ HttpApiEndpoint.post('discard', '/apps/:app/dead-letters/discard', {
713
+ params: app,
714
+ query: stageQuery,
715
+ payload: DeadLetterAction,
716
+ success: DeadLetterActionResponse,
485
717
  error: errors,
486
718
  }),
487
719
  )
@@ -489,6 +721,14 @@ export class ManageApi extends HttpApiGroup.make('manage')
489
721
 
490
722
  export class AdminApi extends HttpApiGroup.make('admin')
491
723
  .add(HttpApiEndpoint.get('overview', '/admin/overview', { success: AdminOverview, error: errors }))
724
+ /** The edge's per-client request floor: on or off, blocked and allowed requests, recently blocked ones. */
725
+ .add(
726
+ HttpApiEndpoint.get('edge', '/admin/edge', {
727
+ query: timeQuery,
728
+ success: EdgeFloorResponse,
729
+ error: errors,
730
+ }),
731
+ )
492
732
  .middleware(Authenticated) {}
493
733
 
494
734
  export class PlatformApi extends HttpApi.make('platform')
@@ -497,6 +737,7 @@ export class PlatformApi extends HttpApi.make('platform')
497
737
  .add(StagesApi)
498
738
  .add(DeploymentsApi)
499
739
  .add(ObserveApi)
740
+ .add(AlertsApi)
500
741
  .add(ManageApi)
501
742
  .add(AdminApi)
502
743
  .prefix('/v1')