@ericminassian/platform-core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/api.d.ts +947 -209
  2. package/dist/api.js +335 -1
  3. package/dist/api.js.map +1 -1
  4. package/dist/auth.d.ts +19 -0
  5. package/dist/auth.js +29 -0
  6. package/dist/auth.js.map +1 -1
  7. package/dist/bindings.d.ts +8 -2
  8. package/dist/bindings.js.map +1 -1
  9. package/dist/cloudfront-function.js +6 -0
  10. package/dist/cloudfront-function.js.map +1 -1
  11. package/dist/config.d.ts +3 -1
  12. package/dist/config.js +7 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/constants.d.ts +11 -0
  15. package/dist/constants.js.map +1 -1
  16. package/dist/manifest.d.ts +96 -92
  17. package/dist/manifest.js +96 -66
  18. package/dist/manifest.js.map +1 -1
  19. package/dist/naming.d.ts +13 -2
  20. package/dist/naming.js +12 -1
  21. package/dist/naming.js.map +1 -1
  22. package/dist/platform-api.d.ts +5337 -0
  23. package/dist/platform-api.js +343 -0
  24. package/dist/platform-api.js.map +1 -0
  25. package/dist/router/decide.d.ts +5 -1
  26. package/dist/router/decide.js +7 -2
  27. package/dist/router.d.ts +1 -1
  28. package/dist/telemetry.d.ts +236 -74
  29. package/dist/telemetry.js +97 -0
  30. package/dist/telemetry.js.map +1 -1
  31. package/package.json +10 -2
  32. package/src/api.ts +427 -231
  33. package/src/auth.ts +33 -0
  34. package/src/bindings.ts +8 -2
  35. package/src/cloudfront-function.ts +6 -0
  36. package/src/config.ts +3 -1
  37. package/src/constants.ts +12 -0
  38. package/src/manifest.ts +145 -87
  39. package/src/naming.ts +13 -2
  40. package/src/platform-api.ts +504 -0
  41. package/src/router/decide.d.ts +5 -1
  42. package/src/router/decide.js +7 -2
  43. package/src/router.ts +1 -1
  44. package/src/telemetry.ts +107 -85
package/src/api.ts CHANGED
@@ -1,250 +1,446 @@
1
1
  /**
2
- * Control plane API types, shared by the API server, the console and the CLI.
3
- * All routes live under `/v1`. Auth is one of:
4
- * - `Authorization: Bearer <platform token>` (CLI, from `plat login`)
5
- * - `Authorization: Bearer <GitHub Actions OIDC token>` (CI deploys only)
6
- * - session cookie (console, after "Sign in with GitHub")
2
+ * Control plane API records and payloads, as schemas: the control plane
3
+ * encodes responses and decodes requests with them, the console and the CLI
4
+ * read the same shapes. The endpoints themselves are `PlatformApi`
5
+ * (`@ericminassian/platform-core/platform-api`). All routes live under `/v1`.
6
+ *
7
+ * Optional fields accept `undefined`, so a record built with spreads of
8
+ * possibly-missing values encodes; JSON drops them either way.
7
9
  */
8
- import type { MemberRole } from './config.ts';
9
- import type { ManifestInput, ResolvedManifest } from './manifest.ts';
10
- import type { Resolution, TelemetryEvent } from './telemetry.ts';
10
+ import { Schema, SchemaGetter } from 'effect';
11
+ import { MemberRole } from './config.ts';
12
+ import { ResolvedManifest } from './manifest.ts';
13
+ import { Resolution, TelemetryEvent } from './telemetry.ts';
14
+
15
+ const optional = Schema.optional;
11
16
 
12
17
  // ---------------------------------------------------------------------------
13
18
  // Records
14
19
  // ---------------------------------------------------------------------------
15
20
 
