@fabrika/provider-zerops 0.2.0 → 0.3.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 (82) hide show
  1. package/package.json +18 -5
  2. package/src/api/client.ts +522 -0
  3. package/src/api/errors.ts +50 -0
  4. package/src/api/polling.ts +59 -0
  5. package/src/api/readers.ts +185 -0
  6. package/src/api/service-env-response.ts +34 -0
  7. package/src/api/types.ts +602 -0
  8. package/src/api.ts +29 -1378
  9. package/src/authoring.ts +7 -10
  10. package/src/cli-args.ts +0 -5
  11. package/src/cli.ts +3 -28
  12. package/src/collaborators.ts +2 -4
  13. package/src/compile.ts +3 -1
  14. package/src/control.ts +203 -450
  15. package/src/descriptor.ts +135 -0
  16. package/src/index.ts +23 -127
  17. package/src/installation/admin-options.ts +128 -0
  18. package/src/installation/admin.ts +123 -0
  19. package/src/installation/deploy-options.ts +155 -0
  20. package/src/installation/deploy.ts +668 -0
  21. package/src/installation/generated/platform-console-schema.ts +41 -0
  22. package/src/installation/generated/platform-proxy-manifest.ts +72 -0
  23. package/src/installation/hosts.ts +117 -0
  24. package/src/installation/index.ts +366 -0
  25. package/src/installation/init.ts +521 -0
  26. package/src/installation/install-collaborators.ts +28 -0
  27. package/src/installation/install-environment.ts +193 -0
  28. package/src/installation/install-options.ts +193 -0
  29. package/src/installation/install-project.ts +201 -0
  30. package/src/installation/install-provisioning.ts +185 -0
  31. package/src/installation/install.ts +286 -0
  32. package/src/installation/installation-source.ts +42 -0
  33. package/src/installation/log.ts +77 -0
  34. package/src/installation/machine-key.ts +65 -0
  35. package/src/installation/manifest.ts +95 -0
  36. package/src/installation/placement-options.ts +33 -0
  37. package/src/installation/platform-source.ts +106 -0
  38. package/src/installation/platform-upload.ts +34 -0
  39. package/src/installation/proxy-manifest.ts +113 -0
  40. package/src/installation/secrets.ts +79 -0
  41. package/src/installation/sidecar.ts +122 -0
  42. package/src/installation/source-options.ts +12 -0
  43. package/src/installation/templates/README.md +116 -0
  44. package/src/installation/templates/fabrika.ref +1 -0
  45. package/src/installation/templates/gitignore +3 -0
  46. package/src/installation/templates/platform.yml +144 -0
  47. package/src/installation/topology/artifacts.ts +141 -0
  48. package/src/installation/topology/index.ts +13 -0
  49. package/src/installation/topology/installation-schemas.ts +225 -0
  50. package/src/installation/topology/invariants.ts +86 -0
  51. package/src/installation/topology/setups.ts +442 -0
  52. package/src/installation/topology/topology.ts +501 -0
  53. package/src/installation/topology/validate.ts +26 -0
  54. package/src/installation/upgrade-options.ts +108 -0
  55. package/src/installation/upgrade-output.ts +31 -0
  56. package/src/installation/upgrade.ts +373 -0
  57. package/src/managed-env.ts +105 -0
  58. package/src/manifest.ts +191 -344
  59. package/src/namespace/claims.ts +77 -0
  60. package/src/namespace/codec.ts +179 -0
  61. package/src/namespace/constants.ts +30 -0
  62. package/src/namespace/errors.ts +60 -0
  63. package/src/namespace/manifest.ts +28 -0
  64. package/src/namespace/operator.ts +151 -0
  65. package/src/namespace/provisioning.ts +482 -0
  66. package/src/namespace/proxy-attempt.ts +220 -0
  67. package/src/namespace/proxy-source.ts +22 -0
  68. package/src/namespace/topology.ts +115 -0
  69. package/src/namespace/types.ts +114 -0
  70. package/src/namespace.ts +34 -1271
  71. package/src/plan.ts +21 -23
  72. package/src/provider.ts +266 -241
  73. package/src/source/constants.ts +11 -0
  74. package/src/source/port.ts +49 -0
  75. package/src/source/types.ts +4 -0
  76. package/src/source/validation.ts +72 -0
  77. package/src/source.ts +2 -1220
  78. package/src/types.ts +8 -7
  79. package/src/version-attempt.ts +18 -0
  80. package/src/codec.ts +0 -108
  81. package/src/namespace-command.ts +0 -209
  82. package/src/source-connection.ts +0 -344
