@fabrika/auth-core 0.8.1 → 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.
- package/package.json +4 -3
- package/src/contract-canonical.ts +1 -0
- package/src/contract.ts +6 -0
- package/src/dev-environment.ts +45 -0
- package/src/framework-release.ts +2 -0
- package/src/framework-variables.ts +14 -2
- package/src/index.ts +5 -0
- package/src/managed-environment.ts +136 -0
- package/src/ops.ts +497 -0
- package/src/terminal.ts +105 -0
- package/src/token.ts +65 -5
- package/src/types.ts +4 -1
- package/src/wire.ts +6 -0
- package/types/src/app-environment.d.ts +24 -0
- package/types/src/canonical-path.d.ts +20 -0
- package/types/src/contract-canonical.d.ts +19 -0
- package/types/src/contract.d.ts +800 -0
- package/types/src/dev-environment.d.ts +37 -0
- package/types/src/device.d.ts +144 -0
- package/types/src/endpoint-digest.d.ts +58 -0
- package/types/src/endpoints.d.ts +65 -0
- package/types/src/environment.d.ts +58 -0
- package/types/src/framework-release.d.ts +2 -0
- package/types/src/framework-variables.d.ts +86 -0
- package/types/src/index.d.ts +28 -0
- package/types/src/installation-endpoint.d.ts +46 -0
- package/types/src/json.d.ts +13 -0
- package/types/src/locale.d.ts +14 -0
- package/types/src/mail.d.ts +67 -0
- package/types/src/managed-environment.d.ts +32 -0
- package/types/src/membership.d.ts +318 -0
- package/types/src/oauth.d.ts +7 -0
- package/types/src/ops.d.ts +181 -0
- package/types/src/path-segment.d.ts +5 -0
- package/types/src/permissions.d.ts +50 -0
- package/types/src/requirement.d.ts +24 -0
- package/types/src/rpc.d.ts +283 -0
- package/types/src/sha256.d.ts +2 -0
- package/types/src/terminal.d.ts +72 -0
- package/types/src/token.d.ts +240 -0
- package/types/src/types.d.ts +196 -0
- package/types/src/wire.d.ts +65 -0
- package/types/src/workloads.d.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/auth-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-cloudflare.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,12 +12,13 @@
|
|
|
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
|
},
|
|
@@ -74,6 +74,7 @@ export function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifa
|
|
|
74
74
|
...(artifact.mail === undefined ? {} : { mail: artifact.mail }),
|
|
75
75
|
...(artifact.members === undefined ? {} : { members: artifact.members }),
|
|
76
76
|
...(artifact.directory === undefined ? {} : { directory: artifact.directory }),
|
|
77
|
+
...(artifact.terminal === undefined ? {} : { terminal: { identify: artifact.terminal.identify } }),
|
|
77
78
|
...(artifact.procedures === undefined
|
|
78
79
|
? {}
|
|
79
80
|
: {
|
package/src/contract.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { Locale } from './locale'
|
|
5
5
|
import type { MailTemplates } from './mail'
|
|
6
|
+
import type { TerminalArtifact } from './terminal'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The artifact format this release writes. A release that changes the artifact raises it, and Control upcasts every
|
|
@@ -61,6 +62,11 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
61
62
|
readonly members?: { readonly manage: string; readonly list: string }
|
|
62
63
|
/** `labels`: the application's directory shows labels to `members.list` holders. Absent unless declared, so digests stay. */
|
|
63
64
|
readonly directory?: 'labels'
|
|
65
|
+
/**
|
|
66
|
+
* The page on the application's own origin that identifies a person at an enrolled terminal (ADR-0067): IAM sends a
|
|
67
|
+
* terminal's browser there, and only an application that declares it may assert a person. Absent unless declared.
|
|
68
|
+
*/
|
|
69
|
+
readonly terminal?: TerminalArtifact
|
|
64
70
|
/**
|
|
65
71
|
* What each procedure of the staged kit admits and how long it runs, by endpoint id, with every default applied: the
|
|
66
72
|
* rules the application applies itself, beside the row the proxy applies. Absent for a contract with no such
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// What the platform's build hands the launcher of a `dev` environment: a generated file beside the generated entrypoint.
|
|
2
|
+
// The provider writes it, the application's own framework release reads it (ADR-0062: protocol, changed additively).
|
|
3
|
+
|
|
4
|
+
/** Relative to the application root. The build writes it after the checks, so no authored file can stand in for it. */
|
|
5
|
+
export const DEV_LAUNCHER_CONFIG_FILE = 'fabrika/dev.generated.json'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The module whose `runDevLauncher(process.env)` a `dev` environment's `run.start` calls instead of the serving entry.
|
|
9
|
+
* No file is generated for it: the checker allows `process.env` in the generated serving entry only.
|
|
10
|
+
*/
|
|
11
|
+
export const DEV_LAUNCHER_MODULE = '@fabrika/app/dev'
|
|
12
|
+
|
|
13
|
+
/** Where the launcher records what it holds, so a restart of the same container resumes it. A new container has none. */
|
|
14
|
+
export const DEV_LAUNCHER_STATE_FILE = 'fabrika/dev-state.json'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The launcher writes it once its boot reconcile reported, served or failed. A dev container's readiness check passes on
|
|
18
|
+
* it too, so a boot that failed still activates, and `reset_dev` can reach the launcher that reports the failure.
|
|
19
|
+
*/
|
|
20
|
+
export const DEV_LAUNCHER_BOOTED_FILE = 'fabrika/dev-booted'
|
|
21
|
+
|
|
22
|
+
/** One command of the build's check chain, run by the shell in the application root. */
|
|
23
|
+
export interface DevLauncherCheck {
|
|
24
|
+
readonly name: string
|
|
25
|
+
readonly command: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DevLauncherConfig {
|
|
29
|
+
readonly format: 1
|
|
30
|
+
readonly appId: string
|
|
31
|
+
/** The commit the bootstrap run built: what a new container holds before its first sync. */
|
|
32
|
+
readonly head: string
|
|
33
|
+
/** The port the serving entry listens on (`PORT`). */
|
|
34
|
+
readonly port: number
|
|
35
|
+
/** The contract's health endpoint, which says when a respawned application serves. */
|
|
36
|
+
readonly healthPath: string
|
|
37
|
+
/** The serving entry, as an argument vector run in the application root. */
|
|
38
|
+
readonly serve: readonly string[]
|
|
39
|
+
/** `fabrika db migrate`, as an argument vector; it runs only with the provisioning credential. */
|
|
40
|
+
readonly migrate: readonly string[]
|
|
41
|
+
/** The authored SPA commands of the build, each run by the shell when a web source changed. */
|
|
42
|
+
readonly spaBuild: readonly string[]
|
|
43
|
+
/** The build's check chain, which `run_checks` asks for. */
|
|
44
|
+
readonly checks: readonly DevLauncherCheck[]
|
|
45
|
+
}
|
|
@@ -16,6 +16,12 @@ export const FABRIKA_SOURCE_MAP_UPLOAD_KEY = 'FABRIKA_SOURCE_MAP_UPLOAD_KEY'
|
|
|
16
16
|
export const FABRIKA_TOKEN_KEYS = 'FABRIKA_TOKEN_KEYS'
|
|
17
17
|
/** The environment's canonical origin (`https://crm.example`), which `ctx.url` builds absolute links on. */
|
|
18
18
|
export const FABRIKA_APP_ORIGIN = 'FABRIKA_APP_ORIGIN'
|
|
19
|
+
/** The digests of the environment's ops keys, which the object checks Control's key against (`parseOpsKeyDigests`, ADR-0069). */
|
|
20
|
+
export const FABRIKA_OPS_KEY_DIGESTS = 'FABRIKA_OPS_KEY_DIGESTS'
|
|
21
|
+
/** The name of the object that serves an environment's ordinary traffic on Cloudflare; `application` without it. */
|
|
22
|
+
export const FABRIKA_APPLICATION_OBJECT = 'FABRIKA_APPLICATION_OBJECT'
|
|
23
|
+
/** The object names an ops request may target, all in the environment's own namespace (`parseApplicationObjects`). */
|
|
24
|
+
export const FABRIKA_APPLICATION_OBJECTS = 'FABRIKA_APPLICATION_OBJECTS'
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
27
|
* The environment names only the platform writes into an application
|
|
@@ -47,6 +53,9 @@ export const FRAMEWORK_VARIABLE_NAMES = [
|
|
|
47
53
|
FABRIKA_SOURCE_MAP_UPLOAD_KEY,
|
|
48
54
|
FABRIKA_TOKEN_KEYS,
|
|
49
55
|
FABRIKA_APP_ORIGIN,
|
|
56
|
+
FABRIKA_OPS_KEY_DIGESTS,
|
|
57
|
+
FABRIKA_APPLICATION_OBJECT,
|
|
58
|
+
FABRIKA_APPLICATION_OBJECTS,
|
|
50
59
|
] as const
|
|
51
60
|
|
|
52
61
|
export type FrameworkVariableName = (typeof FRAMEWORK_VARIABLE_NAMES)[number]
|
|
@@ -159,8 +168,11 @@ export function frameworkVariableReference(text: string): string | null {
|
|
|
159
168
|
return null
|
|
160
169
|
}
|
|
161
170
|
|
|
162
|
-
/**
|
|
163
|
-
|
|
171
|
+
/**
|
|
172
|
+
* The platform's receivers an application reaches over the platform transport: `mail`, the relay of its jobs' mail, and
|
|
173
|
+
* `source`, which hands the launcher of a `dev` environment the files of the workspace bound to it (ADR-0064).
|
|
174
|
+
*/
|
|
175
|
+
export const PLATFORM_RECEIVERS = ['mail', 'source'] as const
|
|
164
176
|
|
|
165
177
|
export type PlatformReceiver = (typeof PLATFORM_RECEIVERS)[number]
|
|
166
178
|
|
package/src/index.ts
CHANGED
|
@@ -3,21 +3,26 @@ export * from './app-environment'
|
|
|
3
3
|
export * from './canonical-path'
|
|
4
4
|
export * from './contract'
|
|
5
5
|
export * from './contract-canonical'
|
|
6
|
+
export * from './dev-environment'
|
|
6
7
|
export * from './device'
|
|
7
8
|
export * from './endpoint-digest'
|
|
8
9
|
export * from './endpoints'
|
|
9
10
|
export * from './environment'
|
|
11
|
+
export * from './framework-release'
|
|
10
12
|
export * from './framework-variables'
|
|
11
13
|
export * from './installation-endpoint'
|
|
12
14
|
export { parseJsonStringArray } from './json'
|
|
13
15
|
export * from './locale'
|
|
14
16
|
export * from './mail'
|
|
17
|
+
export * from './managed-environment'
|
|
15
18
|
export * from './membership'
|
|
16
19
|
export * from './oauth'
|
|
20
|
+
export * from './ops'
|
|
17
21
|
export * from './permissions'
|
|
18
22
|
export * from './requirement'
|
|
19
23
|
export * from './rpc'
|
|
20
24
|
export { sha256Hex } from './sha256'
|
|
25
|
+
export * from './terminal'
|
|
21
26
|
export * from './token'
|
|
22
27
|
export * from './types'
|
|
23
28
|
export * from './wire'
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { FABRIKA_IAM_APP_ID } from './app-environment'
|
|
2
|
+
import { FABRIKA_CONTRACT_DIGEST } from './endpoint-digest'
|
|
3
|
+
import { FABRIKA_IAM_ISSUER } from './environment'
|
|
4
|
+
import {
|
|
5
|
+
FABRIKA_APP_ORIGIN,
|
|
6
|
+
FABRIKA_OPS_KEY_DIGESTS,
|
|
7
|
+
FABRIKA_TOKEN_KEYS,
|
|
8
|
+
FRAMEWORK_VARIABLE_PREFIXES,
|
|
9
|
+
type FrameworkVariableName,
|
|
10
|
+
isConnectKeyVariable,
|
|
11
|
+
isConnectUrlVariable,
|
|
12
|
+
isEmailTransportVariable,
|
|
13
|
+
isPlatformTransportVariable,
|
|
14
|
+
isWorkloadKeyVariable,
|
|
15
|
+
PLATFORM_RECEIVERS,
|
|
16
|
+
platformTransportVariables,
|
|
17
|
+
} from './framework-variables'
|
|
18
|
+
import { FABRIKA_PROXY_SECRET } from './wire'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The framework names Control hands every deploy, each with a value or `null` (the deploy removes it). Beside them, a
|
|
22
|
+
* deploy carries the families of `FRAMEWORK_VARIABLE_PREFIXES`, one variable per workload, import or receiver.
|
|
23
|
+
*/
|
|
24
|
+
export const MANAGED_VARIABLE_NAMES = [
|
|
25
|
+
'FABRIKA_RELEASE',
|
|
26
|
+
'FABRIKA_OPERATIONS_DSN',
|
|
27
|
+
FABRIKA_IAM_ISSUER,
|
|
28
|
+
FABRIKA_IAM_APP_ID,
|
|
29
|
+
'FABRIKA_APP_ID',
|
|
30
|
+
'FABRIKA_ENVIRONMENT',
|
|
31
|
+
'FABRIKA_SERVICE_KEY',
|
|
32
|
+
FABRIKA_PROXY_SECRET,
|
|
33
|
+
'FABRIKA_IAM_RPC_URL',
|
|
34
|
+
'FABRIKA_IAM_RPC_KEY',
|
|
35
|
+
FABRIKA_APP_ORIGIN,
|
|
36
|
+
FABRIKA_TOKEN_KEYS,
|
|
37
|
+
FABRIKA_OPS_KEY_DIGESTS,
|
|
38
|
+
] as const satisfies readonly FrameworkVariableName[]
|
|
39
|
+
|
|
40
|
+
export type ManagedVariableName = (typeof MANAGED_VARIABLE_NAMES)[number]
|
|
41
|
+
|
|
42
|
+
const MANAGED_VARIABLES: ReadonlySet<string> = new Set(MANAGED_VARIABLE_NAMES)
|
|
43
|
+
|
|
44
|
+
/** The framework names that carry no credential: identities, origins and the release. */
|
|
45
|
+
const PUBLIC_VARIABLES: ReadonlySet<string> = new Set<FrameworkVariableName>([
|
|
46
|
+
'FABRIKA_RELEASE',
|
|
47
|
+
FABRIKA_CONTRACT_DIGEST,
|
|
48
|
+
FABRIKA_IAM_ISSUER,
|
|
49
|
+
FABRIKA_IAM_APP_ID,
|
|
50
|
+
'FABRIKA_APP_ID',
|
|
51
|
+
'FABRIKA_ENVIRONMENT',
|
|
52
|
+
'FABRIKA_IAM_RPC_URL',
|
|
53
|
+
FABRIKA_APP_ORIGIN,
|
|
54
|
+
// SHA-256 of 256-bit random keys: a digest neither is a key nor lets anyone forge one.
|
|
55
|
+
FABRIKA_OPS_KEY_DIGESTS,
|
|
56
|
+
])
|
|
57
|
+
|
|
58
|
+
const PLATFORM_URL_VARIABLES: ReadonlySet<string> = new Set(PLATFORM_RECEIVERS.map((receiver) => platformTransportVariables(receiver).url))
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether a managed variable carries a credential, so a provider writes it as a secret and never reads it back. Fail
|
|
62
|
+
* closed: a name not known to be public is a credential.
|
|
63
|
+
*/
|
|
64
|
+
export function isManagedCredential(name: string): boolean {
|
|
65
|
+
return !PUBLIC_VARIABLES.has(name) && !isConnectUrlVariable(name) && !PLATFORM_URL_VARIABLES.has(name)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Whether a deploy writes `name` from what Control hands it, so a deploy that no longer hands it removes it. */
|
|
69
|
+
export function isManagedVariableName(name: string): boolean {
|
|
70
|
+
return MANAGED_VARIABLES.has(name) || FRAMEWORK_VARIABLE_PREFIXES.some((prefix) => name.length > prefix.length && name.startsWith(prefix))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One managed variable: its value, or `null` when the deploy removes it, and whether it is a credential. */
|
|
74
|
+
export interface ManagedEntry {
|
|
75
|
+
readonly value: string | null
|
|
76
|
+
readonly credential: boolean
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** What Control hands a deploy, parsed once: every name is one Control writes, and every family value has its shape. */
|
|
80
|
+
export type ManagedEnvironment = Readonly<Record<string, ManagedEntry>>
|
|
81
|
+
|
|
82
|
+
const isOrigin = (value: string, schemes: readonly string[]): boolean => {
|
|
83
|
+
try {
|
|
84
|
+
const url = new URL(value)
|
|
85
|
+
return url.origin === value && schemes.includes(url.protocol)
|
|
86
|
+
} catch {
|
|
87
|
+
return false
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const KEY = /^px_./s
|
|
92
|
+
|
|
93
|
+
const isKey = (value: string | null): boolean => value !== null && KEY.test(value)
|
|
94
|
+
|
|
95
|
+
/** The reason a family variable's value is refused, or `null`. Messages name the variable, never its value. */
|
|
96
|
+
const familyProblem = (name: string, value: string | null): string | null => {
|
|
97
|
+
if (isEmailTransportVariable(name)) return value === null || value === '' ? 'must not be empty' : null
|
|
98
|
+
if (PLATFORM_URL_VARIABLES.has(name)) {
|
|
99
|
+
// Control's public origin is http in the local stack (`http://control.fabrika.localhost:18080`).
|
|
100
|
+
return value !== null && isOrigin(value, ['http:', 'https:']) ? null : 'must be an http(s) origin'
|
|
101
|
+
}
|
|
102
|
+
if (isConnectUrlVariable(name)) return value !== null && isOrigin(value, ['https:']) ? null : 'must be an https origin'
|
|
103
|
+
if (isPlatformTransportVariable(name) || isWorkloadKeyVariable(name) || isConnectKeyVariable(name)) {
|
|
104
|
+
return isKey(value) ? null : 'must be a px_ key'
|
|
105
|
+
}
|
|
106
|
+
return 'is not a variable a deploy writes'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Parse what Control hands a deploy. Control parses it before any provider effect, and the Cloudflare executor parses
|
|
111
|
+
* what its job carries; a name or a value Control would not produce fails either.
|
|
112
|
+
*/
|
|
113
|
+
export function parseManagedEnvironment(value: Readonly<Record<string, string | null>>): ManagedEnvironment {
|
|
114
|
+
const parsed: Record<string, ManagedEntry> = {}
|
|
115
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
116
|
+
if (!MANAGED_VARIABLES.has(name)) {
|
|
117
|
+
const problem = familyProblem(name, entry)
|
|
118
|
+
if (problem !== null) throw new Error(`managed environment: ${name} ${problem}`)
|
|
119
|
+
}
|
|
120
|
+
parsed[name] = { value: entry, credential: isManagedCredential(name) }
|
|
121
|
+
}
|
|
122
|
+
return parsed
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The value a deploy writes under `name`, or `null` when it writes none. */
|
|
126
|
+
export function managedValue(environment: ManagedEnvironment, name: string): string | null {
|
|
127
|
+
return environment[name]?.value ?? null
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The managed variables a service or Worker still holds that the deploy no longer writes: handed as `null`, or a
|
|
132
|
+
* family member no longer handed. `written` names what the deploy writes there.
|
|
133
|
+
*/
|
|
134
|
+
export function staleManagedVariables(present: Iterable<string>, written: ReadonlySet<string>): string[] {
|
|
135
|
+
return [...present].filter((name) => isManagedVariableName(name) && !written.has(name))
|
|
136
|
+
}
|