@fabrika/provider-cloudflare 0.8.1 → 0.9.0-dev.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.
- package/package.json +16 -15
- package/src/control.ts +1 -0
- package/types/src/assets.d.ts +8 -0
- package/types/src/authoring.d.ts +17 -0
- package/types/src/bounds.d.ts +65 -0
- package/types/src/checkout.d.ts +7 -0
- package/types/src/cli-args.d.ts +25 -0
- package/types/src/cli.d.ts +2 -0
- package/types/src/codec.d.ts +8 -0
- package/types/src/collaborators.d.ts +52 -0
- package/types/src/command.d.ts +49 -0
- package/types/src/config-schema.d.ts +9 -0
- package/types/src/control.d.ts +464 -0
- package/types/src/index.d.ts +18 -0
- package/types/src/installation/cloudflare.d.ts +40 -0
- package/types/src/installation/envfile.d.ts +39 -0
- package/types/src/installation/index.d.ts +2 -0
- package/types/src/installation/init-options.d.ts +59 -0
- package/types/src/installation/init.d.ts +114 -0
- package/types/src/installation/installation.d.ts +2 -0
- package/types/src/installation/scaffold.d.ts +39 -0
- package/types/src/plan.d.ts +20 -0
- package/types/src/provider.d.ts +56 -0
- package/types/src/proxy-worker.d.ts +14 -0
- package/types/src/proxy.d.ts +51 -0
- package/types/src/runner-protocol.d.ts +110 -0
- package/types/src/schema.d.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/provider-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-dev.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,27 +12,28 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"src",
|
|
15
|
-
"!src/**/__tests__/**"
|
|
15
|
+
"!src/**/__tests__/**",
|
|
16
|
+
"types"
|
|
16
17
|
],
|
|
17
18
|
"exports": {
|
|
18
19
|
".": {
|
|
19
20
|
"bun": "./src/index.ts",
|
|
20
|
-
"types": "./src/index.ts",
|
|
21
|
+
"types": "./types/src/index.d.ts",
|
|
21
22
|
"default": "./src/index.ts"
|
|
22
23
|
},
|
|
23
24
|
"./cli": {
|
|
24
25
|
"bun": "./src/cli.ts",
|
|
25
|
-
"types": "./src/cli.ts",
|
|
26
|
+
"types": "./types/src/cli.d.ts",
|
|
26
27
|
"default": "./src/cli.ts"
|
|
27
28
|
},
|
|
28
29
|
"./runner": {
|
|
29
30
|
"bun": "./src/control.ts",
|
|
30
|
-
"types": "./src/control.ts",
|
|
31
|
+
"types": "./types/src/control.d.ts",
|
|
31
32
|
"default": "./src/control.ts"
|
|
32
33
|
},
|
|
33
34
|
"./installation": {
|
|
34
35
|
"bun": "./src/installation/index.ts",
|
|
35
|
-
"types": "./src/installation/index.ts",
|
|
36
|
+
"types": "./types/src/installation/index.d.ts",
|
|
36
37
|
"default": "./src/installation/index.ts"
|
|
37
38
|
}
|
|
38
39
|
},
|
|
@@ -42,15 +43,15 @@
|
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
45
|
"zod": "^3.25.76",
|
|
45
|
-
"@fabrika/app": "0.
|
|
46
|
-
"@fabrika/auth": "0.
|
|
47
|
-
"@fabrika/auth-core": "0.
|
|
48
|
-
"@fabrika/check": "0.
|
|
49
|
-
"@fabrika/email": "0.
|
|
50
|
-
"@fabrika/iam-contract": "0.
|
|
51
|
-
"@fabrika/installation-init": "0.
|
|
52
|
-
"@fabrika/proxy-core": "0.
|
|
53
|
-
"@fabrika/provider-contract": "0.
|
|
46
|
+
"@fabrika/app": "0.9.0-dev.2",
|
|
47
|
+
"@fabrika/auth": "0.9.0-dev.2",
|
|
48
|
+
"@fabrika/auth-core": "0.9.0-dev.2",
|
|
49
|
+
"@fabrika/check": "0.9.0-dev.2",
|
|
50
|
+
"@fabrika/email": "0.9.0-dev.2",
|
|
51
|
+
"@fabrika/iam-contract": "0.9.0-dev.2",
|
|
52
|
+
"@fabrika/installation-init": "0.9.0-dev.2",
|
|
53
|
+
"@fabrika/proxy-core": "0.9.0-dev.2",
|
|
54
|
+
"@fabrika/provider-contract": "0.9.0-dev.2",
|
|
54
55
|
"oblaka-iac": "^0.0.18"
|
|
55
56
|
}
|
|
56
57
|
}
|
package/src/control.ts
CHANGED
|
@@ -286,6 +286,7 @@ const runnerApprovedAccess = (environment: ProviderEnvironment): RunnerApprovedA
|
|
|
286
286
|
|
|
287
287
|
const buildJob = async (options: CloudflareControlOptions, input: ProviderDeployInput): Promise<CloudflareRunnerJob> => {
|
|
288
288
|
input.signal.throwIfAborted()
|
|
289
|
+
if (input.environment.kind === 'dev') throw new Error('Cloudflare runs no dev environment (ADR-0049); a dev environment runs on Zerops only')
|
|
289
290
|
assertRegistrationApp(input)
|
|
290
291
|
const storedTarget = decodeEnvelope('target', 'cloudflare', input.environment.target, cloudflareStoredTargetCodec)
|
|
291
292
|
const artifact = decodeEnvelope('artifact', 'cloudflare', input.environment.artifact, cloudflareArtifactCodec)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GeneratedConfig } from 'oblaka-iac';
|
|
2
|
+
/**
|
|
3
|
+
* wrangler `stat`s each asset rather than `lstat`ing it, so a committed symlink to `/proc/self/environ`
|
|
4
|
+
* (the deploy's own environment holds the account token) or to `.git/config` uploads publicly. Call this
|
|
5
|
+
* per `wrangler deploy` spawn, for the config that spawn reads: the checkout's own build step runs between
|
|
6
|
+
* `open()` and the deploy, so that spawn is the only moment the tree is final.
|
|
7
|
+
*/
|
|
8
|
+
export declare const assertLiteralAssets: (generated: GeneratedConfig, configDir: string) => Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AppConfigBase, type ProviderAuthoredApp } from '@fabrika/provider-contract';
|
|
2
|
+
import type { Worker } from 'oblaka-iac';
|
|
3
|
+
/** Inputs used to materialize one environment's Cloudflare resource graph. */
|
|
4
|
+
export interface ResourceContext {
|
|
5
|
+
readonly env: string;
|
|
6
|
+
readonly domain?: string;
|
|
7
|
+
}
|
|
8
|
+
/** A Cloudflare app config loaded from `fabrika.config.ts` inside the runner checkout. */
|
|
9
|
+
export interface CloudflareAppConfigInput extends AppConfigBase {
|
|
10
|
+
/** The application Worker. The deployer builds the proxy Worker in front of it from the contract (ADR-0048); never return one. */
|
|
11
|
+
readonly resources: (ctx: ResourceContext) => Worker;
|
|
12
|
+
}
|
|
13
|
+
export type CloudflareAppConfig = CloudflareAppConfigInput & ProviderAuthoredApp<'cloudflare'>;
|
|
14
|
+
/** Preserve literal inference while validating the provider's required app id. */
|
|
15
|
+
export declare function defineApp(config: CloudflareAppConfigInput): CloudflareAppConfig;
|
|
16
|
+
/** Narrow an imported module default without trusting code from the checkout. */
|
|
17
|
+
export declare const isCloudflareAppConfig: (value: unknown) => value is CloudflareAppConfig;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type AppEnvironment } from '@fabrika/auth-core';
|
|
2
|
+
import type { GeneratedConfig, Worker } from 'oblaka-iac';
|
|
3
|
+
/** What a deployment may claim on the account. The generated wrangler configs are checked against it. */
|
|
4
|
+
export interface DeploymentBounds {
|
|
5
|
+
/** The environment oblaka provisions into. Every remote name is `${env}-${name}`. */
|
|
6
|
+
readonly env: string;
|
|
7
|
+
/** The one hostname this environment may route; a route on any other host belongs to another app. */
|
|
8
|
+
readonly domain?: string;
|
|
9
|
+
/** The directory a generated config's relative `path` is resolved against: the deploy's worker directory. */
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
/** Fabrika deploying its own components is the one caller allowed to name a platform resource. */
|
|
12
|
+
readonly platformResources: 'refuse' | 'allow';
|
|
13
|
+
/** The IAM application id `<app>@<env>` of the deployment. */
|
|
14
|
+
readonly iamAppId: string;
|
|
15
|
+
/** Every Cloudflare deployment of the installation in Control's registry; their names are refused. Empty outside a run. */
|
|
16
|
+
readonly installation: readonly AppEnvironment[];
|
|
17
|
+
/** The remote name of the proxy Worker the deployer built, or null when it built none. */
|
|
18
|
+
readonly proxy: string | null;
|
|
19
|
+
/**
|
|
20
|
+
* The service binding the deployer wrote for each connector import (`FABRIKA_CONNECT_<IMPORT>`), by binding name, to
|
|
21
|
+
* the remote name of the owner's proxy Worker. These are the only bindings to another application's Worker.
|
|
22
|
+
*/
|
|
23
|
+
readonly connectors: Readonly<Record<string, string>>;
|
|
24
|
+
/**
|
|
25
|
+
* The value of every framework variable the platform wrote into each Worker; a generated config must carry exactly
|
|
26
|
+
* these. `proxy` is null when the deployer built no proxy.
|
|
27
|
+
*/
|
|
28
|
+
readonly frameworkVariables: {
|
|
29
|
+
readonly application: Readonly<Record<string, string>>;
|
|
30
|
+
readonly proxy: Readonly<Record<string, string>> | null;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The framework variables among a Worker's `vars`, as the deployer wrote them. */
|
|
34
|
+
export declare const frameworkValues: (vars: Readonly<Record<string, unknown>> | undefined) => Record<string, string>;
|
|
35
|
+
/** One resource oblaka would apply: the name it was declared under, the remote name it adopts, and its generated id. */
|
|
36
|
+
export interface GeneratedResource {
|
|
37
|
+
readonly kind: string;
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly remote: string;
|
|
40
|
+
readonly id: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface ConfigGeneration {
|
|
43
|
+
readonly configs: readonly GeneratedConfig[];
|
|
44
|
+
readonly resources: readonly GeneratedResource[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generate the wrangler configs of a graph with oblaka's own processor, before any Cloudflare call: every resource is
|
|
48
|
+
* applied in dry-run mode with a client that refuses to authenticate, and nothing is written to disk.
|
|
49
|
+
*/
|
|
50
|
+
export declare const generateWranglerConfigs: (definition: Worker, env: string) => Promise<ConfigGeneration>;
|
|
51
|
+
/**
|
|
52
|
+
* Check the wrangler configs oblaka generated — what `wrangler deploy` reads, whatever objects emitted them — before
|
|
53
|
+
* provisioning and again before the deploy. Only the proxy Worker the deployer built is routed; every other config is
|
|
54
|
+
* an application Worker, and there is exactly one of those.
|
|
55
|
+
*/
|
|
56
|
+
export declare const assertGeneratedConfigs: (configs: readonly GeneratedConfig[], bounds: DeploymentBounds) => void;
|
|
57
|
+
/**
|
|
58
|
+
* The generation run's checks: every generated config, every resource oblaka would apply by the remote name it adopts
|
|
59
|
+
* (a KV namespace's config carries only its id), and every id-bound binding against the ids the run handed out.
|
|
60
|
+
*/
|
|
61
|
+
export declare const assertGeneration: (generation: ConfigGeneration, bounds: DeploymentBounds) => void;
|
|
62
|
+
/** The KV namespace oblaka keeps deploy state in is the ONE name it uses verbatim (`KVStateStorage`): no env prefix. */
|
|
63
|
+
export declare const assertStateNamespace: (stateNamespace: string, platformResources: "refuse" | "allow") => void;
|
|
64
|
+
/** The `assets.directory` of a generated config, relative to the config's own directory, once it has been bounded. */
|
|
65
|
+
export declare const assetDirectory: (generated: GeneratedConfig) => string | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Worker } from 'oblaka-iac';
|
|
2
|
+
/**
|
|
3
|
+
* Rebuild the Worker graph a checkout's config returned out of this package's own `Worker` class, so oblaka's
|
|
4
|
+
* processor and the deployer see one class whichever `oblaka-iac` the checkout installed. Every option is carried
|
|
5
|
+
* over as it is; the generated configs are what is checked. Other bindings stay the checkout's objects.
|
|
6
|
+
*/
|
|
7
|
+
export declare const runnerWorkerGraph: (value: unknown, path?: readonly unknown[]) => Worker;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ParsedCloudflareArgs {
|
|
2
|
+
readonly command: string | undefined;
|
|
3
|
+
readonly subcommand: string | undefined;
|
|
4
|
+
readonly env: string | undefined;
|
|
5
|
+
readonly config: string;
|
|
6
|
+
readonly runnerConfig: string | undefined;
|
|
7
|
+
readonly workerConfig: string | undefined;
|
|
8
|
+
/** The single-component form of `platform deploy|plan`: deploy exactly this one platform config. */
|
|
9
|
+
readonly componentConfig: string | undefined;
|
|
10
|
+
readonly managedVarNames: readonly string[];
|
|
11
|
+
readonly dryRun: boolean;
|
|
12
|
+
readonly help: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const parseCloudflareArgs: (argv: readonly string[]) => ParsedCloudflareArgs;
|
|
15
|
+
export interface PlatformComponent {
|
|
16
|
+
readonly label: string;
|
|
17
|
+
readonly configPath: string;
|
|
18
|
+
}
|
|
19
|
+
/** What `platformComponents` needs off a parsed command line. */
|
|
20
|
+
export type PlatformComponentSelection = Pick<ParsedCloudflareArgs, 'runnerConfig' | 'workerConfig' | 'componentConfig'>;
|
|
21
|
+
/**
|
|
22
|
+
* One config (`--component-config`) or the executor-then-control pair, never mixed. Both run with
|
|
23
|
+
* `platformResources: 'allow'`, which is why the single form lives here and not on `app deploy`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const platformComponents: (selection: PlatformComponentSelection) => readonly PlatformComponent[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ProviderCodec } from '@fabrika/provider-contract';
|
|
2
|
+
/** A checkout recipe. The Oblaka graph stays executable code in the referenced config module. */
|
|
3
|
+
export interface CloudflareArtifact {
|
|
4
|
+
readonly configPath: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const cloudflareArtifactCodec: ProviderCodec<CloudflareArtifact>;
|
|
7
|
+
/** Build the default checkout recipe used by the Cloudflare runner. */
|
|
8
|
+
export declare const cloudflareArtifact: (configPath?: string) => CloudflareArtifact;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@fabrika/auth-core';
|
|
2
|
+
import type { SchemaReconciler } from '@fabrika/provider-contract';
|
|
3
|
+
import { type Definition, type DeployResult as OblakaDeployResult } from 'oblaka-iac';
|
|
4
|
+
import { type CloudflareAppConfig } from './authoring';
|
|
5
|
+
import { type RunnerOutcomeFile } from './runner-protocol';
|
|
6
|
+
export interface CommandSpec {
|
|
7
|
+
readonly command: string;
|
|
8
|
+
readonly args: string[];
|
|
9
|
+
readonly cwd: string;
|
|
10
|
+
readonly env?: Record<string, string>;
|
|
11
|
+
/** Names dropped from the INHERITED environment: a child that runs checkout code gets no platform credential. */
|
|
12
|
+
readonly omitEnv?: readonly string[];
|
|
13
|
+
readonly stdin?: string;
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
export interface CommandResult {
|
|
17
|
+
readonly exitCode: number;
|
|
18
|
+
readonly stdout: string;
|
|
19
|
+
readonly stderr: string;
|
|
20
|
+
}
|
|
21
|
+
export type CommandRunner = (spec: CommandSpec) => Promise<CommandResult>;
|
|
22
|
+
export interface ProvisionInput {
|
|
23
|
+
readonly definition: Definition;
|
|
24
|
+
readonly accountId: string;
|
|
25
|
+
readonly apiToken: string;
|
|
26
|
+
readonly env: string;
|
|
27
|
+
readonly cwd: string;
|
|
28
|
+
readonly stateNamespace: string;
|
|
29
|
+
readonly dryRun: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type OblakaProvisioner = (input: ProvisionInput) => Promise<OblakaDeployResult>;
|
|
32
|
+
/** Hand the run's outcome back to the runner, which folds it into the terminal status the control plane reads. */
|
|
33
|
+
export type OutcomeWriter = (outcome: RunnerOutcomeFile) => Promise<void>;
|
|
34
|
+
export interface LoadedCloudflareConfig {
|
|
35
|
+
readonly config: CloudflareAppConfig;
|
|
36
|
+
readonly cwd: string;
|
|
37
|
+
}
|
|
38
|
+
export type CloudflareConfigLoader = (cwd: string, configPath: string) => Promise<LoadedCloudflareConfig>;
|
|
39
|
+
/** The contract an application root declares, or null when it has no `fabrika.contract.ts`. */
|
|
40
|
+
export type ContractReader = (root: string) => Promise<ContractArtifact | null>;
|
|
41
|
+
export interface CloudflareCollaborators {
|
|
42
|
+
readonly loadConfig: CloudflareConfigLoader;
|
|
43
|
+
readonly readContract: ContractReader;
|
|
44
|
+
readonly runCommand: CommandRunner;
|
|
45
|
+
readonly provision: OblakaProvisioner;
|
|
46
|
+
readonly writeOutcome: OutcomeWriter;
|
|
47
|
+
}
|
|
48
|
+
export declare const loadCloudflareConfig: (cwd: string, configPath: string) => Promise<LoadedCloudflareConfig & {
|
|
49
|
+
readonly absolutePath: string;
|
|
50
|
+
}>;
|
|
51
|
+
export declare const defaultCloudflareCollaborators: CloudflareCollaborators;
|
|
52
|
+
export type { SchemaReconciler };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type AppEnvironment } from '@fabrika/auth-core';
|
|
2
|
+
import type { CloudflareAppConfig } from './authoring';
|
|
3
|
+
import { type CloudflareDeployResult, type PlatformIamTarget } from './provider';
|
|
4
|
+
import { type RunnerApprovedAccess } from './runner-protocol';
|
|
5
|
+
/**
|
|
6
|
+
* Decode `FABRIKA_IAM_RETURN_ORIGINS`, the comma-separated set the control plane projects into the
|
|
7
|
+
* deploy environment (ADR-0022). Undefined for an absent or empty value, so a deploy with nothing to
|
|
8
|
+
* project leaves IAM's registry alone rather than clearing it. Part of the executor's environment
|
|
9
|
+
* contract, exported for the test that pins it; not part of the package's public surface.
|
|
10
|
+
*/
|
|
11
|
+
export declare const parseReturnOrigins: (raw: string | undefined) => readonly string[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Decode `FABRIKA_CROSS_ORIGINS`, the environment's cross-origin list as the runner writes it. Undefined when absent or
|
|
14
|
+
* empty; anything malformed fails the deploy, and the proxy manifest's own parser judges each origin.
|
|
15
|
+
*/
|
|
16
|
+
export declare const parseCrossOrigins: (raw: string | undefined) => readonly string[] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Decode `FABRIKA_INSTALLATION_APPS`, the Cloudflare deployments Control registered, as the runner writes it.
|
|
19
|
+
* Undefined when absent; anything malformed fails the deploy rather than dropping the refusal it feeds.
|
|
20
|
+
*/
|
|
21
|
+
export declare const parseInstallationApps: (raw: string | undefined) => readonly AppEnvironment[] | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Read the access Control approved for this run from the file at `FABRIKA_APPROVED_ACCESS_FILE`, as the runner
|
|
24
|
+
* writes it. Undefined when no runner set it (a local deploy); a file that is unreadable or malformed fails the deploy
|
|
25
|
+
* rather than falling back to the checkout.
|
|
26
|
+
*/
|
|
27
|
+
export declare const readApprovedAccess: (path: string | undefined) => Promise<RunnerApprovedAccess | undefined>;
|
|
28
|
+
export interface LoadedCloudflareCommandConfig {
|
|
29
|
+
readonly config: CloudflareAppConfig;
|
|
30
|
+
readonly absolutePath: string;
|
|
31
|
+
readonly cwd: string;
|
|
32
|
+
}
|
|
33
|
+
export declare const loadCloudflareCommandConfig: (configPath: string, cwd: string) => Promise<LoadedCloudflareCommandConfig>;
|
|
34
|
+
export interface CloudflareCommandDeployOptions {
|
|
35
|
+
readonly env: string;
|
|
36
|
+
readonly configPath?: string;
|
|
37
|
+
readonly cwd?: string;
|
|
38
|
+
readonly dryRun?: boolean;
|
|
39
|
+
readonly stateNamespace?: string;
|
|
40
|
+
readonly managedVarNames?: readonly string[];
|
|
41
|
+
/** Defaults to `refuse`: only fabrika deploying its own components may name a platform resource. */
|
|
42
|
+
readonly platformResources?: 'refuse' | 'allow';
|
|
43
|
+
/** Where a platform deploy registers a component's schema (ADR-0058); only the installation sets it. */
|
|
44
|
+
readonly platformIam?: PlatformIamTarget;
|
|
45
|
+
readonly signal?: AbortSignal;
|
|
46
|
+
readonly log?: (line: string) => void;
|
|
47
|
+
}
|
|
48
|
+
/** Deploy one config with the account credentials, declared secrets and vars read from the environment. */
|
|
49
|
+
export declare const deployCloudflareConfig: (options: CloudflareCommandDeployOptions) => Promise<CloudflareDeployResult>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AppSchema } from '@fabrika/auth-core';
|
|
2
|
+
/**
|
|
3
|
+
* A config's IAM schema, parsed and deep-frozen. A config that still declares `gates` is refused: an application is
|
|
4
|
+
* protected by the endpoint table of its `fabrika.contract.ts`, and the platform's own services by theirs.
|
|
5
|
+
*/
|
|
6
|
+
export declare const configSchema: (config: {
|
|
7
|
+
readonly gates?: unknown;
|
|
8
|
+
readonly schema?: unknown;
|
|
9
|
+
}) => AppSchema | null;
|