16
- export interface AppRecord {
17
- name: string;
21
+ export const AppRecord = Schema.Struct({
22
+ name: Schema.String,
18
23
  /** GitHub `owner/name` allowed to deploy this app from CI. */
19
- repo: string;
20
- description?: string;
24
+ repo: Schema.String,
25
+ description: optional(Schema.String),
21
26
  /** GitHub usernames who can manage the app (admins can manage everything). */
22
- owners: string[];
23
- createdBy: string;
24
- createdAt: string;
25
- }
26
-
27
- export type StageStatus = 'active' | 'deploying' | 'failed' | 'destroying' | 'destroyed';
28
-
29
- export interface StageRecord {
30
- app: string;
31
- stage: string;
32
- host: string;
33
- url: string;
34
- status: StageStatus;
35
- preview: boolean;
36
- currentDeployment?: string;
37
- previousDeployment?: string;
27
+ owners: Schema.Array(Schema.String),
28
+ createdBy: Schema.String,
29
+ createdAt: Schema.String,
30
+ });
31
+ export type AppRecord = typeof AppRecord.Type;
32
+
33
+ export const StageStatus = Schema.Literals(['active', 'deploying', 'failed', 'destroying', 'destroyed']);
34
+ export type StageStatus = typeof StageStatus.Type;
35
+
36
+ export const StageRecord = Schema.Struct({
37
+ app: Schema.String,
38
+ stage: Schema.String,
39
+ host: Schema.String,
40
+ url: Schema.String,
41
+ status: StageStatus,
42
+ preview: Schema.Boolean,
43
+ currentDeployment: optional(Schema.String),
44
+ previousDeployment: optional(Schema.String),
38
45
  /** Web Function revision ids, for instant rollback. */
39
- currentRevision?: string;
40
- previousRevision?: string;
41
- createdAt: string;
42
- updatedAt: string;
43
- }
44
-
45
- export type DeploymentStatus =
46
- | 'awaiting_upload'
47
- | 'queued'
48
- | 'running'
49
- | 'succeeded'
50
- | 'failed'
51
- | 'rolled_back';
52
-
53
- export interface DeploymentEventEntry {
54
- ts: number;
55
- level: 'info' | 'warn' | 'error';
56
- msg: string;
46
+ currentRevision: optional(Schema.String),
47
+ previousRevision: optional(Schema.String),
48
+ createdAt: Schema.String,
49
+ updatedAt: Schema.String,
50
+ });
51
+ export type StageRecord = typeof StageRecord.Type;
52
+
53
+ export const DeploymentStatus = Schema.Literals([
54
+ 'awaiting_upload',
55
+ 'queued',
56
+ 'running',
57
+ 'succeeded',
58
+ 'failed',
59
+ 'rolled_back',
60
+ ]);
61
+ export type DeploymentStatus = typeof DeploymentStatus.Type;
62
+
63
+ export const DeploymentEventEntry = Schema.Struct({
64
+ ts: Schema.Finite,
65
+ level: Schema.Literals(['info', 'warn', 'error']),
66
+ msg: Schema.String,
57
67
  /** Resource the step acted on, e.g. `table foo--prod`. */
58
- resource?: string;
59
- }
60
-
61
- export interface DeploymentRecord {
62
- id: string;
63
- app: string;
64
- stage: string;
65
- status: DeploymentStatus;
68
+ resource: optional(Schema.String),
69
+ });
70
+ export type DeploymentEventEntry = typeof DeploymentEventEntry.Type;
71
+
72
+ export const DeploymentRecord = Schema.Struct({
73
+ id: Schema.String,
74
+ app: Schema.String,
75
+ stage: Schema.String,
76
+ status: DeploymentStatus,
66
77
  /** GitHub username, or `ci:<repo>` for OIDC deploys. */
67
- actor: string;
68
- commit?: string;
69
- ref?: string;
70
- message?: string;
71
- manifest?: ResolvedManifest;
72
- url?: string;
73
- error?: string;
74
- events: DeploymentEventEntry[];
75
- createdAt: string;
76
- startedAt?: string;
77
- finishedAt?: string;
78
- }
78
+ actor: Schema.String,
79
+ commit: optional(Schema.String),
80
+ ref: optional(Schema.String),
81
+ message: optional(Schema.String),
82
+ manifest: optional(ResolvedManifest),
83
+ url: optional(Schema.String),
84
+ error: optional(Schema.String),
85
+ events: Schema.Array(DeploymentEventEntry),
86
+ createdAt: Schema.String,
87
+ startedAt: optional(Schema.String),
88
+ finishedAt: optional(Schema.String),
89
+ });
90
+ export type DeploymentRecord = typeof DeploymentRecord.Type;
79
91
 
