@fabrika/auth-core 0.8.2 → 0.9.0-cloudflare.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 (42) hide show
  1. package/package.json +4 -3
  2. package/src/contract-canonical.ts +1 -0
  3. package/src/contract.ts +6 -0
  4. package/src/dev-environment.ts +45 -0
  5. package/src/framework-release.ts +2 -0
  6. package/src/framework-variables.ts +14 -2
  7. package/src/index.ts +5 -0
  8. package/src/managed-environment.ts +136 -0
  9. package/src/ops.ts +497 -0
  10. package/src/terminal.ts +105 -0
  11. package/src/token.ts +65 -5
  12. package/src/types.ts +4 -1
  13. package/types/src/app-environment.d.ts +24 -0
  14. package/types/src/canonical-path.d.ts +20 -0
  15. package/types/src/contract-canonical.d.ts +19 -0
  16. package/types/src/contract.d.ts +800 -0
  17. package/types/src/dev-environment.d.ts +37 -0
  18. package/types/src/device.d.ts +144 -0
  19. package/types/src/endpoint-digest.d.ts +58 -0
  20. package/types/src/endpoints.d.ts +65 -0
  21. package/types/src/environment.d.ts +58 -0
  22. package/types/src/framework-release.d.ts +2 -0
  23. package/types/src/framework-variables.d.ts +86 -0
  24. package/types/src/index.d.ts +28 -0
  25. package/types/src/installation-endpoint.d.ts +46 -0
  26. package/types/src/json.d.ts +13 -0
  27. package/types/src/locale.d.ts +14 -0
  28. package/types/src/mail.d.ts +67 -0
  29. package/types/src/managed-environment.d.ts +32 -0
  30. package/types/src/membership.d.ts +318 -0
  31. package/types/src/oauth.d.ts +7 -0
  32. package/types/src/ops.d.ts +181 -0
  33. package/types/src/path-segment.d.ts +5 -0
  34. package/types/src/permissions.d.ts +50 -0
  35. package/types/src/requirement.d.ts +24 -0
  36. package/types/src/rpc.d.ts +283 -0
  37. package/types/src/sha256.d.ts +2 -0
  38. package/types/src/terminal.d.ts +72 -0
  39. package/types/src/token.d.ts +240 -0
  40. package/types/src/types.d.ts +196 -0
  41. package/types/src/wire.d.ts +65 -0
  42. package/types/src/workloads.d.ts +25 -0
