@fabrika/provider-cloudflare 0.8.2 → 0.9.0-cloudflare.2

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 (45) hide show
  1. package/package.json +16 -15
  2. package/src/bounds.ts +142 -4
  3. package/src/cli.ts +14 -0
  4. package/src/command.ts +8 -4
  5. package/src/contract-support.ts +118 -0
  6. package/src/control.ts +37 -119
  7. package/src/index.ts +1 -1
  8. package/src/installation/init.ts +11 -18
  9. package/src/installation/templates/README.md +21 -4
  10. package/src/installation/templates/platform.yml +6 -0
  11. package/src/managed-secrets.ts +61 -0
  12. package/src/plan.ts +11 -3
  13. package/src/provider.ts +309 -54
  14. package/src/proxy-worker.ts +33 -13
  15. package/src/proxy.ts +48 -16
  16. package/src/runner-protocol.ts +16 -1
  17. package/src/spa-assets.ts +150 -0
  18. package/types/src/assets.d.ts +8 -0
  19. package/types/src/authoring.d.ts +17 -0
  20. package/types/src/bounds.d.ts +81 -0
  21. package/types/src/checkout.d.ts +7 -0
  22. package/types/src/cli-args.d.ts +25 -0
  23. package/types/src/cli.d.ts +8 -0
  24. package/types/src/codec.d.ts +8 -0
  25. package/types/src/collaborators.d.ts +52 -0
  26. package/types/src/command.d.ts +49 -0
  27. package/types/src/config-schema.d.ts +9 -0
  28. package/types/src/contract-support.d.ts +39 -0
  29. package/types/src/control.d.ts +468 -0
  30. package/types/src/index.d.ts +18 -0
  31. package/types/src/installation/cloudflare.d.ts +40 -0
  32. package/types/src/installation/envfile.d.ts +39 -0
  33. package/types/src/installation/index.d.ts +2 -0
  34. package/types/src/installation/init-options.d.ts +59 -0
  35. package/types/src/installation/init.d.ts +114 -0
  36. package/types/src/installation/installation.d.ts +2 -0
  37. package/types/src/installation/scaffold.d.ts +39 -0
  38. package/types/src/managed-secrets.d.ts +19 -0
  39. package/types/src/plan.d.ts +21 -0
  40. package/types/src/provider.d.ts +58 -0
  41. package/types/src/proxy-worker.d.ts +15 -0
  42. package/types/src/proxy.d.ts +72 -0
  43. package/types/src/runner-protocol.d.ts +121 -0
  44. package/types/src/schema.d.ts +17 -0
  45. package/types/src/spa-assets.d.ts +27 -0