@@ -0,0 +1,602 @@
1
+ // The ZEROPS driver's collaborator: a thin, typed client over the Zerops REST API. This is the whole
2
+ // side-effect surface of a Zerops deploy — ADR-0003 says a deploy there is HTTP calls and nothing else, so
3
+ // substituting this ONE interface is what makes the driver testable and dry-run-able (ADR-0011).
4
+ //
5
+ // PROVENANCE. Every request/response shape below was read off Zerops' own OpenAPI document, served at
6
+ // `https://api.app-prg1.zerops.io/api/rest/public/swagger/openapi.yml` (linked from the REST API
7
+ // reference). Members whose shape could NOT be read off that document are marked `UNVERIFIED:` in their
8
+ // doc comment — there is exactly one such area (the log service behind `GET /project/{id}/log`), plus a
9
+ // handful of BEHAVIOURS (as opposed to shapes) that no document states. Do not quietly promote one to
10
+ // fact; check it against a real account first.
11
+ //
12
+ // SECURITY. The token is a Zerops PERSONAL ACCESS TOKEN and carries account-wide admin rights. It is
13
+ // never logged, never included in an error message, and never returned from a method. There is exactly
14
+ // one credential this module DOES hand back — the integration token `createIntegrationToken` mints, which
15
+ // exists so that nothing has to reuse the personal one; it obeys the same no-log, no-error-message rule.
16
+
17
+ import type { Sleeper } from '../collaborators'
18
+
19
+ /** Every status a Zerops application version can be in. VERIFIED: `OutDtoGetAppVersion.status` enum. */
20
+ export type ZeropsAppVersionStatus =
21
+ | 'UPLOADING'
22
+ | 'WAITING_TO_BUILD'
23
+ | 'BUILDING'
24
+ | 'BUILD_FAILED'
25
+ | 'BUILD_VALIDATION_FAILED'
26
+ | 'WAITING_TO_DEPLOY'
27
+ | 'DEPLOYING'
28
+ | 'DEPLOY_FAILED'
29
+ | 'PREPARING_RUNTIME'
30
+ | 'PREPARING_RUNTIME_FAILED'
31
+ | 'ACTIVE'
32
+ | 'BACKUP'
33
+ | 'CANCELLED'
34
+
35
+ /** The one status that means "this version is live". */
36
+ export const ZEROPS_ACTIVE: ZeropsAppVersionStatus = 'ACTIVE'
37
+
38
+ /**
39
+ * Statuses a version never leaves. `BACKUP` is included deliberately: a version we triggered that has
40
+ * become an archived one was superseded by another deploy, which is an outcome, not a step on the way.
41
+ */
42
+ export const ZEROPS_TERMINAL: ReadonlySet<ZeropsAppVersionStatus> = new Set<ZeropsAppVersionStatus>([
43
+ 'ACTIVE',
44
+ 'BACKUP',
45
+ 'BUILD_FAILED',
46
+ 'BUILD_VALIDATION_FAILED',
47
+ 'DEPLOY_FAILED',
48
+ 'PREPARING_RUNTIME_FAILED',
49
+ 'CANCELLED',
50
+ ])
51
+
52
+ /** One application version, narrowed to what the driver reads. VERIFIED: `GET /app-version/{id}`. */
53
+ export interface ZeropsAppVersion {
54
+ id: string
55
+ /** Absent on a response that omitted it; the poll loop treats that as "not yet known". */
56
+ status?: ZeropsAppVersionStatus
57
+ serviceStackId?: string
58
+ projectId?: string
59
+ /** Monotonic per service — how Zerops orders the 10 versions it retains. */
60
+ sequence?: number
61
+ /** Build-pipeline timestamps (ISO dateTime), when a build ran. */
62
+ build?: { startDate?: string; endDate?: string; pipelineStart?: string; pipelineFinish?: string; pipelineFailed?: string }
63
+ }
64
+
65
+ /** The credential-bearing result of reserving one upload-backed application version. */
66
+ export interface ZeropsAppVersionUpload {
67
+ id: string
68
+ /** Presigned object-storage destination. Never log it or include it in an error. */
69
+ uploadUrl: string
70
+ }
71
+
72
+ /** An asynchronous platform operation. VERIFIED: `OutDtoProcess`. */
73
+ export interface ZeropsProcess {
74
+ id: string
75
+ /** Free-form on the wire (`OutDtoProcess.status` is an untyped string defaulting to `PENDING`). */
76
+ status?: string
77
+ actionName?: string
78
+ serviceStackId?: string
79
+ appVersionId?: string
80
+ }
81
+
82
+ /**
83
+ * The status a process that succeeded carries.
84
+ *
85
+ * VERIFIED AS A VALUE, not as an enum member: `docs/reference/zerops-platform.md` records
86
+ * `stack.updateUserData`, `stack.enableSubdomainAccess` and an import's processes reaching exactly this
87
+ * string live. `ResponseProcess.status` is an untyped string in the published document, so the platform
88
+ * declares no set anywhere.
89
+ */
90
+ export const ZEROPS_PROCESS_FINISHED = 'FINISHED'
91
+
92
+ /**
93
+ * Statuses a process never leaves.
94
+ *
95
+ * UNVERIFIED AS A CLOSED SET — the OpenAPI document gives `ResponseProcess.status` no enum at all. These
96
+ * are the values `zops process list --status` documents (`PENDING, RUNNING, FINISHED, FAILED, CANCELED`)
97
+ * minus the two that mean "still going". Note the single `L` in `CANCELED`: an app VERSION spells the same
98
+ * idea `CANCELLED`, and the two vocabularies are not the same one.
99
+ *
100
+ * `waitForProcess` treats everything not in here as "keep waiting", so a status this build has never seen
101
+ * can only ever cost time — it can never be read as success.
102
+ */
103
+ export const ZEROPS_PROCESS_TERMINAL: ReadonlySet<string> = new Set(['FINISHED', 'FAILED', 'CANCELED'])
104
+
105
+ /** One service created or updated by an import. VERIFIED: `OutDtoProjectImportServiceStack`. */
106
+ export interface ZeropsImportedService {
107
+ id: string
108
+ /** The service's name as Zerops stores it (hostname, possibly suffixed by env). */
109
+ name: string
110
+ processes: ZeropsProcess[]
111
+ }
112
+
113
+ /** The result of applying an import document. VERIFIED: `ResponseProjectImport`. */
114
+ export interface ZeropsImportResult {
115
+ projectId: string
116
+ projectName?: string
117
+ services: ZeropsImportedService[]
118
+ }
119
+
120
+ /** Every documented project lifecycle state. VERIFIED: `ResponseProject.status`. */
121
+ export type ZeropsProjectStatus = 'NEW' | 'CREATING' | 'ACTIVE' | 'DELETING' | 'FAILED' | 'STOPPING' | 'STOPPED' | 'STARTING'
122
+
123
+ /** Project compute tier. The import schema calls the same choice `corePackage`. VERIFIED: `ResponseProject.mode`. */
124
+ export type ZeropsProjectMode = 'LIGHT' | 'SERIOUS'
125
+
126
+ /** Every documented service-stack lifecycle state. VERIFIED: `ResponseServiceStack.status`. */
127
+ export type ZeropsServiceStatus =
128
+ | 'NEW'
129
+ | 'CREATING'
130
+ | 'ACTIVE'
131
+ | 'STOPPING'
132
+ | 'STOPPED'
133
+ | 'STARTING'
134
+ | 'RESTARTING'
135
+ | 'RELOADING'
136
+ | 'DELETING'
137
+ | 'DELETED'
138
+ | 'FAILED'
139
+ | 'ACTION_FAILED'
140
+ | 'UPGRADING'
141
+ | 'READY_TO_DEPLOY'
142
+ | 'SERVICE_CREATING'
143
+ | 'SERVICE_ACTIVE'
144
+ | 'SERVICE_STOPPING'
145
+ | 'SERVICE_STOPPED'
146
+ | 'SERVICE_STARTING'
147
+ | 'SERVICE_RESTARTING'
148
+ | 'SERVICE_RELOADING'
149
+ | 'SERVICE_DELETING'
150
+ | 'SERVICE_DELETED'
151
+ | 'SERVICE_FAILED'
152
+ | 'SERVICE_ACTION_FAILED'
153
+ | 'SERVICE_REPAIRING'
154
+ | 'SERVICE_CONTAINER_FAILED'
155
+ | 'SERVICE_MOVING_CONTAINER'
156
+ | 'SERVICE_UPGRADING'
157
+ | 'SERVICE_SCALING'
158
+ | 'SERVICE_REPAIR_FAILED'
159
+ | 'REPAIRING'
160
+ | 'CONTAINER_FAILED'
161
+ | 'MOVING_CONTAINER'
162
+ | 'SCALING'
163
+ | 'REPAIR_FAILED'
164
+
165
+ /** One service. VERIFIED: `ResponseServiceStack` (narrowed to the fields fabrika reads). */
166
+ export interface ZeropsService {
167
+ id: string
168
+ name: string
169
+ projectId?: string
170
+ status?: ZeropsServiceStatus
171
+ /** Full service-type identifier, e.g. `alpine/bun@1.3`. VERIFIED: `ResponseServiceStack.base`. */
172
+ base?: string
173
+ activeAppVersionId?: string
174
+ /** Whether Zerops' public subdomain routes this service. VERIFIED: `ResponseServiceStack.subdomainAccess`. */
175
+ subdomainAccess?: boolean
176
+ /** Provider profile identifier, e.g. `oltp-production`. VERIFIED: `ResponseServiceStack.autoscalingProfileId`. */
177
+ autoscalingProfileId?: string
178
+ }
179
+
180
+ /** One project. VERIFIED: `ResponseProject` (narrowed). */
181
+ export interface ZeropsProject {
182
+ id: string
183
+ name: string
184
+ status?: ZeropsProjectStatus
185
+ /** The wire calls the import schema's `corePackage` choice `mode`. */
186
+ mode?: ZeropsProjectMode
187
+ /** VERIFIED: `ResponseProject.description`. */
188
+ description?: string
189
+ /** VERIFIED: `ResponseProject.tagList`. */
190
+ tagList?: string[]
191
+ }
192
+
193
+ /**
194
+ * A Zerops access role. VERIFIED: the `roleCode` enum, shared by `RequestClientIntegrationToken` and
195
+ * `ResponseClientIntegrationTokenRaw`.
196
+ *
197
+ * Tiered, and the schema's own description states the order: `OWNER > ADMIN > BASIC_USER > READ_ONLY >
198
+ * NO_ACCESS`, with a PROJECT role overriding the client-wide one. That override is the whole mechanism
199
+ * behind a scoped token — client `NO_ACCESS` plus one project `ADMIN` reaches exactly one project.
200
+ */
201
+ export type ZeropsRoleCode = 'OWNER' | 'ADMIN' | 'BASIC_USER' | 'READ_ONLY' | 'NO_ACCESS'
202
+
203
+ /**
204
+ * One project grant carried by an integration token. VERIFIED:
205
+ * `ResponseClientIntegrationTokenRaw.projects[]` — `projectId` is required and `roleCode` is not, so a
206
+ * grant read back can omit it (the schema documents `NO_ACCESS` as the default; this client does not
207
+ * substitute one, because an assumed grant is worse than an absent one).
208
+ */
209
+ export interface ZeropsTokenProjectGrant {
210
+ projectId: string
211
+ roleCode?: ZeropsRoleCode
212
+ }
213
+
214
+ /**
215
+ * A freshly minted integration token. VERIFIED: `ResponseClientIntegrationTokenRaw` — `id`, `name`,
216
+ * `projects` and `token` are all in its `required` list.
217
+ *
218
+ * THE ONE SHAPE ON THIS CLIENT THAT CARRIES A CREDENTIAL, and the `Raw` in the schema's name is why: the
219
+ * plaintext `token` appears in this one response and nowhere afterwards. Everything the module header says
220
+ * about the personal access token applies to it — never logged, never in an error message — with the
221
+ * single exception that it must reach whatever is going to store it.
222
+ */
223
+ export interface ZeropsIntegrationToken {
224
+ id: string
225
+ name: string
226
+ /** The bearer value. NEVER log it. */
227
+ token: string
228
+ /** The grants the platform actually recorded, so a caller can check the scope it asked for. */
229
+ projects: ZeropsTokenProjectGrant[]
230
+ /** The client-wide role. Absent from the response's `required` list, so it can genuinely be missing. */
231
+ roleCode?: ZeropsRoleCode
232
+ }
233
+
234
+ /**
235
+ * ONE service-level environment variable. VERIFIED: `OutDtoUserData`.
236
+ *
237
+ * UNVERIFIED BEHAVIOUR: whether `content` carries the real value for a variable Zerops stores as a
238
+ * SECRET, or a blurred placeholder. `docs/backlog/06-can-zerops-secrets-be-read-back.md` is open on
239
+ * exactly this; the dashboard UX depends on the answer. Never log `content`.
240
+ */
241
+ export interface ZeropsServiceEnv {
242
+ id: string
243
+ key: string
244
+ content: string
245
+ serviceStackId?: string
246
+ /** Record classification, not a sensitivity or ownership guarantee; sensitive records can be USER. */
247
+ type?: string
248
+ /** Live service-env responses identify sensitive USER records independently of their type. */
249
+ sensitive?: boolean
250
+ }
251
+
252
+ /**
253
+ * A short-lived grant for the project's LOG service. VERIFIED: `ResponseProjectLog` — the field names and
254
+ * types are exactly these. What the URLs speak was measured separately; see `readBuildLog`.
255
+ */
256
+ export interface ZeropsLogAccess {
257
+ url: string
258
+ urlPlain: string
259
+ urlInfo: string
260
+ urlUi: string
261
+ /** Bearer for the log service (a different credential from the personal access token). Never log it. */
262
+ accessToken: string
263
+ /** ISO dateTime after which the grant is dead and must be re-fetched. */
264
+ expiration: string
265
+ }
266
+
267
+ /** One relayed build/runtime log line. Shape is fabrika's, not the platform's. */
268
+ export interface ZeropsLogLine {
269
+ /** RFC3339 stamp Zerops put at the head of the line, when the line carried one. */
270
+ timestamp?: string
271
+ /** The line as the log service wrote it, timestamp and tag included. */
272
+ message: string
273
+ }
274
+
275
+ /**
276
+ * The Zerops REST surface fabrika depends on, as ONE injectable interface (ADR-0011's collaborator
277
+ * bundle). Every method takes the run's `AbortSignal`: a driver that polls `/app-version` is precisely the
278
+ * case cancellation was added for, and an abandoned run must not keep an HTTP request alive.
279
+ *
280
+ * WIDER THAN THE DRIVER, on purpose. The driver uses four of these; the rest are the CONTROL PLANE's
281
+ * Zerops surface — the service-env methods for the edit-time secret writes that ADR-0004 says are not a
282
+ * deploy step, `importProject` for creating a managed project, and `getAppVersion`/`latestAppVersion` for
283
+ * the startup reconciliation of in-flight runs that ADR-0003 makes a requirement. One client, so there is
284
+ * one place the Zerops contract is written down.
285
+ *
286
+ * NOTE WHAT IS ABSENT. There is no method that writes a PROJECT-level environment variable. That is not
287
+ * an oversight and must not be "completed": project-level variables are injected into every service in the
288
+ * project, and one project holds many apps, so a project-level write hands app A's credentials to app B
289
+ * (ADR-0004). The invariant is enforced by the surface not existing — `POST /project/{id}/env` and
290
+ * `PUT /project-env/{id}` are real endpoints that this client deliberately does not expose. `getProjectEnv`
291
+ * reads one back (for drift reporting); nothing here can create or change one.
292
+ */
293
+ export interface ZeropsApi {
294
+ // ── service-stack: applying the compiled import document ──────────────────────
295
+
296
+ /**
297
+ * Apply a `zerops-import.yaml` (its `services:` section) to an EXISTING project — fabrika's
298
+ * provisioning step. VERIFIED: `POST /project/{id}/service-stack/import`, body `{ yaml }`.
299
+ *
300
+ * VERIFIED (2026-08-05): re-applying an unchanged document is a complete no-op — same ids, no
301
+ * processes, `lastUpdate` unmoved. That is ADR-0003's idempotency claim, and it is ALL of it: a
302
+ * changed `profile`/`maxContainers`/`objectStorageSize` is silently ignored too, so this reconciles
303
+ * nothing. Change a live field through the API that owns it.
304
+ */
305
+ importServices(input: { projectId: string; yaml: string; signal: AbortSignal }): Promise<ZeropsImportResult>
306
+
307
+ /**
308
+ * Apply a full `zerops-import.yaml` INCLUDING its `project:` section, creating the project.
309
+ * VERIFIED: `POST /client/{id}/project/import`, body `{ yaml }`.
310
+ *
311
+ * Needed because `envIsolation` is settable at project CREATION only — `RequestPutProject` has no such
312
+ * field, so a project made without it cannot be corrected through the project API afterwards. The
313
+ * driver compensates by also setting `envIsolation` per service, which the schema says overrides the
314
+ * project-level value.
315
+ */
316
+ importProject(input: { clientId: string; yaml: string; signal: AbortSignal }): Promise<ZeropsImportResult>
317
+
318
+ // ── app-version: build + deploy ───────────────────────────────────────────────
319
+
320
+ /**
321
+ * Trigger a build+deploy pipeline for a service. VERIFIED:
322
+ * `PUT /service-stack/{id}/trigger-pipeline`, body `RequestPutStandardServiceStackTriggerPipeline`.
323
+ *
324
+ * With no `buildFromGit` the platform builds from the service's configured Git integration (the
325
+ * private-repo path); with one it does a one-time build from that PUBLIC repository URL.
326
+ *
327
+ * UNVERIFIED BEHAVIOUR: the response is `{ process?: … }` with EVERY field optional, so whether the
328
+ * new app-version id is reliably reachable at `process.appVersion.id` is a guess. The driver therefore
329
+ * does not depend on it — it resolves the version it triggered via `latestAppVersion` instead.
330
+ */
331
+ triggerPipeline(input: {
332
+ serviceId: string
333
+ /** Public Git repository URL for a one-time build. Omit to use the service's Git integration. */
334
+ buildFromGit?: string
335
+ /** Inline `zerops.yaml`, overriding whatever is in the repo. */
336
+ zeropsYaml?: string
337
+ /** Which `setup:` block of the `zerops.yaml` to use. */
338
+ zeropsSetup?: string
339
+ signal: AbortSignal
340
+ }): Promise<ZeropsProcess | null>
341
+
342
+ /**
343
+ * Reserve an upload-backed application version. VERIFIED: `POST /service-stack/{id}/app-version`,
344
+ * optional body `{ name }`, response `ResponsePostAppVersion`.
345
+ */
346
+ createAppVersion(input: { serviceId: string; name?: string; signal: AbortSignal }): Promise<ZeropsAppVersionUpload>
347
+
348
+ /**
349
+ * Build and deploy an application version whose source archive has already been uploaded. VERIFIED:
350
+ * `PUT /app-version/{id}/build-and-deploy`, required body `{ zeropsYaml }` and optional
351
+ * `zeropsYamlSetup`.
352
+ */
353
+ buildAndDeployAppVersion(input: {
354
+ appVersionId: string
355
+ zeropsYaml: string
356
+ zeropsYamlSetup?: string
357
+ signal: AbortSignal
358
+ }): Promise<ZeropsProcess>
359
+
360
+ /** Delete an application version, including an untriggered upload reservation. VERIFIED: `DELETE /app-version/{id}`. */
361
+ deleteAppVersion(input: { appVersionId: string; signal: AbortSignal }): Promise<void>
362
+
363
+ /** One application version's current state — the poll target. VERIFIED: `GET /app-version/{id}`. */
364
+ getAppVersion(input: { appVersionId: string; signal: AbortSignal }): Promise<ZeropsAppVersion>
365
+
366
+ /**
367
+ * The newest application version of a service. VERIFIED: `GET /service-stack/{id}/app-version`
368
+ * (`{ list, total }`, `limit`/`offset`/`statuses` query params).
369
+ *
370
+ * UNVERIFIED BEHAVIOUR: the list's ORDER. The driver does not rely on it — it picks the highest
371
+ * `sequence`, which the schema documents as monotonic per service.
372
+ */
373
+ latestAppVersion(input: { serviceId: string; signal: AbortSignal }): Promise<ZeropsAppVersion | null>
374
+
375
+ /** Cancel an in-flight build — what a cancelled run does with the work it started. VERIFIED: `PUT /app-version/{id}/cancel-build`. */
376
+ cancelBuild(input: { appVersionId: string; signal: AbortSignal }): Promise<void>
377
+
378
+ // ── process: the asynchronous half of almost every write ──────────────────────
379
+
380
+ /**
381
+ * One platform operation's current state. VERIFIED: `GET /process/{id}` (`GetProcessDetails`,
382
+ * response `ResponseProcess`).
383
+ *
384
+ * WHAT IT IS FOR. Several writes here return a process INSTEAD of their result and complete afterwards:
385
+ * an import hands back one per service it touched, and `POST /service-stack/{id}/user-data` answers with
386
+ * a process rather than the record it created. A caller that imports services and then immediately
387
+ * writes their environment needs to know the import's processes finished, and until this existed
388
+ * nothing could ask.
389
+ *
390
+ * UNVERIFIED BEHAVIOUR: the status VOCABULARY (see `ZEROPS_PROCESS_TERMINAL`). The published document
391
+ * types `status` as a bare string defaulting to `PENDING`, so it stays `string` here rather than being
392
+ * narrowed to a set nobody publishes.
393
+ */
394
+ getProcess(input: { processId: string; signal: AbortSignal }): Promise<ZeropsProcess>
395
+
396
+ // ── service-stack: public access ──────────────────────────────────────────────
397
+
398
+ /**
399
+ * Publish a service on Zerops' generated `*.zerops.app` subdomain. VERIFIED:
400
+ * `PUT /service-stack/{id}/enable-subdomain-access`, no body, `ResponseProcess`.
401
+ *
402
+ * THE ONLY THING THAT ESTABLISHES ONE. `enableSubdomainAccess: true` in an import document is accepted
403
+ * and then silently dropped — on CREATE as well as on `override` — so a service imported with it reads
404
+ * back `subdomainAccess: false` and stays that way (`docs/reference/zerops-platform.md`).
405
+ *
406
+ * TWO ORDERING FACTS the caller must respect. It needs a DEPLOYED HTTP port: before the first deploy
407
+ * the platform answers `400 serviceStackIsNotHttp`. And a 2xx here is NOT a success signal — calling it
408
+ * on a service that already has a subdomain returns a process that then FAILS — so decide by reading
409
+ * `getService().subdomainAccess` back, never by this call returning.
410
+ */
411
+ enableSubdomainAccess(input: { serviceId: string; signal: AbortSignal }): Promise<void>
412
+
413
+ // ── service-stack / project: reading state ────────────────────────────────────
414
+
415
+ /** One service by id. VERIFIED: `GET /service-stack/{id}`. */
416
+ getService(input: { serviceId: string; signal: AbortSignal }): Promise<ZeropsService>
417
+
418
+ /** One service by hostname within a project, or `null` if absent. VERIFIED: `GET /service-stack-by-name/{projectId}/{name}`. */
419
+ findService(input: { projectId: string; hostname: string; signal: AbortSignal }): Promise<ZeropsService | null>
420
+
421
+ /** One project by id. VERIFIED: `GET /project/{id}`. */
422
+ getProject(input: { projectId: string; signal: AbortSignal }): Promise<ZeropsProject>
423
+
424
+ /**
425
+ * Every project under a client. VERIFIED: `GET /client/{id}/project`.
426
+ * The implementation follows the response's `total` with explicit `limit`/`offset` pages.
427
+ */
428
+ listProjects(input: { clientId: string; signal: AbortSignal }): Promise<ZeropsProject[]>
429
+
430
+ /**
431
+ * Every exact-name match under a client. VERIFIED: `GET /client/{id}/projects-by-name/{name}`.
432
+ * Zerops returns an array, so duplicate names remain visible to the caller.
433
+ */
434
+ findProjects(input: { clientId: string; name: string; signal: AbortSignal }): Promise<ZeropsProject[]>
435
+
436
+ /**
437
+ * Every service stack under a project. VERIFIED: `GET /project/{id}/service-stack`.
438
+ * The implementation follows the response's `total` with explicit `limit`/`offset` pages.
439
+ */
440
+ listProjectServices(input: { projectId: string; signal: AbortSignal }): Promise<ZeropsService[]>
441
+
442
+ // ── user-data: SERVICE-level environment variables (ADR-0004) ─────────────────
443
+ //
444
+ // EVERY WRITE HERE IS ASYNCHRONOUS. Create, replace and delete each answer with a PENDING
445
+ // `stack.updateUserData` process rather than the record, and while one is running the platform
446
+ // refuses the next operation on that service with `400 userDataSyncRunning`. So all three wait for
447
+ // their own process before returning: a caller that writes a variable and then builds — which is
448
+ // what every deploy does — must not have to know that.
449
+
450
+ /**
451
+ * Every environment variable of ONE service, each with the record id `deleteServiceEnv` takes.
452
+ * VERIFIED: `GET /service-stack/{id}/env` (`{ items }`).
453
+ *
454
+ * NOT `GET /service-stack/{id}/user-data`: it answers a list now (2026-08-21), but `/env` is the
455
+ * endpoint whose record ids `PUT`/`DELETE /user-data/{id}` take, and the list's paging terms were
456
+ * never verified — see `docs/reference/zerops-platform.md`. The `/env` reading omits
457
+ * variables the service's own `zerops.yaml` declares (`type: ENV`); fabrika never writes those.
458
+ * The OpenAPI publishes no lookup/pagination terms and live probes found query terms ignored, so the
459
+ * implementation reads one full response under a byte bound rather than imposing an entry-count cap.
460
+ */
461
+ listServiceEnv(input: { serviceId: string; signal: AbortSignal }): Promise<ZeropsServiceEnv[]>
462
+
463
+ /**
464
+ * Create ONE service-level variable only when the key is absent.
465
+ * VERIFIED: `POST /service-stack/{id}/user-data`, body `{ key, content }`.
466
+ *
467
+ * Unlike `putServiceEnv`, a duplicate is an error and is never followed by a read or update. Error
468
+ * details are intentionally unavailable because both the request and an upstream response can contain
469
+ * the secret value.
470
+ */
471
+ createServiceEnv(input: { serviceId: string; key: string; value: string; signal: AbortSignal }): Promise<void>
472
+
473
+ /**
474
+ * Create-or-update ONE service-level variable — the only way fabrika ever writes a secret, and it is
475
+ * addressed BY SERVICE so ADR-0004's invariant cannot be violated by calling it.
476
+ * VERIFIED: `POST /service-stack/{id}/user-data` creates and `PUT /user-data/{id}` replaces, both
477
+ * `{ key, content }`; POSTing an existing key answers `400 userDataDuplicateKey` and changes nothing.
478
+ *
479
+ * WRITE FIRST, READ ONLY ON CONFLICT. A read before the write cannot be part of this: the create
480
+ * must work on a service that has never been deployed, which is exactly ADR-0004's bring-up order.
481
+ */
482
+ putServiceEnv(input: { serviceId: string; key: string; value: string; signal: AbortSignal }): Promise<void>
483
+
484
+ /** Delete one service-level variable by its record id. VERIFIED: `DELETE /user-data/{id}`. */
485
+ deleteServiceEnv(input: { envId: string; signal: AbortSignal }): Promise<void>
486
+
487
+ /**
488
+ * Read ONE project-level variable back, by record id. VERIFIED: `GET /project-env/{id}`.
489
+ * Read-only ON PURPOSE — see the note on this interface. Present so drift can be REPORTED.
490
+ */
491
+ getProjectEnv(input: { projectEnvId: string; signal: AbortSignal }): Promise<ZeropsServiceEnv>
492
+
493
+ // ── client: minting a credential ──────────────────────────────────────────────
494
+
495
+ /**
496
+ * Mint a project-scoped INTEGRATION token. VERIFIED: `POST /client/{id}/integration-token`
497
+ * (`createIntegrationToken`), body `RequestClientIntegrationToken` — `name` and `projects` are its two
498
+ * required members — response `ResponseClientIntegrationTokenRaw`, whose `required` list contains
499
+ * `token`.
500
+ *
501
+ * WHAT IT IS FOR. A control plane deployed on Zerops holds a Zerops credential, and it must not be the
502
+ * personal access token an operator or a bootstrap authenticated with: that one carries account-wide
503
+ * admin rights (module header). An integration token left at client `NO_ACCESS` with one project
504
+ * granted `ADMIN` can do nothing outside that project.
505
+ *
506
+ * `roleCode` IS ALWAYS SENT, even when its value is the schema's own default, for the reason
507
+ * `compile.ts` writes `envIsolation` instead of inheriting it: a security-relevant field that never
508
+ * reaches the wire is a field nobody can review.
509
+ *
510
+ * `canCreateProjects` IS EXPOSED, because a control plane that provisions app namespaces cannot work
511
+ * without it: every namespace preset creates a project, and `POST /client/{id}/project/import` answers
512
+ * `403 insufficientPermissions` to a token without the flag (measured live, 2026-08-18; ADR-0034).
513
+ * The cost is real and bounded — the token receives `OWNER` on what it creates, and nothing else:
514
+ * `roleCode` stays `NO_ACCESS`, so a project it never created and was never granted stays unreachable.
515
+ *
516
+ * NOT EXPOSED, deliberately: `canViewFinances` / `canEditFinances`. Both default to `false`, and
517
+ * fabrika has no use for either.
518
+ *
519
+ * UNVERIFIED BEHAVIOUR: EVERYTHING AT RUNTIME. No token has ever been minted against a real account —
520
+ * doing so is a mutation, not an inspection — so the shapes below are the published document's and the
521
+ * behaviours are unmeasured: whether a repeated `name` conflicts, whether client `NO_ACCESS` alongside
522
+ * a project grant is accepted, and what the token's own prefix or length looks like.
523
+ *
524
+ * THE RESPONSE CARRIES A SECRET, so the implementation redacts the server's message from any error it
525
+ * raises. This is the one endpoint whose error envelope could quote a token value back.
526
+ */
527
+ createIntegrationToken(input: {
528
+ clientId: string
529
+ /** The token's label in the Zerops UI. Not a secret and not unique as far as any document says. */
530
+ name: string
531
+ /** Per-project grants. `ADMIN` is what a control plane needs on a project it deploys into. */
532
+ projects: readonly { projectId: string; roleCode: ZeropsRoleCode }[]
533
+ /** The client-wide role. Defaults to `NO_ACCESS`, which is the entire point of a scoped token. */
534
+ roleCode?: ZeropsRoleCode
535
+ /** Let the token create projects, which it then OWNS. Required to provision app namespaces (ADR-0034). */
536
+ canCreateProjects?: boolean
537
+ signal: AbortSignal
538
+ }): Promise<ZeropsIntegrationToken>
539
+
540
+ // ── logs ──────────────────────────────────────────────────────────────────────
541
+
542
+ /** A short-lived grant for the project's log service. VERIFIED: `GET /project/{id}/log`. */
543
+ getLogAccess(input: { projectId: string; signal: AbortSignal }): Promise<ZeropsLogAccess>
544
+
545
+ /**
546
+ * One window of the project's log, narrowed to ONE app version.
547
+ *
548
+ * VERIFIED 2026-08-21 by measurement, not by document: the OpenAPI file stops at the grant, so the
549
+ * separate log service was read against a live project. `urlPlain` answers one
550
+ * `<RFC3339 timestamp> <tag> <message>` line per record and accepts `serviceStackId`, `limit`, `tags`
551
+ * and `desc`; `from` and unknown terms are accepted and silently ignored, so nothing may depend on them.
552
+ *
553
+ * ORDERING, also measured: `limit=N` without `desc` returns the NEWEST N records in ASCENDING timestamp
554
+ * order (`limit=3` against a log starting 15:50 answered 17:00:00, 17:00:00, 17:15:00), and `desc=1`
555
+ * returns the same newest N, newest first. So `desc` is needed neither for the `since` cut nor for a
556
+ * build longer than the limit: each poll re-reads the newest window and the caller's dedupe streams it.
557
+ *
558
+ * A version's BUILD lines carry the tag `zbuilder@<appVersionId>` and are produced on a separate
559
+ * builder stack, so they are selected by `tags` ALONE — combining that tag with the runtime
560
+ * `serviceStackId` matches nothing. RUNTIME lines carry no version marker at all and the runtime
561
+ * service's window mixes every version that ever ran, so they are selected by `serviceStackId` and cut
562
+ * at `since` (the version's `build.pipelineStart`). Without `since` no runtime line is read: a line
563
+ * from an earlier version is worse in a run log than a missing one. The cut is by TIME, not identity —
564
+ * the outgoing container keeps logging until it is replaced, so its lines stamped after `since` still
565
+ * pass, and only the earlier version's older history is excluded.
566
+ *
567
+ * The two windows are read INDEPENDENTLY: one failing must not discard what the other returned, and only
568
+ * a failure of every window attempted is raised. The driver then treats that as non-fatal anyway — log
569
+ * relay degrades to "no lines" and the deploy succeeds or fails on `/app-version` status alone. A log
570
+ * service must never be able to fail a deploy.
571
+ */
572
+ readBuildLog(input: {
573
+ access: ZeropsLogAccess
574
+ serviceId: string
575
+ /** Select this version's build lines by their `zbuilder@` tag; without it no build line is read. */
576
+ appVersionId?: string
577
+ /** RFC3339 lower bound for runtime lines, normally `build.pipelineStart`; without it none are read. */
578
+ since?: string
579
+ limit?: number
580
+ signal: AbortSignal
581
+ }): Promise<ZeropsLogLine[]>
582
+ }
583
+
584
+ /**
585
+ * Just enough of `fetch` for this client — narrower than `typeof fetch` so a test can supply a plain
586
+ * function without also implementing the runtime's extras (`preconnect`).
587
+ */
588
+ export type FetchLike = (
589
+ input: string,
590
+ init?: { method?: string; headers?: Record<string, string>; body?: string; signal?: AbortSignal },
591
+ ) => Promise<Response>
592
+
593
+ /** How the real client is built. `fetchImpl` exists so a test can drive the REAL client offline. */
594
+ export interface ZeropsApiOptions {
595
+ /** Zerops personal access token. Sent as `Authorization: Bearer`. NEVER logged. */
596
+ token: string
597
+ /** Override for a different region's API host. */
598
+ baseUrl?: string
599
+ fetchImpl?: FetchLike
600
+ /** How the user-data writes wait for their platform process. Tests pass a sleeper that does not sleep. */
601
+ sleep?: Sleeper
602
+ }