@@ -0,0 +1,37 @@
1
+ /** Relative to the application root. The build writes it after the checks, so no authored file can stand in for it. */
2
+ export declare const DEV_LAUNCHER_CONFIG_FILE = "fabrika/dev.generated.json";
3
+ /**
4
+ * The module whose `runDevLauncher(process.env)` a `dev` environment's `run.start` calls instead of the serving entry.
5
+ * No file is generated for it: the checker allows `process.env` in the generated serving entry only.
6
+ */
7
+ export declare const DEV_LAUNCHER_MODULE = "@fabrika/app/dev";
8
+ /** Where the launcher records what it holds, so a restart of the same container resumes it. A new container has none. */
9
+ export declare const DEV_LAUNCHER_STATE_FILE = "fabrika/dev-state.json";
10
+ /**
11
+ * The launcher writes it once its boot reconcile reported, served or failed. A dev container's readiness check passes on
12
+ * it too, so a boot that failed still activates, and `reset_dev` can reach the launcher that reports the failure.
13
+ */
14
+ export declare const DEV_LAUNCHER_BOOTED_FILE = "fabrika/dev-booted";
15
+ /** One command of the build's check chain, run by the shell in the application root. */
16
+ export interface DevLauncherCheck {
17
+ readonly name: string;
18
+ readonly command: string;
19
+ }
20
+ export interface DevLauncherConfig {
21
+ readonly format: 1;
22
+ readonly appId: string;
23
+ /** The commit the bootstrap run built: what a new container holds before its first sync. */
24
+ readonly head: string;
25
+ /** The port the serving entry listens on (`PORT`). */
26
+ readonly port: number;
27
+ /** The contract's health endpoint, which says when a respawned application serves. */
28
+ readonly healthPath: string;
29
+ /** The serving entry, as an argument vector run in the application root. */
30
+ readonly serve: readonly string[];
31
+ /** `fabrika db migrate`, as an argument vector; it runs only with the provisioning credential. */
32
+ readonly migrate: readonly string[];
33
+ /** The authored SPA commands of the build, each run by the shell when a web source changed. */
34
+ readonly spaBuild: readonly string[];
35
+ /** The build's check chain, which `run_checks` asks for. */
36
+ readonly checks: readonly DevLauncherCheck[];
37
+ }
@@ -0,0 +1,144 @@
1
+ import type { Scope } from './types';
2
+ export interface StartDeviceAuthorizationInput {
3
+ app: string;
4
+ label: string;
5
+ permissions: string[];
6
+ keyLifetimeSeconds: number;
7
+ redemptionChallenge: string;
8
+ approvalChallenge: string;
9
+ }
10
+ export interface DeviceAuthorizationStarted {
11
+ attemptId: string;
12
+ expiresAt: number;
13
+ pollIntervalSeconds: 3;
14
+ }
15
+ export interface DeviceAuthorizationProof {
16
+ attemptId: string;
17
+ redemptionVerifier: string;
18
+ }
19
+ export interface DeviceAuthorizationConsent {
20
+ consentId: string;
21
+ app: string;
22
+ label: string;
23
+ permissions: string[];
24
+ scope: Scope;
25
+ keyExpiresAt: number;
26
+ }
27
+ export interface DeviceAuthorizationReceipt {
28
+ attemptId: string;
29
+ consent: DeviceAuthorizationConsent;
30
+ credentialId: string;
31
+ principalId: string;
32
+ issuedAt: number;
33
+ revokedAt: number | null;
34
+ }
35
+ export type DeviceAuthorizationTerminalStatus = 'denied' | 'cancelled' | 'expired' | 'authority_lost';
36
+ export type DeviceAuthorizationStatus = {
37
+ status: 'pending';
38
+ expiresAt: number;
39
+ } | {
40
+ status: 'approved';
41
+ consent: DeviceAuthorizationConsent;
42
+ } | {
43
+ status: 'issued';
44
+ receipt: DeviceAuthorizationReceipt;
45
+ } | {
46
+ status: DeviceAuthorizationTerminalStatus;
47
+ };
48
+ export interface ExchangeDeviceAuthorizationInput extends DeviceAuthorizationProof {
49
+ consentId: string;
50
+ }
51
+ export type ExchangeDeviceAuthorizationResult = {
52
+ ok: true;
53
+ token: string;
54
+ receipt: DeviceAuthorizationReceipt;
55
+ } | {
56
+ ok: false;
57
+ reason: 'already_issued';
58
+ receipt: DeviceAuthorizationReceipt;
59
+ } | {
60
+ ok: false;
61
+ reason: 'invalid_attempt' | 'pending' | DeviceAuthorizationTerminalStatus | 'consent_mismatch';
62
+ };
63
+ export interface DeviceAuthorizationCaller {
64
+ app: string;
65
+ credential: string;
66
+ requestId: string;
67
+ }
68
+ export interface InspectDeviceAuthorizationInput extends DeviceAuthorizationCaller {
69
+ attemptId: string;
70
+ approvalVerifier: string;
71
+ }
72
+ export interface DeviceAuthorizationRequest {
73
+ attemptId: string;
74
+ app: string;
75
+ label: string;
76
+ permissions: string[];
77
+ keyLifetimeSeconds: number;
78
+ expiresAt: number;
79
+ }
80
+ export interface ApproveDeviceAuthorizationInput extends InspectDeviceAuthorizationInput {
81
+ scope: Scope;
82
+ }
83
+ export interface ListOwnDeviceAuthorizationsInput extends DeviceAuthorizationCaller {
84
+ before?: string;
85
+ limit?: number;
86
+ }
87
+ export interface DeviceAuthorizationFailure {
88
+ ok: false;
89
+ reason: 'invalid_attempt' | 'not_allowed' | 'invalid_input' | 'expired' | 'conflict' | 'authority_lost';
90
+ }
91
+ export type InspectDeviceAuthorizationResult = {
92
+ ok: true;
93
+ request: DeviceAuthorizationRequest;
94
+ } | DeviceAuthorizationFailure;
95
+ export type ApproveDeviceAuthorizationResult = {
96
+ ok: true;
97
+ consent: DeviceAuthorizationConsent;
98
+ } | DeviceAuthorizationFailure;
99
+ export type DenyDeviceAuthorizationResult = {
100
+ ok: true;
101
+ } | DeviceAuthorizationFailure;
102
+ export type ListOwnDeviceAuthorizationsResult = {
103
+ ok: true;
104
+ items: DeviceAuthorizationReceipt[];
105
+ nextCursor: string | null;
106
+ } | DeviceAuthorizationFailure;
107
+ export type StartDeviceAuthorizationResult = {
108
+ ok: true;
109
+ } & DeviceAuthorizationStarted | {
110
+ ok: false;
111
+ reason: 'invalid_input' | 'not_allowed' | 'rate_limited';
112
+ };
113
+ export type PollDeviceAuthorizationResult = {
114
+ ok: true;
115
+ } & DeviceAuthorizationStatus | {
116
+ ok: false;
117
+ reason: 'invalid_attempt' | 'slow_down';
118
+ };
119
+ export type CancelDeviceAuthorizationResult = {
120
+ ok: true;
121
+ } | {
122
+ ok: false;
123
+ reason: 'invalid_attempt' | 'already_issued';
124
+ };
125
+ export declare function parseStartDeviceAuthorizationInput(value: unknown): StartDeviceAuthorizationInput | null;
126
+ export declare function parseDeviceAuthorizationStarted(value: unknown): DeviceAuthorizationStarted | null;
127
+ export declare function parseDeviceAuthorizationProof(value: unknown): DeviceAuthorizationProof | null;
128
+ export declare function parseExchangeDeviceAuthorizationInput(value: unknown): ExchangeDeviceAuthorizationInput | null;
129
+ export declare function parseDeviceAuthorizationConsent(value: unknown): DeviceAuthorizationConsent | null;
130
+ export declare function parseDeviceAuthorizationReceipt(value: unknown): DeviceAuthorizationReceipt | null;
131
+ export declare function parseDeviceAuthorizationRequest(value: unknown): DeviceAuthorizationRequest | null;
132
+ export declare function parseDeviceAuthorizationCaller(value: unknown): DeviceAuthorizationCaller | null;
133
+ export declare function parseInspectDeviceAuthorizationInput(value: unknown): InspectDeviceAuthorizationInput | null;
134
+ export declare function parseApproveDeviceAuthorizationInput(value: unknown): ApproveDeviceAuthorizationInput | null;
135
+ export declare function parseListOwnDeviceAuthorizationsInput(value: unknown): ListOwnDeviceAuthorizationsInput | null;
136
+ export declare function parseDeviceAuthorizationStatus(value: unknown): DeviceAuthorizationStatus | null;
137
+ export declare function parseExchangeDeviceAuthorizationResult(value: unknown): ExchangeDeviceAuthorizationResult | null;
138
+ export declare function parseStartDeviceAuthorizationResult(value: unknown): StartDeviceAuthorizationResult | null;
139
+ export declare function parsePollDeviceAuthorizationResult(value: unknown): PollDeviceAuthorizationResult | null;
140
+ export declare function parseCancelDeviceAuthorizationResult(value: unknown): CancelDeviceAuthorizationResult | null;
141
+ export declare function parseInspectDeviceAuthorizationResult(value: unknown): InspectDeviceAuthorizationResult | null;
142
+ export declare function parseApproveDeviceAuthorizationResult(value: unknown): ApproveDeviceAuthorizationResult | null;
143
+ export declare function parseDenyDeviceAuthorizationResult(value: unknown): DenyDeviceAuthorizationResult | null;
144
+ export declare function parseListOwnDeviceAuthorizationsResult(value: unknown): ListOwnDeviceAuthorizationsResult | null;
@@ -0,0 +1,58 @@
1
+ import type { ContractArtifact, EndpointRow, ExportDescription } from './contract';
2
+ import type { InstallationEndpointRow, InstallationEndpointTable } from './installation-endpoint';
3
+ /** The variable that carries the digest of the contract a deploy was approved with; the application compares its own. */
4
+ export declare const FABRIKA_CONTRACT_DIGEST = "FABRIKA_CONTRACT_DIGEST";
5
+ /**
6
+ * The variable that carries `installationTableDigest` of the table an installation service's proxy publishes; the
7
+ * service picks its own table by it and refuses to start when it names none.
8
+ */
9
+ export declare const FABRIKA_SERVICE_TABLE_DIGEST = "FABRIKA_SERVICE_TABLE_DIGEST";
10
+ /**
11
+ * What a membership or scope-creating endpoint spends at IAM through a single-use delegation grant (ADR-0022 rule 6):
12
+ * `creates` for an endpoint that creates a value, `members` for one whose action is the `members.manage` action of the
13
+ * dimension its access form names.
14
+ */
15
+ export type EndpointDelegation = 'members' | 'creates';
16
+ /**
17
+ * The fields of an endpoint row the proxy applies, with its delegation. Its digest covers exactly these. An
18
+ * installation row adds its OAuth scopes; an application row has no `oauth` field.
19
+ */
20
+ export type EndpointRules = (Pick<EndpointRow, 'kind' | 'method' | 'path' | 'callers' | 'requirement' | 'admission' | 'crossOrigin' | 'response' | 'cache' | 'authorization'> & {
21
+ readonly delegation: EndpointDelegation | null;
22
+ }) | (Pick<InstallationEndpointRow, 'kind' | 'method' | 'path' | 'callers' | 'requirement' | 'admission' | 'oauth'> & {
23
+ readonly delegation: null;
24
+ });
25
+ /** Whether `value` has the form every digest here has, `sha256:<64 hex digits>`. */
26
+ export declare function isDigest(value: string): boolean;
27
+ /** The one derivation of an endpoint's delegation: the proxy table, the IAM schema and the digest all read it. */
28
+ export declare function endpointDelegation(artifact: Pick<ContractArtifact, 'dimensions'>, row: EndpointRow): EndpointDelegation | null;
29
+ /** The digest of an artifact's endpoint row, its delegation derived from the artifact. */
30
+ export declare function endpointDigest(artifact: Pick<ContractArtifact, 'dimensions'>, row: EndpointRow): string;
31
+ /**
32
+ * The digest of what the proxy applies to an endpoint: its kind, method, path, callers, requirement, admission and
33
+ * delegation, an installation row's OAuth scopes, and an application row's cross-origin form, file-response profile, cache
34
+ * and `Authorization` forwarding.
35
+ * Caller, content-type and scope order carry no meaning, so they do not change it; input and output schemas are not
36
+ * part of it, because the proxy does not apply them.
37
+ */
38
+ export declare function requirementDigest(rules: EndpointRules): string;
39
+ /** The digest of the whole artifact, over its one canonical serialization. */
40
+ export declare function contractDigest(artifact: ContractArtifact): string;
41
+ /**
42
+ * The digest of an installation service's table: each row's id and `requirementDigest`, and the reserved prefixes. A
43
+ * composition writes it beside the service from the table its proxy publishes, so the service refuses to start under
44
+ * another table (ADR-0022 "Installation entries"). Row and prefix order carry no meaning.
45
+ */
46
+ export declare function installationTableDigest(table: InstallationEndpointTable): string;
47
+ /**
48
+ * The digest of an export's description: what a consumer's vendored snapshot and its import name, so a schema that
49
+ * changed under the same version is told apart.
50
+ */
51
+ export declare function exportDigest(description: Omit<ExportDescription, 'digest'>): string;
52
+ /** `X-Fabrika-Endpoint`'s value: the endpoint id the proxy selected and the digest of the rules it applied. */
53
+ export declare function formatEndpointHeader(id: string, digest: string): string;
54
+ /** Read `X-Fabrika-Endpoint`; `null` for anything that is not `<id>@sha256:<hex>`. */
55
+ export declare function parseEndpointHeader(value: string): {
56
+ readonly id: string;
57
+ readonly digest: string;
58
+ } | null;
@@ -0,0 +1,65 @@
1
+ import type { EndpointRow } from './contract';
2
+ import { type InstallationEndpointMethod } from './installation-endpoint';
3
+ type Segment = {
4
+ readonly kind: 'literal';
5
+ readonly value: string;
6
+ } | {
7
+ readonly kind: 'param';
8
+ readonly name: string;
9
+ } | {
10
+ readonly kind: 'wildcard';
11
+ };
12
+ /**
13
+ * What selection reads of a row. The proxy's manifest rows carry these and the rules, not the schemas. Only an
14
+ * installation row may have the method `*`.
15
+ */
16
+ export interface EndpointPattern {
17
+ readonly id: string;
18
+ readonly method: InstallationEndpointMethod;
19
+ readonly path: string;
20
+ }
21
+ /** A table of any rows that carry an endpoint pattern; `EndpointTable` is the artifact's. */
22
+ export interface EndpointPatternTable<Row extends EndpointPattern> {
23
+ readonly endpoints: readonly Row[];
24
+ readonly reservedPrefixes: readonly string[];
25
+ }
26
+ interface CompiledEndpoint<Row extends EndpointPattern> {
27
+ readonly row: Row;
28
+ readonly segments: readonly Segment[];
29
+ }
30
+ /** An endpoint table that `assertNoAmbiguity` accepted, ready for `planEndpoint`. Only `compileEndpointTable` makes one. */
31
+ declare class CompiledEndpointTable<Row extends EndpointPattern = EndpointRow> {
32
+ #private;
33
+ constructor(endpoints: readonly CompiledEndpoint<Row>[], reservedPrefixes: readonly string[]);
34
+ plan(method: string, rawPath: string): EndpointPlan<Row>;
35
+ }
36
+ export type { CompiledEndpointTable };
37
+ /** `no-endpoint` is a 403 at the proxy and a 404 in the framework; `non-canonical` is a 400 at both. */
38
+ export type EndpointPlan<Row extends EndpointPattern = EndpointRow> = {
39
+ readonly outcome: 'non-canonical';
40
+ } | {
41
+ readonly outcome: 'no-endpoint';
42
+ } | {
43
+ readonly outcome: 'endpoint';
44
+ readonly endpoint: Row;
45
+ /** `:name` segments of the selected path, raw and still percent-encoded. */
46
+ readonly params: Readonly<Record<string, string>>;
47
+ };
48
+ export declare class EndpointTableError extends Error {
49
+ readonly name = "EndpointTableError";
50
+ readonly problems: readonly string[];
51
+ constructor(problems: readonly string[]);
52
+ }
53
+ /**
54
+ * Refuse a table in which a request could select an endpoint by accident: an invalid path or reserved prefix, a
55
+ * duplicate id, or two endpoints of one method whose paths have the same shape, which no specificity orders. The
56
+ * method `*` is every method, so it shares a shape with no other endpoint.
57
+ */
58
+ export declare function assertNoAmbiguity<Row extends EndpointPattern>(table: EndpointPatternTable<Row>): void;
59
+ /** Validate a table once, where it is loaded, so that `planEndpoint` never meets an invalid one. */
60
+ export declare function compileEndpointTable<Row extends EndpointPattern = EndpointRow>(table: EndpointPatternTable<Row>): CompiledEndpointTable<Row>;
61
+ /**
62
+ * Select the endpoint for a request: refuse a non-canonical raw path, then take the most specific endpoint of the
63
+ * request's method. Under a reserved prefix only the endpoints declared under it compete. There is no fall-through.
64
+ */
65
+ export declare function planEndpoint<Row extends EndpointPattern>(table: CompiledEndpointTable<Row>, method: string, rawPath: string): EndpointPlan<Row>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The environment NAME, and the one rule that keeps it honest.
3
+ *
4
+ * `local` is not a label. It is the switch every Access-plane bypass is gated on — IAM's
5
+ * `localDevLogin` (`iam/src/services.ts`), its ephemeral signing key (`iam/src/signing.ts`) and its
6
+ * credential-less caller path (`iam/src/auth.ts`) all fire on exactly this string. A live installation
7
+ * carrying it is one added branch away from turning them on, which is what `fabrika-test` was measured
8
+ * doing on 2026-08-05 (backlog 59). So a composition that can SEE it is not local REFUSES the name,
9
+ * on the same reasoning as `readProxyEnv` and `buildOidc`: refusing to boot beats booting
10
+ * misconfigured.
11
+ *
12
+ * What "can see it" means is the whole design, and shared code does not go looking for a signal. The
13
+ * COMPOSITION ROOT states the fact, the way it names the client-address header
14
+ * (`iam/src/client-address.ts`), and the fact it states is the PUBLIC ORIGIN this service serves on.
15
+ * That value is the one thing here that cannot be wrong quietly: it is the `iss` of every minted
16
+ * token, the host a `__Host-` cookie belongs to, and the address a browser is sent back to. A service
17
+ * answering on a public name is not a laptop, whatever `ENVIRONMENT` says — and no local composition
18
+ * in this repository has one (`local-stack/compose.yaml` serves `*.fabrika.localhost`, the Cloudflare
19
+ * local build serves `http://localhost:18191`).
20
+ *
21
+ * Two non-answers are supported and are never a guess: naming NO origin means this composition cannot
22
+ * see its own public address, and an origin that is not a parseable absolute URL is not evidence
23
+ * either — a typo there already breaks sign-in, and turning it into a second, different failure buys
24
+ * nothing.
25
+ */
26
+ /** The environment name every bypass is gated on. Compared literally; there is no other spelling. */
27
+ export declare const LOCAL_ENVIRONMENT = "local";
28
+ /**
29
+ * The ONE name an IAM issuer travels under, from the platform's own configuration to the application
30
+ * that verifies tokens against it ([ADR-0035](../../../docs/decisions/0035-the-platform-owns-the-application-iam-issuer.md)).
31
+ *
32
+ * PLATFORM-OWNED, which is why it is a constant here rather than a string each reader spells. It is the
33
+ * `iss` of every token, it is identical for every application on an installation, and the control plane
34
+ * is the only thing that knows it — so a deploy delivers it in `managedEnvironment` and an application
35
+ * that declares it for itself is refused rather than quietly pointed somewhere else.
36
+ *
37
+ * It lives in this package because everything that reads or writes it — `@fabrika/auth`, both proxies,
38
+ * `@fabrika/provider-contract` and the control plane — already depends on `@fabrika/auth-core`, and
39
+ * `@fabrika/auth-core` depends on nothing.
40
+ */
41
+ export declare const FABRIKA_IAM_ISSUER = "FABRIKA_IAM_ISSUER";
42
+ export declare class EnvironmentNameError extends Error {
43
+ constructor(publicOrigin: string);
44
+ }
45
+ /**
46
+ * Loopback per RFC 6761 §6.3 — `localhost` and every name under `.localhost` always resolve to the
47
+ * loopback interface — plus the literal loopback addresses. Deliberately nothing else: a LAN address
48
+ * or an internal DNS name is still a name another machine reaches this service at.
49
+ */
50
+ export declare function isLoopbackHost(hostname: string): boolean;
51
+ /**
52
+ * Validate a composition's declared environment name against the public origin it serves on, and
53
+ * return the name. Throws `EnvironmentNameError` only for the one contradiction it can prove.
54
+ *
55
+ * @param declared the raw `ENVIRONMENT` value
56
+ * @param publicOrigin this composition's own public origin, or `undefined` when it has none to state
57
+ */
58
+ export declare function readEnvironmentName(declared: string, publicOrigin: string | undefined): string;
@@ -0,0 +1,2 @@
1
+ /** A framework release as npm publishes it; the only form one may take before it reaches a generated build command. */
2
+ export declare const FRAMEWORK_RELEASE_PATTERN: RegExp;
@@ -0,0 +1,86 @@
1
+ import type { WorkloadKind } from './types';
2
+ /** Where a platform build uploads its source maps: the destination without its bearer, and the asset roots (JSON). */
3
+ export declare const FABRIKA_SOURCE_MAP_UPLOAD = "FABRIKA_SOURCE_MAP_UPLOAD";
4
+ /** The run-scoped bearer of that upload. */
5
+ export declare const FABRIKA_SOURCE_MAP_UPLOAD_KEY = "FABRIKA_SOURCE_MAP_UPLOAD_KEY";
6
+ /**
7
+ * The keys an application environment signs and verifies its signed tokens with: `<kid>:<secret>` entries joined by `,`,
8
+ * the signing key first, then each retired key still verifying. Written only for a contract that declares token purposes.
9
+ */
10
+ export declare const FABRIKA_TOKEN_KEYS = "FABRIKA_TOKEN_KEYS";
11
+ /** The environment's canonical origin (`https://crm.example`), which `ctx.url` builds absolute links on. */
12
+ export declare const FABRIKA_APP_ORIGIN = "FABRIKA_APP_ORIGIN";
13
+ /** The digests of the environment's ops keys, which the object checks Control's key against (`parseOpsKeyDigests`, ADR-0069). */
14
+ export declare const FABRIKA_OPS_KEY_DIGESTS = "FABRIKA_OPS_KEY_DIGESTS";
15
+ /** The name of the object that serves an environment's ordinary traffic on Cloudflare; `application` without it. */
16
+ export declare const FABRIKA_APPLICATION_OBJECT = "FABRIKA_APPLICATION_OBJECT";
17
+ /** The object names an ops request may target, all in the environment's own namespace (`parseApplicationObjects`). */
18
+ export declare const FABRIKA_APPLICATION_OBJECTS = "FABRIKA_APPLICATION_OBJECTS";
19
+ /**
20
+ * The environment names only the platform writes into an application
21
+ * ([ADR-0043](../../../docs/decisions/0043-validate-and-render-one-zerops-descriptor-meaning.md)). Control refuses an
22
+ * application variable or secret under one of them, and so does every provider, for every surface that writes one.
23
+ * A work unit that gives an application a new credential adds its name here.
24
+ */
25
+ export declare const FRAMEWORK_VARIABLE_NAMES: readonly ["FABRIKA_RELEASE", "FABRIKA_CONTRACT_DIGEST", "FABRIKA_IAM_ISSUER", "FABRIKA_IAM_APP_ID", "FABRIKA_OPERATIONS_DSN", "FABRIKA_APP_ID", "FABRIKA_ENVIRONMENT", "FABRIKA_SERVICE_KEY", "FABRIKA_APP_DATABASE_URL", "FABRIKA_APP_RUNTIME_DATABASE_URL", "FABRIKA_APP_DATABASE_CONNECTIONS", "FABRIKA_APP_STORAGE_ENDPOINT", "FABRIKA_APP_STORAGE_BUCKET", "FABRIKA_APP_STORAGE_ACCESS_KEY_ID", "FABRIKA_APP_STORAGE_SECRET_ACCESS_KEY", "FABRIKA_STORAGE_PROVENANCE", "FABRIKA_PROXY_SECRET", "FABRIKA_IAM_RPC_URL", "FABRIKA_IAM_RPC_KEY", "FABRIKA_SOURCE_MAP_UPLOAD", "FABRIKA_SOURCE_MAP_UPLOAD_KEY", "FABRIKA_TOKEN_KEYS", "FABRIKA_APP_ORIGIN", "FABRIKA_OPS_KEY_DIGESTS", "FABRIKA_APPLICATION_OBJECT", "FABRIKA_APPLICATION_OBJECTS"];
26
+ export type FrameworkVariableName = (typeof FRAMEWORK_VARIABLE_NAMES)[number];
27
+ /**
28
+ * The name families only the platform writes: one variable per job, webhook or public procedure, named after it
29
+ * (`workloadKeyVariable`), a connector import's address, key and Worker binding (`connectVariables`), the
30
+ * installation's mail transport (`isEmailTransportVariable`), and a platform receiver's address and key
31
+ * (`platformTransportVariables`). Every name under one is framework-only. A public procedure's family is
32
+ * `FABRIKA_PROCEDURE_`, because `FABRIKA_PUBLIC_*` names an application's public build values.
33
+ */
34
+ export declare const FRAMEWORK_VARIABLE_PREFIXES: readonly ["FABRIKA_JOB_", "FABRIKA_WEBHOOK_", "FABRIKA_PROCEDURE_", "FABRIKA_CONNECT_", "FABRIKA_EMAIL_", "FABRIKA_PLATFORM_"];
35
+ /** Whether only the platform may write `name`. */
36
+ export declare function isFrameworkVariableName(name: string): boolean;
37
+ /** A contract name as one segment of a variable name: `nightlyDigest` → `NIGHTLY_DIGEST`. */
38
+ export declare function variableSegment(name: string): string;
39
+ /** Whether `name` is the variable of a job's, a webhook's or a public procedure's credential, as `workloadKeyVariable` names one. */
40
+ export declare function isWorkloadKeyVariable(name: string): boolean;
41
+ /** The workload kinds an application holds its own key of; an `app` key is a connector's (`connectVariables`). */
42
+ export type OwnWorkloadKind = Exclude<WorkloadKind, 'app'>;
43
+ /**
44
+ * The variable a workload's credential travels under: `FABRIKA_JOB_NIGHTLY_DIGEST_KEY`. A public procedure's endpoint id
45
+ * has dots and may differ from another only by case or `_`, so its readable segment carries the first 8 hex digits of
46
+ * the id's SHA-256 as well: `api.stats.cta` → `FABRIKA_PROCEDURE_API_STATS_CTA_<8 hex>_KEY`.
47
+ */
48
+ export declare function workloadKeyVariable(kind: OwnWorkloadKind, name: string): string;
49
+ /** The variables that carry one connector import, and the Cloudflare service binding that carries its calls. */
50
+ export interface ConnectVariables {
51
+ /** The owner's origin, `https://<owner host>`; on Cloudflare also the URL a binding request carries. */
52
+ readonly url: string;
53
+ /** The consumer's `app` key at the owner. */
54
+ readonly key: string;
55
+ /** The service binding to the owner's proxy Worker. */
56
+ readonly binding: string;
57
+ }
58
+ /** `catalog` → `FABRIKA_CONNECT_CATALOG_URL`, `_KEY` and the binding `FABRIKA_CONNECT_CATALOG`. */
59
+ export declare function connectVariables(importName: string): ConnectVariables;
60
+ /** Whether `name` carries a connector import's key, as `connectVariables` names it. */
61
+ export declare function isConnectKeyVariable(name: string): boolean;
62
+ /** Whether `name` carries a connector import's owner origin, as `connectVariables` names it. */
63
+ export declare function isConnectUrlVariable(name: string): boolean;
64
+ /** Whether `name` belongs to the installation's mail transport, which only Control hands an application. */
65
+ export declare function isEmailTransportVariable(name: string): boolean;
66
+ /**
67
+ * The first reference in `text` to a framework-only variable, or `null`. A value that references one copies a
68
+ * platform credential into a variable the application controls, so every surface that writes authored values refuses
69
+ * it. A reference nested in another is refused too, because its name is only known once Zerops resolves it.
70
+ */
71
+ export declare function frameworkVariableReference(text: string): string | null;
72
+ /**
73
+ * The platform's receivers an application reaches over the platform transport: `mail`, the relay of its jobs' mail, and
74
+ * `source`, which hands the launcher of a `dev` environment the files of the workspace bound to it (ADR-0064).
75
+ */
76
+ export declare const PLATFORM_RECEIVERS: readonly ["mail", "source"];
77
+ export type PlatformReceiver = (typeof PLATFORM_RECEIVERS)[number];
78
+ /** The variables that carry one platform receiver: its base URL, which is public, and the application's key, which is secret. */
79
+ export interface PlatformTransportVariables {
80
+ readonly url: string;
81
+ readonly key: string;
82
+ }
83
+ /** `mail` → `FABRIKA_PLATFORM_MAIL_URL` and `FABRIKA_PLATFORM_MAIL_KEY`. */
84
+ export declare function platformTransportVariables(receiver: PlatformReceiver): PlatformTransportVariables;
85
+ /** Whether `name` carries a platform receiver's URL or key, as `platformTransportVariables` names them. */
86
+ export declare function isPlatformTransportVariable(name: string): boolean;
@@ -0,0 +1,28 @@
1
+ export * from './app-environment';
2
+ export * from './canonical-path';
3
+ export * from './contract';
4
+ export * from './contract-canonical';
5
+ export * from './dev-environment';
6
+ export * from './device';
7
+ export * from './endpoint-digest';
8
+ export * from './endpoints';
9
+ export * from './environment';
10
+ export * from './framework-release';
11
+ export * from './framework-variables';
12
+ export * from './installation-endpoint';
13
+ export { parseJsonStringArray } from './json';
14
+ export * from './locale';
15
+ export * from './mail';
16
+ export * from './managed-environment';
17
+ export * from './membership';
18
+ export * from './oauth';
19
+ export * from './ops';
20
+ export * from './permissions';
21
+ export * from './requirement';
22
+ export * from './rpc';
23
+ export { sha256Hex } from './sha256';
24
+ export * from './terminal';
25
+ export * from './token';
26
+ export * from './types';
27
+ export * from './wire';
28
+ export * from './workloads';
@@ -0,0 +1,46 @@
1
+ import type { BodyAdmission, Caller, EndpointMethod } from './contract';
2
+ /** Any method. The ambiguity check treats it as overlapping every method of the same path shape. */
3
+ export declare const ANY_METHOD = "*";
4
+ export type InstallationEndpointMethod = EndpointMethod | typeof ANY_METHOD;
5
+ /** The caller an OAuth resource token presents. Only an installation row may admit it. */
6
+ export declare const OAUTH_CALLER = "oauth";
7
+ /** Every caller a verified token can present: an application caller, or `oauth`. */
8
+ export type TokenCaller = Caller | typeof OAUTH_CALLER;
9
+ export type InstallationCaller = 'human' | 'machine' | typeof OAUTH_CALLER;
10
+ /** `service` verifies a credential; `protocol` and `health` are anonymous, and `protocol` keeps `Authorization`. */
11
+ export type InstallationEndpointKind = 'service' | 'protocol' | 'health';
12
+ /** The caller kind must be one of the row's callers; no permission is needed. */
13
+ export interface AuthenticatedRequirement {
14
+ readonly kind: 'authenticated';
15
+ }
16
+ /** What a row that admits `oauth` requires of an OAuth resource token: every one of these scopes. */
17
+ export interface OAuthEndpointScopes {
18
+ readonly scopes: readonly string[];
19
+ }
20
+ interface InstallationEndpointBase {
21
+ readonly id: string;
22
+ readonly method: InstallationEndpointMethod;
23
+ /** The same pattern syntax as an application endpoint's path. */
24
+ readonly path: string;
25
+ readonly admission: BodyAdmission | null;
26
+ }
27
+ export interface InstallationCredentialedEndpoint extends InstallationEndpointBase {
28
+ readonly kind: 'service';
29
+ readonly callers: readonly [InstallationCaller, ...InstallationCaller[]];
30
+ readonly requirement: AuthenticatedRequirement;
31
+ /** Present exactly when `callers` holds `oauth`. */
32
+ readonly oauth: OAuthEndpointScopes | null;
33
+ }
34
+ export interface InstallationAnonymousEndpoint extends InstallationEndpointBase {
35
+ readonly kind: 'protocol' | 'health';
36
+ readonly callers: readonly [];
37
+ readonly requirement: null;
38
+ readonly oauth: null;
39
+ }
40
+ export type InstallationEndpointRow = InstallationCredentialedEndpoint | InstallationAnonymousEndpoint;
41
+ /** An installation service's endpoint table: what `planEndpoint` selects from, with the installation forms. */
42
+ export interface InstallationEndpointTable {
43
+ readonly endpoints: readonly InstallationEndpointRow[];
44
+ readonly reservedPrefixes: readonly string[];
45
+ }
46
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Tiny structural readers for untrusted JSON — here, a verified-but-loosely-typed JWT
3
+ * payload (jose returns `JWTPayload`, an index signature of `unknown`). They let `token.ts`
4
+ * narrow claims without `as` casts: read a field, check its runtime type, proceed. Mirrors the
5
+ * worker's own `json.ts`; kept here so the token-claim parser can live in `@fabrika/auth-core`
6
+ * (the contract both the Worker and the SDK must agree on) with no cross-package import.
7
+ */
8
+ /** Read a property off an unknown value (undefined when absent / not an object). */
9
+ export declare function prop(value: unknown, key: string): unknown;
10
+ export declare function stringField(value: unknown, key: string): string | undefined;
11
+ export declare function numberField(value: unknown, key: string): number | undefined;
12
+ /** The string entries of a JSON array; non-string entries are dropped, and malformed or non-array text yields []. */
13
+ export declare function parseJsonStringArray(text: string): string[];
@@ -0,0 +1,14 @@
1
+ /** The languages IAM renders its pages and its own e-mails in. */
2
+ export declare const LOCALES: readonly ["en", "cs"];
3
+ export type Locale = (typeof LOCALES)[number];
4
+ /** IAM's language for a request that names no application, or one that declares none. */
5
+ export declare const DEFAULT_LOCALE: Locale;
6
+ export declare function isLocale(value: unknown): value is Locale;
7
+ /** The longest display name, in code points: it is a page heading and part of an e-mail subject. */
8
+ export declare const MAX_DISPLAY_NAME_LENGTH = 80;
9
+ /**
10
+ * Why `value` cannot be an application's display name, or `null` when it can. It is plain text that IAM escapes, so
11
+ * the rule only keeps it one short line: trimmed, non-empty, bounded, without a control character (an e-mail subject
12
+ * carries it).
13
+ */
14
+ export declare function displayNameProblem(value: string): string | null;
@@ -0,0 +1,67 @@
1
+ import type { Locale } from './locale';
2
+ export declare const MESSAGE_KINDS: readonly ["invitation", "enrollment", "reset"];
3
+ export type MessageKind = (typeof MESSAGE_KINDS)[number];
4
+ /**
5
+ * The placeholders each message fills. `companyLabel` and `message` are empty until an invitation carries them.
6
+ * `appUrl` is the application's address, its first registered return origin: IAM sends a template that names it only
7
+ * while one is registered, and its own wording otherwise.
8
+ */
9
+ export declare const MAIL_PLACEHOLDERS: {
10
+ readonly invitation: readonly ["displayName", "recipient", "inviterLabel", "companyLabel", "message", "actionUrl", "appUrl", "expiry"];
11
+ readonly enrollment: readonly ["displayName", "recipient", "actionUrl", "appUrl", "expiry"];
12
+ readonly reset: readonly ["displayName", "recipient", "actionUrl", "appUrl", "expiry"];
13
+ };
14
+ export type MailPlaceholder<K extends MessageKind> = (typeof MAIL_PLACEHOLDERS)[K][number];
15
+ /** One message in one language: the subject line, the plain-text body and, optionally, the HTML body. */
16
+ export interface MailTemplate {
17
+ readonly subject: string;
18
+ readonly text: string;
19
+ /** A body in the closed HTML subset of `mailHtmlTokens`; absent, IAM builds the HTML part from `text`. */
20
+ readonly html?: string;
21
+ }
22
+ /** The contract's `mail`: the templates it declares, by message and language. A missing one is IAM's default. */
23
+ export type MailTemplates = {
24
+ readonly [K in MessageKind]?: {
25
+ readonly [L in Locale]?: MailTemplate;
26
+ };
27
+ };
28
+ export declare const MAX_MAIL_SUBJECT_LENGTH = 200;
29
+ export declare const MAX_MAIL_TEXT_BYTES: number;
30
+ export declare const MAX_MAIL_HTML_BYTES: number;
31
+ export declare function isMessageKind(value: string): value is MessageKind;
32
+ /** Why `template` cannot be the `kind` message, one line each; empty when it can. */
33
+ export declare function mailTemplateProblems(kind: MessageKind, template: MailTemplate): string[];
34
+ /** The elements an HTML body may use: text structure, a list, a quote and a link. Nothing loads, runs or submits. */
35
+ export declare const MAIL_HTML_ELEMENTS: readonly ["a", "b", "blockquote", "br", "div", "em", "h1", "h2", "h3", "hr", "i", "li", "ol", "p", "span", "strong", "u", "ul"];
36
+ /**
37
+ * One piece of an HTML body: literal text (placeholders included, character references as written), an element that
38
+ * opens (with a link's `href`, verbatim), or one that closes. IAM renders the body from these, never from its source.
39
+ */
40
+ export type MailHtmlToken = {
41
+ readonly kind: 'text';
42
+ readonly text: string;
43
+ } | {
44
+ readonly kind: 'open';
45
+ readonly name: string;
46
+ readonly href: string | null;
47
+ } | {
48
+ readonly kind: 'close';
49
+ readonly name: string;
50
+ };
51
+ interface RefusedHtml {
52
+ readonly ok: false;
53
+ readonly problems: string[];
54
+ }
55
+ /**
56
+ * An HTML body read by a small tokenizer that admits only `MAIL_HTML_ELEMENTS`, in lower case, balanced, with no
57
+ * attribute but a link's double-quoted `href` to `{{actionUrl}}`, `{{appUrl}}` or a `mailto:` address, no comment and
58
+ * no `&` that starts no character reference. So no script, style, form, frame, event handler, image, remote resource
59
+ * or `javascript:`/`data:` URL can be written, and a value IAM inserts is text.
60
+ */
61
+ export declare function mailHtmlTokens(html: string): {
62
+ readonly ok: true;
63
+ readonly tokens: MailHtmlToken[];
64
+ } | RefusedHtml;
65
+ /** `template` with each placeholder replaced by its value; a name without a value becomes empty. */
66
+ export declare function fillMailTemplate(template: string, values: Readonly<Record<string, string>>): string;
67
+ export {};