@@ -0,0 +1,468 @@
1
+ import { type AppEnvironment } from '@fabrika/auth-core';
2
+ import type { ControlProvider, ProviderCodec, ProviderSource, ProviderSourceBinding, ProviderSourceResolution, ProviderSourceResolutionInput, ProviderTerminalOutcome } from '@fabrika/provider-contract';
3
+ import { z } from 'zod';
4
+ import { type RunnerApprovedAccess, type RunnerIamReconcile } from './runner-protocol';
5
+ export * from './runner-protocol';
6
+ /** Persisted Cloudflare target data. Installation credentials never enter this envelope. */
7
+ export interface CloudflareStoredTarget {
8
+ readonly stateNamespace?: string;
9
+ }
10
+ export declare const cloudflareStoredTargetCodec: ProviderCodec<CloudflareStoredTarget>;
11
+ /** Cloudflare-specific request carried from the control plane to the deploy runner. */
12
+ export interface CloudflareRunnerJob {
13
+ readonly runId: string;
14
+ readonly repoUrl: string;
15
+ readonly ref: string;
16
+ readonly env: string;
17
+ readonly workerDir?: string;
18
+ readonly configPath?: string;
19
+ readonly stateNamespace?: string;
20
+ readonly domain?: string;
21
+ /** The environment's cross-origin list from Control's registry (ADR-0022); the proxy Worker's manifest entry lists it. */
22
+ readonly crossOrigins?: readonly string[];
23
+ /** The origin of the environment's Operations ingest, from Control; the proxy Worker's `connect-src` admits it. */
24
+ readonly operationsOrigin?: string;
25
+ /** `<app>@<env>` of every Cloudflare deployment in Control's registry; the deploy refuses another application's names. */
26
+ readonly installationApps?: readonly string[];
27
+ /** What the deployed proxy enforces and the application starts as; every run but a dry one carries it. */
28
+ readonly approvedAccess?: RunnerApprovedAccess;
29
+ readonly dryRun?: boolean;
30
+ /**
31
+ * Shared secret the runner verifies before it touches D1 or the container; the binding alone proves
32
+ * nothing. Optional in the type because the wire boundary may omit it — the Worker refuses it there.
33
+ */
34
+ readonly runnerKey?: string;
35
+ /** Exactly the Cloudflare account credential. IAM's admin key stays in the control plane (ADR-0022). */
36
+ readonly credentials: {
37
+ readonly CLOUDFLARE_ACCOUNT_ID: string;
38
+ readonly CLOUDFLARE_API_TOKEN: string;
39
+ };
40
+ readonly secrets?: Readonly<Record<string, string>>;
41
+ readonly vars?: Readonly<Record<string, string>>;
42
+ readonly managedEnvironment?: Readonly<Record<string, string>>;
43
+ readonly artifactUpload?: {
44
+ readonly url: string;
45
+ readonly bearer: string;
46
+ readonly appId: string;
47
+ readonly environment: string;
48
+ readonly serviceKey: string;
49
+ readonly release: string;
50
+ readonly runId: string;
51
+ };
52
+ }
53
+ /**
54
+ * The checkout-relative directory a relative `path` names, as the runner resolves it: `''` for the checkout itself
55
+ * (`.`, `./` and no path), empty and `.` segments dropped, or null for an absolute path or one with a `..` segment.
56
+ * The runner executes from this directory and Control reads the run's snapshot there, so both normalize with this.
57
+ */
58
+ export declare const checkoutRelativeDirectory: (path: string | undefined) => string | null;
59
+ /**
60
+ * Validate the Worker-to-runner JSON boundary by VALUE, not only by type: every field here becomes an
61
+ * argv element, a filesystem path or a hostname inside the deploy container.
62
+ */
63
+ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
64
+ runId: z.ZodString;
65
+ repoUrl: z.ZodEffects<z.ZodString, string, string>;
66
+ ref: z.ZodEffects<z.ZodString, string, string>;
67
+ env: z.ZodString;
68
+ credentials: z.ZodObject<{
69
+ CLOUDFLARE_ACCOUNT_ID: z.ZodString;
70
+ CLOUDFLARE_API_TOKEN: z.ZodString;
71
+ }, "strict", z.ZodTypeAny, {
72
+ CLOUDFLARE_ACCOUNT_ID: string;
73
+ CLOUDFLARE_API_TOKEN: string;
74
+ }, {
75
+ CLOUDFLARE_ACCOUNT_ID: string;
76
+ CLOUDFLARE_API_TOKEN: string;
77
+ }>;
78
+ runnerKey: z.ZodOptional<z.ZodString>;
79
+ workerDir: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
80
+ configPath: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
81
+ stateNamespace: z.ZodOptional<z.ZodString>;
82
+ domain: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
83
+ crossOrigins: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
84
+ operationsOrigin: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
85
+ installationApps: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
86
+ approvedAccess: z.ZodOptional<z.ZodEffects<z.ZodObject<{
87
+ kind: z.ZodLiteral<"contract">;
88
+ contract: z.ZodUnknown;
89
+ contractDigest: z.ZodEffects<z.ZodString, string, string>;
90
+ framework: z.ZodOptional<z.ZodString>;
91
+ }, "strict", z.ZodTypeAny, {
92
+ kind: "contract";
93
+ contractDigest: string;
94
+ contract?: unknown;
95
+ framework?: string | undefined;
96
+ }, {
97
+ kind: "contract";
98
+ contractDigest: string;
99
+ contract?: unknown;
100
+ framework?: string | undefined;
101
+ }>, RunnerApprovedAccess, {
102
+ kind: "contract";
103
+ contractDigest: string;
104
+ contract?: unknown;
105
+ framework?: string | undefined;
106
+ }>>;
107
+ dryRun: z.ZodOptional<z.ZodBoolean>;
108
+ secrets: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">, {
109
+ [k: string]: string;
110
+ }, [string, string][]>, {
111
+ [k: string]: string;
112
+ }, unknown>>;
113
+ vars: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">, {
114
+ [k: string]: string;
115
+ }, [string, string][]>, {
116
+ [k: string]: string;
117
+ }, unknown>>;
118
+ managedEnvironment: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>, "many">, {
119
+ [k: string]: string;
120
+ }, [string, string][]>, {
121
+ [k: string]: string;
122
+ }, unknown>>;
123
+ artifactUpload: z.ZodOptional<z.ZodObject<{
124
+ url: z.ZodString;
125
+ bearer: z.ZodString;
126
+ appId: z.ZodString;
127
+ environment: z.ZodString;
128
+ serviceKey: z.ZodString;
129
+ release: z.ZodString;
130
+ runId: z.ZodString;
131
+ }, "strip", z.ZodTypeAny, {
132
+ url: string;
133
+ environment: string;
134
+ release: string;
135
+ appId: string;
136
+ bearer: string;
137
+ runId: string;
138
+ serviceKey: string;
139
+ }, {
140
+ url: string;
141
+ environment: string;
142
+ release: string;
143
+ appId: string;
144
+ bearer: string;
145
+ runId: string;
146
+ serviceKey: string;
147
+ }>>;
148
+ }, "strip", z.ZodTypeAny, {
149
+ env: string;
150
+ ref: string;
151
+ runId: string;
152
+ credentials: {
153
+ CLOUDFLARE_ACCOUNT_ID: string;
154
+ CLOUDFLARE_API_TOKEN: string;
155
+ };
156
+ repoUrl: string;
157
+ vars?: {
158
+ [k: string]: string;
159
+ } | undefined;
160
+ secrets?: {
161
+ [k: string]: string;
162
+ } | undefined;
163
+ operationsOrigin?: string | undefined;
164
+ crossOrigins?: string[] | undefined;
165
+ dryRun?: boolean | undefined;
166
+ domain?: string | undefined;
167
+ installationApps?: string[] | undefined;
168
+ stateNamespace?: string | undefined;
169
+ configPath?: string | undefined;
170
+ runnerKey?: string | undefined;
171
+ workerDir?: string | undefined;
172
+ approvedAccess?: RunnerApprovedAccess | undefined;
173
+ managedEnvironment?: {
174
+ [k: string]: string;
175
+ } | undefined;
176
+ artifactUpload?: {
177
+ url: string;
178
+ environment: string;
179
+ release: string;
180
+ appId: string;
181
+ bearer: string;
182
+ runId: string;
183
+ serviceKey: string;
184
+ } | undefined;
185
+ }, {
186
+ env: string;
187
+ ref: string;
188
+ runId: string;
189
+ credentials: {
190
+ CLOUDFLARE_ACCOUNT_ID: string;
191
+ CLOUDFLARE_API_TOKEN: string;
192
+ };
193
+ repoUrl: string;
194
+ vars?: unknown;
195
+ secrets?: unknown;
196
+ operationsOrigin?: string | undefined;
197
+ crossOrigins?: string[] | undefined;
198
+ dryRun?: boolean | undefined;
199
+ domain?: string | undefined;
200
+ installationApps?: string[] | undefined;
201
+ stateNamespace?: string | undefined;
202
+ configPath?: string | undefined;
203
+ runnerKey?: string | undefined;
204
+ workerDir?: string | undefined;
205
+ approvedAccess?: {
206
+ kind: "contract";
207
+ contractDigest: string;
208
+ contract?: unknown;
209
+ framework?: string | undefined;
210
+ } | undefined;
211
+ managedEnvironment?: unknown;
212
+ artifactUpload?: {
213
+ url: string;
214
+ environment: string;
215
+ release: string;
216
+ appId: string;
217
+ bearer: string;
218
+ runId: string;
219
+ serviceKey: string;
220
+ } | undefined;
221
+ }>, {
222
+ env: string;
223
+ ref: string;
224
+ runId: string;
225
+ credentials: {
226
+ CLOUDFLARE_ACCOUNT_ID: string;
227
+ CLOUDFLARE_API_TOKEN: string;
228
+ };
229
+ repoUrl: string;
230
+ vars?: {
231
+ [k: string]: string;
232
+ } | undefined;
233
+ secrets?: {
234
+ [k: string]: string;
235
+ } | undefined;
236
+ operationsOrigin?: string | undefined;
237
+ crossOrigins?: string[] | undefined;
238
+ dryRun?: boolean | undefined;
239
+ domain?: string | undefined;
240
+ installationApps?: string[] | undefined;
241
+ stateNamespace?: string | undefined;
242
+ configPath?: string | undefined;
243
+ runnerKey?: string | undefined;
244
+ workerDir?: string | undefined;
245
+ approvedAccess?: RunnerApprovedAccess | undefined;
246
+ managedEnvironment?: {
247
+ [k: string]: string;
248
+ } | undefined;
249
+ artifactUpload?: {
250
+ url: string;
251
+ environment: string;
252
+ release: string;
253
+ appId: string;
254
+ bearer: string;
255
+ runId: string;
256
+ serviceKey: string;
257
+ } | undefined;
258
+ }, {
259
+ env: string;
260
+ ref: string;
261
+ runId: string;
262
+ credentials: {
263
+ CLOUDFLARE_ACCOUNT_ID: string;
264
+ CLOUDFLARE_API_TOKEN: string;
265
+ };
266
+ repoUrl: string;
267
+ vars?: unknown;
268
+ secrets?: unknown;
269
+ operationsOrigin?: string | undefined;
270
+ crossOrigins?: string[] | undefined;
271
+ dryRun?: boolean | undefined;
272
+ domain?: string | undefined;
273
+ installationApps?: string[] | undefined;
274
+ stateNamespace?: string | undefined;
275
+ configPath?: string | undefined;
276
+ runnerKey?: string | undefined;
277
+ workerDir?: string | undefined;
278
+ approvedAccess?: {
279
+ kind: "contract";
280
+ contractDigest: string;
281
+ contract?: unknown;
282
+ framework?: string | undefined;
283
+ } | undefined;
284
+ managedEnvironment?: unknown;
285
+ artifactUpload?: {
286
+ url: string;
287
+ environment: string;
288
+ release: string;
289
+ appId: string;
290
+ bearer: string;
291
+ runId: string;
292
+ serviceKey: string;
293
+ } | undefined;
294
+ }>, {
295
+ env: string;
296
+ ref: string;
297
+ runId: string;
298
+ credentials: {
299
+ CLOUDFLARE_ACCOUNT_ID: string;
300
+ CLOUDFLARE_API_TOKEN: string;
301
+ };
302
+ repoUrl: string;
303
+ vars?: {
304
+ [k: string]: string;
305
+ } | undefined;
306
+ secrets?: {
307
+ [k: string]: string;
308
+ } | undefined;
309
+ operationsOrigin?: string | undefined;
310
+ crossOrigins?: string[] | undefined;
311
+ dryRun?: boolean | undefined;
312
+ domain?: string | undefined;
313
+ installationApps?: string[] | undefined;
314
+ stateNamespace?: string | undefined;
315
+ configPath?: string | undefined;
316
+ runnerKey?: string | undefined;
317
+ workerDir?: string | undefined;
318
+ approvedAccess?: RunnerApprovedAccess | undefined;
319
+ managedEnvironment?: {
320
+ [k: string]: string;
321
+ } | undefined;
322
+ artifactUpload?: {
323
+ url: string;
324
+ environment: string;
325
+ release: string;
326
+ appId: string;
327
+ bearer: string;
328
+ runId: string;
329
+ serviceKey: string;
330
+ } | undefined;
331
+ }, {
332
+ env: string;
333
+ ref: string;
334
+ runId: string;
335
+ credentials: {
336
+ CLOUDFLARE_ACCOUNT_ID: string;
337
+ CLOUDFLARE_API_TOKEN: string;
338
+ };
339
+ repoUrl: string;
340
+ vars?: unknown;
341
+ secrets?: unknown;
342
+ operationsOrigin?: string | undefined;
343
+ crossOrigins?: string[] | undefined;
344
+ dryRun?: boolean | undefined;
345
+ domain?: string | undefined;
346
+ installationApps?: string[] | undefined;
347
+ stateNamespace?: string | undefined;
348
+ configPath?: string | undefined;
349
+ runnerKey?: string | undefined;
350
+ workerDir?: string | undefined;
351
+ approvedAccess?: {
352
+ kind: "contract";
353
+ contractDigest: string;
354
+ contract?: unknown;
355
+ framework?: string | undefined;
356
+ } | undefined;
357
+ managedEnvironment?: unknown;
358
+ artifactUpload?: {
359
+ url: string;
360
+ environment: string;
361
+ release: string;
362
+ appId: string;
363
+ bearer: string;
364
+ runId: string;
365
+ serviceKey: string;
366
+ } | undefined;
367
+ }>, {
368
+ env: string;
369
+ ref: string;
370
+ runId: string;
371
+ credentials: {
372
+ CLOUDFLARE_ACCOUNT_ID: string;
373
+ CLOUDFLARE_API_TOKEN: string;
374
+ };
375
+ repoUrl: string;
376
+ vars?: {
377
+ [k: string]: string;
378
+ } | undefined;
379
+ secrets?: {
380
+ [k: string]: string;
381
+ } | undefined;
382
+ operationsOrigin?: string | undefined;
383
+ crossOrigins?: string[] | undefined;
384
+ dryRun?: boolean | undefined;
385
+ domain?: string | undefined;
386
+ installationApps?: string[] | undefined;
387
+ stateNamespace?: string | undefined;
388
+ configPath?: string | undefined;
389
+ runnerKey?: string | undefined;
390
+ workerDir?: string | undefined;
391
+ approvedAccess?: RunnerApprovedAccess | undefined;
392
+ managedEnvironment?: {
393
+ [k: string]: string;
394
+ } | undefined;
395
+ artifactUpload?: {
396
+ url: string;
397
+ environment: string;
398
+ release: string;
399
+ appId: string;
400
+ bearer: string;
401
+ runId: string;
402
+ serviceKey: string;
403
+ } | undefined;
404
+ }, {
405
+ env: string;
406
+ ref: string;
407
+ runId: string;
408
+ credentials: {
409
+ CLOUDFLARE_ACCOUNT_ID: string;
410
+ CLOUDFLARE_API_TOKEN: string;
411
+ };
412
+ repoUrl: string;
413
+ vars?: unknown;
414
+ secrets?: unknown;
415
+ operationsOrigin?: string | undefined;
416
+ crossOrigins?: string[] | undefined;
417
+ dryRun?: boolean | undefined;
418
+ domain?: string | undefined;
419
+ installationApps?: string[] | undefined;
420
+ stateNamespace?: string | undefined;
421
+ configPath?: string | undefined;
422
+ runnerKey?: string | undefined;
423
+ workerDir?: string | undefined;
424
+ approvedAccess?: {
425
+ kind: "contract";
426
+ contractDigest: string;
427
+ contract?: unknown;
428
+ framework?: string | undefined;
429
+ } | undefined;
430
+ managedEnvironment?: unknown;
431
+ artifactUpload?: {
432
+ url: string;
433
+ environment: string;
434
+ release: string;
435
+ appId: string;
436
+ bearer: string;
437
+ runId: string;
438
+ serviceKey: string;
439
+ } | undefined;
440
+ }>;
441
+ export interface CloudflareCloneSource {
442
+ readonly repoUrl: string;
443
+ }
444
+ /** A run's terminal outcome plus what the executor reported: the IAM schema it compiled. */
445
+ export type CloudflareRunOutcome = ProviderTerminalOutcome & {
446
+ readonly iamReconcile?: RunnerIamReconcile;
447
+ readonly dryRun?: boolean;
448
+ };
449
+ /** What the runner reports for a run after a control-plane restart: its persisted outcome, or still in flight. */
450
+ export type CloudflareRunRecovery = CloudflareRunOutcome | {
451
+ readonly state: 'running';
452
+ };
453
+ export interface CloudflareControlOptions {
454
+ readonly accountId: string;
455
+ readonly apiToken: string;
456
+ readonly runnerKey: string;
457
+ /** Every Cloudflare deployment in Control's registry, sent with each job so another application's names are refused. */
458
+ installationApps?(signal: AbortSignal): Promise<readonly AppEnvironment[]>;
459
+ resolveSource(input: ProviderSourceResolutionInput): Promise<ProviderSourceResolution>;
460
+ prepareClone(source: ProviderSource, signal: AbortSignal, sourceBinding?: ProviderSourceBinding): Promise<CloudflareCloneSource>;
461
+ startRun(job: CloudflareRunnerJob): Promise<CloudflareRunOutcome>;
462
+ cancelRun(runId: string): Promise<void>;
463
+ recoverRun?(runId: string): Promise<CloudflareRunRecovery>;
464
+ /** Overridable for tests; the wait between two reads of Control's step boundary. */
465
+ readonly sleep?: (ms: number, signal: AbortSignal) => Promise<void>;
466
+ }
467
+ /** Build the Cloudflare control capability over its runner and source-resolution ports. */
468
+ export declare const createCloudflareControlProvider: (options: CloudflareControlOptions) => ControlProvider;
@@ -0,0 +1,18 @@
1
+ export * from 'oblaka-iac';
2
+ export { type CloudflareAppConfig, type CloudflareAppConfigInput, defineApp, isCloudflareAppConfig, type ResourceContext } from './authoring';
3
+ export { assertGeneratedConfigs, assertGeneration, generateWranglerConfigs } from './bounds';
4
+ export type { ConfigGeneration, DeploymentBounds, GeneratedResource } from './bounds';
5
+ export { parseCloudflareArgs, platformComponents } from './cli-args';
6
+ export type { ParsedCloudflareArgs, PlatformComponent } from './cli-args';
7
+ export { type CloudflareArtifact, cloudflareArtifact, cloudflareArtifactCodec } from './codec';
8
+ export { type CloudflareCollaborators, type CloudflareConfigLoader, type CommandResult, type CommandRunner, type CommandSpec, type ContractReader, defaultCloudflareCollaborators, type LoadedCloudflareConfig, type OblakaProvisioner, type OutcomeWriter, type ProvisionInput, type SchemaReconciler, } from './collaborators';
9
+ export { deployCloudflareConfig, loadCloudflareCommandConfig } from './command';
10
+ export type { CloudflareCommandDeployOptions, LoadedCloudflareCommandConfig } from './command';
11
+ export { cloudflareStoredTargetCodec, createCloudflareControlProvider } from './control';
12
+ export type { CloudflareCloneSource, CloudflareControlOptions, CloudflareRunnerJob, CloudflareStoredTarget } from './control';
13
+ export { buildPlan, findMigratableDatabases, PLATFORM_RESOURCE_NAMES } from './plan';
14
+ export type { CloudflareStep, CloudflareStepKind, MigratableDatabase } from './plan';
15
+ export { type CloudflareDeployerOptions, type CloudflareDeployResult, type CloudflareDeployRun, createCloudflareDeployer } from './provider';
16
+ export { createCloudflareProxyWorker, IAM_APPLICATION_ENTRYPOINT, iamServiceReference, proxyManifestJson } from './proxy';
17
+ export type { CloudflareProxyWorkerOptions } from './proxy';
18
+ export { type AppSchemaParse, parseAppSchema } from './schema';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Cloudflare API helpers for the fabrika CLI — token verification, account resolution, and zone lookup.
3
+ * These run from the operator's machine against the public CF API with the token from the environment;
4
+ * the token VALUE is never logged here (only pass/fail + names).
5
+ *
6
+ * Local schemas validate the consumed fields while tolerating upstream additions.
7
+ */
8
+ /** The CF account picked for this deploy (id + human name, for display). */
9
+ export interface CfAccount {
10
+ id: string;
11
+ name: string;
12
+ }
13
+ /** A resolved CF zone (registrable domain). */
14
+ export interface CfZone {
15
+ id: string;
16
+ name: string;
17
+ }
18
+ /**
19
+ * Best-effort token liveness check → true iff Cloudflare reports the token `active`. Tries the
20
+ * ACCOUNT-scoped endpoint first when an account id is known: an ACCOUNT-OWNED token is NOT visible to
21
+ * `/user/tokens/verify` (which returns "Invalid API Token" for it) — only `/accounts/<id>/tokens/verify`
22
+ * sees it — then falls back to the user endpoint. NEVER throws: a `false` means "couldn't confirm", and
23
+ * the caller decides whether to proceed (the real deploy is the ultimate check).
24
+ */
25
+ export declare function verifyToken(token: string, accountId?: string): Promise<boolean>;
26
+ /** List the accounts the token can act on: `GET /accounts`. */
27
+ export declare function listAccounts(token: string): Promise<CfAccount[]>;
28
+ /**
29
+ * The CF account to deploy into, from the accounts the token lists. An explicit id wins and does not
30
+ * need to be listed — an account-owned token typically cannot list its own account. Without one, the
31
+ * token must act on exactly one account; otherwise the error names them and the flag that picks one.
32
+ */
33
+ export declare function selectAccount(accounts: readonly CfAccount[], accountId: string | undefined): CfAccount;
34
+ /**
35
+ * Best-effort zone lookup for the registrable domain of `hostname`. Naively takes the last two
36
+ * dot-labels (e.g. `fabrika.example.com` → `example.com`) and queries `GET /zones?name=<domain>`.
37
+ * Returns the zone or null. The CLI WARNS on null (a custom-domain bind needs the zone) but never
38
+ * fails on it — the operator may add the zone before the real deploy.
39
+ */
40
+ export declare function findZone(token: string, hostname: string): Promise<CfZone | null>;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Resume support: persist captured secrets to a per-account env file, so an abort (or a crash) at ANY
3
+ * point can be recovered by simply re-running — the second run picks every value back up and SKIPS
4
+ * re-creating the external resources (GitHub App, vault key, provisioning key) that would otherwise be
5
+ * orphaned with their secrets lost.
6
+ *
7
+ * The file is `$XDG_CONFIG_HOME/fabrika/cloudflare/<account>/.env` (0700 directory, 0600 file), NOT
8
+ * `$PWD/.env`: it holds the Cloudflare account token, the vault KEK and IAM's signing key, and the cwd
9
+ * is wherever the operator happened to be — routinely inside an unrelated repository. Living outside
10
+ * every checkout also means Bun no longer auto-loads it, so `openEnvFile` loads it explicitly.
11
+ *
12
+ * Values are encoded so they survive Bun's `.env` loader exactly (see `encodeEnvValue`); `parseEnvFile`
13
+ * is the matching decoder. This module NEVER logs a secret value — only the path and the KEY names.
14
+ */
15
+ /** `$XDG_CONFIG_HOME/fabrika/cloudflare/<account>`, falling back to `~/.config`. */
16
+ export declare function accountEnvDirectory(account: string): string;
17
+ /**
18
+ * Bind this run's env file, creating its 0700 directory, and load what it already holds into
19
+ * `process.env`. A value already present in the environment wins, matching Bun's own loader — which is
20
+ * exactly why a stray `$PWD/.env` is called out: Bun loaded it before this ran, so ITS values outrank
21
+ * the per-account file, and one left over from another account would be reused silently.
22
+ */
23
+ export declare function openEnvFile(account: string): Promise<string>;
24
+ /** The absolute path of the env file being written (non-secret, printed once in the closing summary). */
25
+ export declare function envPath(): string;
26
+ /** Read an env var, returning undefined for unset OR empty. Dynamic access by design (no literal-key lint). */
27
+ export declare function fromEnv(name: string): string | undefined;
28
+ /**
29
+ * Upsert `KEY=value` into the env file (creating it if absent) and reflect it into the live `process.env`
30
+ * so the rest of THIS run sees it too. An existing `KEY=` line (with or without a leading `export`) is
31
+ * replaced in place; otherwise the line is appended. NEVER logs the value.
32
+ */
33
+ export declare function persistEnv(key: string, value: string): Promise<void>;
34
+ /** Persist a related resume bundle with one same-filesystem atomic replacement. */
35
+ export declare function persistEnvBundle(values: Readonly<Record<string, string>>): Promise<void>;
36
+ /** Package-local test seam for the same atomic env-file replacement used in production. */
37
+ export declare function persistEnvBundleAt(path: string, values: Readonly<Record<string, string>>): Promise<void>;
38
+ /** Decode a whole env file written by `encodeEnvValue`. The inverse Bun used to perform for us. */
39
+ export declare function parseEnvFile(contents: string): Record<string, string>;
@@ -0,0 +1,2 @@
1
+ export { runInit } from './init';
2
+ export { cloudflareInstallationCli as installationCli } from './installation';
@@ -0,0 +1,59 @@
1
+ import { type CommandEnv, type InstallationEmail } from '@fabrika/installation-init';
2
+ /**
3
+ * Placeholder OIDC — the client id an operator gets by naming none, to bring the base up BEFORE wiring
4
+ * a real SSO provider. IAM boots, machine auth and the bootstrap-admin hatch work; only human SSO login
5
+ * is inert until a real `FABRIKA_IAM_OIDC_CLIENT_ID`/`_SECRET` replace these. The issuer stays a real
6
+ * discoverable host so IAM's OIDC discovery doesn't fail at boot.
7
+ */
8
+ export declare const PLACEHOLDER_OIDC_CLIENT_ID = "placeholder.apps.googleusercontent.com";
9
+ export declare const PLACEHOLDER_OIDC_CLIENT_SECRET = "placeholder-oidc-client-secret-rotate-when-sso-wired";
10
+ export interface OidcInput {
11
+ readonly issuer: string;
12
+ /** `PLACEHOLDER_OIDC_CLIENT_ID` when the operator deferred real SSO. */
13
+ readonly clientId: string;
14
+ /** Environment only. The placeholder secret pairs with the placeholder client id. */
15
+ readonly clientSecret: string;
16
+ /** Email domains admitted as a human at IAM login (self-provisioning allowlist). */
17
+ readonly humanEmailDomains: readonly string[];
18
+ }
19
+ /** Every input `runInit` takes from the operator. */
20
+ export interface InitInput {
21
+ /** Names the GitHub Environment, the installer env file, the default repository and checkout. */
22
+ readonly account: string;
23
+ /** Absent: the one account the token can act on. */
24
+ readonly accountId?: string;
25
+ /** The Cloudflare account API token. Environment only. */
26
+ readonly apiToken: string;
27
+ readonly repo: string;
28
+ /** The absolute local checkout directory of `repo`. */
29
+ readonly checkout: string;
30
+ readonly hosts: {
31
+ readonly control: string;
32
+ readonly operations: string;
33
+ readonly iam: string;
34
+ };
35
+ /** Absent when OIDC login is not enabled. */
36
+ readonly oidc?: OidcInput;
37
+ readonly passwordEnabled: boolean;
38
+ /** IAM's mail transport; the provider's variables come from the environment only. */
39
+ readonly email: InstallationEmail;
40
+ /** First-admin emails for the escape hatch, admitted to both control and IAM. */
41
+ readonly bootstrapAdmins: readonly string[];
42
+ /** `--yes`: answer every confirmation yes. */
43
+ readonly unattended: boolean;
44
+ }
45
+ /**
46
+ * The account name, after refusing any argument init does not know.
47
+ *
48
+ * Read on its own because the installer env file is named after it, and that file has to be loaded
49
+ * before the rest is parsed: a resumed run reads its earlier answers from it.
50
+ */
51
+ export declare const parseInitAccount: (argv: readonly string[]) => string;
52
+ /**
53
+ * Parse the command's arguments and environment into the one input `runInit` takes.
54
+ *
55
+ * `env` must already hold the installer env file's values (`openEnvFile`), so a resumed run reuses them.
56
+ */
57
+ export declare const parseInitArgs: (argv: readonly string[], env: CommandEnv, cwd?: string) => InitInput;
58
+ /** The command that repeats this run, with every value but the credentials, which stay in the environment. */
59
+ export declare const rerunCommand: (input: InitInput, accountId: string) => string;