80
92
  // ---------------------------------------------------------------------------
81
- // Requests / responses
93
+ // Session
82
94
  // ---------------------------------------------------------------------------
83
95
 
84
- export interface MeResponse {
85
- github: string;
86
- role: MemberRole;
87
- }
96
+ export const MeResponse = Schema.Struct({ github: Schema.String, role: MemberRole });
97
+ export type MeResponse = typeof MeResponse.Type;
88
98
 
89
- export interface CliLoginRequest {
99
+ export const CliLoginRequest = Schema.Struct({
90
100
  /** A GitHub token for the user (e.g. `gh auth token`); used once to identify them. */
91
- githubToken: string;
92
- }
93
-
94
- export interface CliLoginResponse {
95
- token: string;
96
- github: string;
97
- role: MemberRole;
98
- expiresAt: string;
99
- }
100
-
101
- export interface CreateAppRequest {
102
- name: string;
103
- repo: string;
104
- description?: string;
105
- }
106
-
107
- export type ArtifactFile = 'manifest.json' | 'server.zip' | 'worker.zip' | 'static.zip';
108
-
109
- export interface PresignedPost {
110
- url: string;
111
- fields: Record<string, string>;
112
- }
113
-
114
- export interface CreateDeploymentRequest {
115
- stage: string;
116
- manifest: ManifestInput;
117
- /** Which artifacts the CLI will upload (manifest.json is always uploaded). */
118
- files: ArtifactFile[];
119
- commit?: string;
120
- ref?: string;
121
- message?: string;
122
- }
123
-
124
- export interface CreateDeploymentResponse {
125
- deployment: DeploymentRecord;
126
- uploads: Partial<Record<ArtifactFile, PresignedPost>>;
127
- }
128
-
129
- export interface AppSummary {
130
- app: AppRecord;
131
- stages: StageRecord[];
101
+ githubToken: Schema.String.check(Schema.isNonEmpty({ message: 'githubToken is required' })),
102
+ });
103
+ export type CliLoginRequest = typeof CliLoginRequest.Type;
104
+
105
+ export const CliLoginResponse = Schema.Struct({
106
+ token: Schema.String,
107
+ github: Schema.String,
108
+ role: MemberRole,
109
+ expiresAt: Schema.String,
110
+ });
111
+ export type CliLoginResponse = typeof CliLoginResponse.Type;
112
+
113
+ // ---------------------------------------------------------------------------
114
+ // Apps
115
+ // ---------------------------------------------------------------------------
116
+
117
+ /** GitHub `owner/name`. */
118
+ export const REPO_PATTERN = /^[A-Za-z0-9-]{1,39}\/[A-Za-z0-9._-]{1,100}$/;
119
+ const Repo = Schema.Trim.check(Schema.isPattern(REPO_PATTERN, { message: 'repo must be "owner/name"' }));
120
+ /** Longer descriptions are cut to 200 characters rather than refused. */
121
+ const Description = Schema.String.pipe(
122
+ Schema.decode({
123
+ decode: SchemaGetter.transform((s: string) => s.slice(0, 200)),
124
+ encode: SchemaGetter.transform((s: string) => s),
125
+ }),
126
+ );
127
+
128
+ export const CreateAppRequest = Schema.Struct({
129
+ /** Checked against the naming rules and reserved names by the server. */
130
+ name: Schema.Trim,
131
+ repo: Repo,
132
+ description: optional(Description),
133
+ });
134
+ export type CreateAppRequest = typeof CreateAppRequest.Type;
135
+
136
+ export const UpdateAppRequest = Schema.Struct({
137
+ description: optional(Description),
138
+ repo: optional(Repo),
139
+ /** The server removes duplicates. */
140
+ owners: optional(
141
+ Schema.Array(Schema.String).check(Schema.isMinLength(1, { message: 'owners must be a non-empty list' })),
142
+ ),
143
+ });
144
+ export type UpdateAppRequest = typeof UpdateAppRequest.Type;
145
+
146
+ export const AppHealth = Schema.Struct({
147
+ up: Schema.NullOr(Schema.Boolean),
148
+ reqPerMin: Schema.Finite,
149
+ errorRate: Schema.Finite,
150
+ p95: Schema.NullOr(Schema.Finite),
151
+ });
152
+ export type AppHealth = typeof AppHealth.Type;
153
+
154
+ export const AppSummary = Schema.Struct({
155
+ app: AppRecord,
156
+ stages: Schema.Array(StageRecord),
132
157
  /** Prod health over the last hour (null when there is no prod stage). */
133
- health: {
134
- up: boolean | null;
135
- reqPerMin: number;
136
- errorRate: number;
137
- p95: number | null;
138
- } | null;
139
- costMonthToDateUsd?: number;
140
- lastDeployment?: DeploymentRecord;
141
- }
142
-
143
- export interface MetricsPoint {
144
- ts: string;
145
- req: number;
146
- s2xx: number;
147
- s3xx: number;
148
- s4xx: number;
149
- s5xx: number;
150
- p50: number | null;
151
- p95: number | null;
152
- p99: number | null;
153
- cold: number;
154
- }
155
-
156
- export interface MetricsResponse {
157
- app: string;
158
- stage: string;
159
- res: Resolution;
160
- points: MetricsPoint[];
161
- }
162
-
163
- export interface RouteStats {
164
- route: string;
165
- method: string;
166
- req: number;
167
- s5xx: number;
168
- s4xx: number;
169
- p50: number | null;
170
- p95: number | null;
171
- }
172
-
173
- export interface JobStats {
174
- kind: 'queue' | 'event' | 'cron' | 'invoke';
175
- name: string;
176
- ok: number;
177
- error: number;
178
- p95: number | null;
179
- lastRun?: string;
180
- }
181
-
182
- export interface QueueStats {
183
- name: string;
184
- visible: number;
185
- inFlight: number;
186
- deadLetter: number;
187
- oldestAgeSeconds: number | null;
188
- }
189
-
190
- export interface ErrorGroup {
191
- fingerprint: string;
192
- stage: string;
193
- name: string;
194
- message: string;
195
- source: string;
196
- count: number;
197
- firstSeen: string;
198
- lastSeen: string;
199
- status: 'open' | 'resolved' | 'ignored';
200
- sample: { stack?: string; route?: string; job?: string; trace?: string; rev?: string };
201
- }
202
-
203
- export interface LogLine {
204
- ts: string;
205
- stream: 'web' | 'worker';
206
- level?: string;
207
- message: string;
208
- trace?: string;
209
- event?: TelemetryEvent;
210
- }
211
-
212
- export interface LogsResponse {
213
- lines: LogLine[];
214
- nextToken?: string;
215
- }
216
-
217
- export interface TraceResponse {
218
- trace: string;
219
- events: TelemetryEvent[];
220
- }
221
-
222
- export interface UptimePoint {
223
- ts: string;
224
- ok: boolean;
225
- status: number;
226
- ms: number;
227
- }
228
-
229
- export interface CostResponse {
230
- app: string;
231
- currency: 'USD';
232
- days: Array<{ date: string; usd: number }>;
233
- monthToDateUsd: number;
234
- }
235
-
236
- export interface SecretInfo {
237
- name: string;
238
- scope: 'stage' | 'shared';
239
- stage?: string;
240
- updatedAt?: string;
241
- }
242
-
243
- export interface DataPage {
244
- items: Record<string, unknown>[];
245
- cursor?: string;
246
- }
247
-
248
- export interface ApiErrorBody {
249
- error: { code: string; message: string };
250
- }
158
+ health: Schema.NullOr(AppHealth),
159
+ costMonthToDateUsd: optional(Schema.Finite),
160
+ lastDeployment: optional(DeploymentRecord),
161
+ });
162
+ export type AppSummary = typeof AppSummary.Type;
163
+
164
+ // ---------------------------------------------------------------------------
165
+ // Stages and deployments
166
+ // ---------------------------------------------------------------------------
167
+
168
+ export const ArtifactFile = Schema.Literals(['manifest.json', 'server.zip', 'worker.zip', 'static.zip']);
169
+ export type ArtifactFile = typeof ArtifactFile.Type;
170
+
171
+ export const PresignedPost = Schema.Struct({
172
+ url: Schema.String,
173
+ fields: Schema.Record(Schema.String, Schema.String),
174
+ });
175
+ export type PresignedPost = typeof PresignedPost.Type;
176
+
177
+ export const CreateDeploymentRequest = Schema.Struct({
178
+ stage: Schema.String,
179
+ /**
180
+ * The evaluated `plat.config.ts` (`ManifestInput`). The server validates it
181
+ * with `parseManifest` and answers 422 with every issue when it's invalid.
182
+ */
183
+ manifest: Schema.Unknown,
184
+ /** Which artifacts the CLI will upload (manifest.json is always uploaded). */
185
+ files: optional(Schema.Array(ArtifactFile)),
186
+ commit: optional(Schema.String),
187
+ ref: optional(Schema.String),
188
+ message: optional(Schema.String),
189
+ });
190
+ export type CreateDeploymentRequest = typeof CreateDeploymentRequest.Encoded;
191
+
192
+ export const CreateDeploymentResponse = Schema.Struct({
193
+ deployment: DeploymentRecord,
194
+ /** A form for each artifact the request listed, plus `manifest.json`. */
195
+ uploads: Schema.Struct({
196
+ 'manifest.json': optional(PresignedPost),
197
+ 'server.zip': optional(PresignedPost),
198
+ 'worker.zip': optional(PresignedPost),
199
+ 'static.zip': optional(PresignedPost),
200
+ }),
201
+ });
202
+ export type CreateDeploymentResponse = typeof CreateDeploymentResponse.Type;
203
+
204
+ export const RollbackRequest = Schema.Struct({
205
+ /** Default: the stage's previous deployment. */
206
+ deploymentId: optional(Schema.String),
207
+ });
208
+ export type RollbackRequest = typeof RollbackRequest.Type;
209
+
210
+ export const RollbackResponse = Schema.Struct({
211
+ /** The deployment the stage routes to now. */
212
+ currentDeployment: Schema.String,
213
+ url: Schema.String,
214
+ });
215
+ export type RollbackResponse = typeof RollbackResponse.Type;
216
+
217
+ /** Answered with 202: the stage is being torn down. */
218
+ export const StageDestroying = Schema.Struct({ status: Schema.Literal('destroying') });
219
+ /** Answered with 200: there was nothing left to destroy. */
220
+ export const StageDestroyed = Schema.Struct({ status: Schema.Literal('destroyed') });
221
+ export const DestroyStageResponse = Schema.Union([StageDestroying, StageDestroyed]);
222
+ export type DestroyStageResponse = typeof DestroyStageResponse.Type;
223
+
224
+ // ---------------------------------------------------------------------------
225
+ // Observability
226
+ // ---------------------------------------------------------------------------
227
+
228
+ export const MetricsPoint = Schema.Struct({
229
+ ts: Schema.String,
230
+ req: Schema.Finite,
231
+ s2xx: Schema.Finite,
232
+ s3xx: Schema.Finite,
233
+ s4xx: Schema.Finite,
234
+ s5xx: Schema.Finite,
235
+ p50: Schema.NullOr(Schema.Finite),
236
+ p95: Schema.NullOr(Schema.Finite),
237
+ p99: Schema.NullOr(Schema.Finite),
238
+ cold: Schema.Finite,
239
+ });
240
+ export type MetricsPoint = typeof MetricsPoint.Type;
241
+
242
+ export const MetricsResponse = Schema.Struct({
243
+ app: Schema.String,
244
+ stage: Schema.String,
245
+ res: Resolution,
246
+ points: Schema.Array(MetricsPoint),
247
+ });
248
+ export type MetricsResponse = typeof MetricsResponse.Type;
249
+
250
+ export const RouteStats = Schema.Struct({
251
+ route: Schema.String,
252
+ method: Schema.String,
253
+ req: Schema.Finite,
254
+ s5xx: Schema.Finite,
255
+ s4xx: Schema.Finite,
256
+ p50: Schema.NullOr(Schema.Finite),
257
+ p95: Schema.NullOr(Schema.Finite),
258
+ });
259
+ export type RouteStats = typeof RouteStats.Type;
260
+
261
+ export const JobKind = Schema.Literals(['queue', 'event', 'cron', 'invoke']);
262
+ export type JobKind = typeof JobKind.Type;
263
+
264
+ export const JobStats = Schema.Struct({
265
+ kind: JobKind,
266
+ name: Schema.String,
267
+ ok: Schema.Finite,
268
+ error: Schema.Finite,
269
+ p95: Schema.NullOr(Schema.Finite),
270
+ lastRun: optional(Schema.String),
271
+ });
272
+ export type JobStats = typeof JobStats.Type;
273
+
274
+ export const JobsResponse = Schema.Struct({
275
+ jobs: Schema.Array(JobStats),
276
+ crons: Schema.Array(Schema.Struct({ name: Schema.String, schedule: Schema.String })),
277
+ });
278
+ export type JobsResponse = typeof JobsResponse.Type;
279
+
280
+ export const QueueStats = Schema.Struct({
281
+ name: Schema.String,
282
+ visible: Schema.Finite,
283
+ inFlight: Schema.Finite,
284
+ deadLetter: Schema.Finite,
285
+ oldestAgeSeconds: Schema.NullOr(Schema.Finite),
286
+ });
287
+ export type QueueStats = typeof QueueStats.Type;
288
+
289
+ export const ErrorStatus = Schema.Literals(['open', 'resolved', 'ignored']);
290
+ export type ErrorStatus = typeof ErrorStatus.Type;
291
+
292
+ export const ErrorGroup = Schema.Struct({
293
+ fingerprint: Schema.String,
294
+ stage: Schema.String,
295
+ name: Schema.String,
296
+ message: Schema.String,
297
+ source: Schema.String,
298
+ count: Schema.Finite,
299
+ firstSeen: Schema.String,
300
+ lastSeen: Schema.String,
301
+ status: ErrorStatus,
302
+ sample: Schema.Struct({
303
+ stack: optional(Schema.String),
304
+ route: optional(Schema.String),
305
+ job: optional(Schema.String),
306
+ trace: optional(Schema.String),
307
+ rev: optional(Schema.String),
308
+ }),
309
+ });
310
+ export type ErrorGroup = typeof ErrorGroup.Type;
311
+
312
+ export const UpdateErrorRequest = Schema.Struct({ status: ErrorStatus });
313
+ export type UpdateErrorRequest = typeof UpdateErrorRequest.Type;
314
+
315
+ export const LogLine = Schema.Struct({
316
+ ts: Schema.String,
317
+ stream: Schema.Literals(['web', 'worker']),
318
+ level: optional(Schema.String),
319
+ message: Schema.String,
320
+ trace: optional(Schema.String),
321
+ event: optional(TelemetryEvent),
322
+ });
323
+ export type LogLine = typeof LogLine.Type;
324
+
325
+ export const LogsResponse = Schema.Struct({
326
+ lines: Schema.Array(LogLine),
327
+ nextToken: optional(Schema.String),
328
+ });
329
+ export type LogsResponse = typeof LogsResponse.Type;
330
+
331
+ export const TraceResponse = Schema.Struct({
332
+ trace: Schema.String,
333
+ events: Schema.Array(TelemetryEvent),
334
+ });
335
+ export type TraceResponse = typeof TraceResponse.Type;
336
+
337
+ export const UptimePoint = Schema.Struct({
338
+ ts: Schema.String,
339
+ ok: Schema.Boolean,
340
+ status: Schema.Finite,
341
+ ms: Schema.Finite,
342
+ });
343
+ export type UptimePoint = typeof UptimePoint.Type;
344
+
345
+ export const CostResponse = Schema.Struct({
346
+ app: Schema.String,
347
+ currency: Schema.Literal('USD'),
348
+ days: Schema.Array(Schema.Struct({ date: Schema.String, usd: Schema.Finite })),
349
+ monthToDateUsd: Schema.Finite,
350
+ });
351
+ export type CostResponse = typeof CostResponse.Type;
352
+
353
+ // ---------------------------------------------------------------------------
354
+ // Data, storage, secrets, job controls
355
+ // ---------------------------------------------------------------------------
356
+
357
+ export const SecretInfo = Schema.Struct({
358
+ name: Schema.String,
359
+ scope: Schema.Literals(['stage', 'shared']),
360
+ stage: optional(Schema.String),
361
+ updatedAt: optional(Schema.String),
362
+ });
363
+ export type SecretInfo = typeof SecretInfo.Type;
364
+
365
+ export const SecretsResponse = Schema.Struct({
366
+ secrets: Schema.Array(SecretInfo),
367
+ /** Names `plat.config.ts` declares on the live deployment. */
368
+ declared: Schema.Array(Schema.String),
369
+ missing: Schema.Array(Schema.String),
370
+ });
371
+ export type SecretsResponse = typeof SecretsResponse.Type;
372
+
373
+ export const PutSecretRequest = Schema.Struct({
374
+ value: Schema.String.check(
375
+ Schema.isNonEmpty({ message: 'value is required' }),
376
+ Schema.isMaxLength(4096, { message: 'secret values are limited to 4 KB' }),
377
+ ),
378
+ });
379
+ export type PutSecretRequest = typeof PutSecretRequest.Type;
380
+
381
+ /** `GET /v1/apps/:app/data/collections`. */
382
+ export const DataCollections = Schema.Struct({
383
+ /**
384
+ * Whether the stage has a table. False when `db` is off in plat.config.ts or
385
+ * the stage was never deployed; a table kept after turning `db` off counts.
386
+ */
387
+ database: Schema.Boolean,
388
+ /** Item counts come from a bounded scan sample, so large collections are undercounted. */
389
+ collections: Schema.Array(Schema.Struct({ name: Schema.String, sampled: Schema.Finite })),
390
+ });
391
+ export type DataCollections = typeof DataCollections.Type;
392
+
393
+ export const DataPage = Schema.Struct({
394
+ items: Schema.Array(Schema.Record(Schema.String, Schema.Unknown)),
395
+ cursor: optional(Schema.String),
396
+ });
397
+ export type DataPage = typeof DataPage.Type;
398
+
399
+ export const StoredObjectInfo = Schema.Struct({
400
+ key: Schema.String,
401
+ size: Schema.Finite,
402
+ lastModified: optional(Schema.String),
403
+ });
404
+ export type StoredObjectInfo = typeof StoredObjectInfo.Type;
405
+
406
+ /** `GET /v1/apps/:app/storage`: the declared stores without `?store=`, a listing with it. */
407
+ export const StorageResponse = Schema.Union([
408
+ Schema.Struct({ stores: Schema.Array(Schema.String) }),
409
+ Schema.Struct({ objects: Schema.Array(StoredObjectInfo), cursor: optional(Schema.String) }),
410
+ ]);
411
+ export type StorageResponse = typeof StorageResponse.Type;
412
+
413
+ export const UrlResponse = Schema.Struct({ url: Schema.String });
414
+ export type UrlResponse = typeof UrlResponse.Type;
415
+
416
+ export const CronRunResponse = Schema.Struct({ started: Schema.String });
417
+ export type CronRunResponse = typeof CronRunResponse.Type;
418
+
419
+ export const RedriveResponse = Schema.Struct({ taskHandle: Schema.String });
420
+ export type RedriveResponse = typeof RedriveResponse.Type;
421
+
422
+ // ---------------------------------------------------------------------------
423
+ // Admin
424
+ // ---------------------------------------------------------------------------
425
+
426
+ export const AdminOverview = Schema.Struct({
427
+ members: Schema.Array(Schema.Struct({ github: Schema.String, role: MemberRole })),
428
+ limits: Schema.Struct({ appsPerMember: Schema.Finite, stagesPerApp: Schema.Finite }),
429
+ apps: Schema.Finite,
430
+ stages: Schema.Finite,
431
+ previews: Schema.Finite,
432
+ /** Apps with a stage whose uptime check is failing. */
433
+ down: Schema.Array(Schema.String),
434
+ cost: Schema.Struct({ total: Schema.NullOr(CostResponse), shared: Schema.NullOr(CostResponse) }),
435
+ });
436
+ export type AdminOverview = typeof AdminOverview.Type;
437
+
438
+ // ---------------------------------------------------------------------------
439
+ // Errors
440
+ // ---------------------------------------------------------------------------
441
+
442
+ /** Body of every API error, whatever the status. */
443
+ export const ApiErrorBody = Schema.Struct({
444
+ error: Schema.Struct({ code: Schema.String, message: Schema.String }),
445
+ });
446
+ export type ApiErrorBody = typeof ApiErrorBody.Type;