@pithy-sh/core 0.9.0 → 0.10.0
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/dist/asyncapi/document.d.ts +46 -0
- package/dist/asyncapi/document.d.ts.map +1 -0
- package/dist/asyncapi/document.js +115 -0
- package/dist/capability/capability.d.ts +7 -0
- package/dist/capability/capability.d.ts.map +1 -1
- package/dist/capability/composition.d.ts.map +1 -1
- package/dist/capability/composition.js +5 -1
- package/dist/capability/settings.d.ts +10 -2
- package/dist/capability/settings.d.ts.map +1 -1
- package/dist/capability/settings.js +5 -3
- package/dist/cli/command.d.ts +364 -0
- package/dist/cli/command.d.ts.map +1 -0
- package/dist/cli/command.js +418 -0
- package/dist/cli/commandCatalog.generated.d.ts +2275 -0
- package/dist/cli/commandCatalog.generated.d.ts.map +1 -0
- package/dist/cli/commandCatalog.generated.js +2390 -0
- package/dist/cli/commandFacts.d.ts +164 -0
- package/dist/cli/commandFacts.d.ts.map +1 -0
- package/dist/cli/commandFacts.js +215 -0
- package/dist/controlPlane/error/errors.d.ts.map +1 -1
- package/dist/controlPlane/error/errors.js +4 -3
- package/dist/controlPlane/http/guard.d.ts.map +1 -1
- package/dist/controlPlane/http/guard.js +11 -1
- package/dist/controlPlane/http/routes.d.ts +1 -1
- package/dist/controlPlane/http/routes.d.ts.map +1 -1
- package/dist/controlPlane/http/routes.js +34 -7
- package/dist/createBackend.d.ts +7 -0
- package/dist/createBackend.d.ts.map +1 -1
- package/dist/createBackend.js +34 -4
- package/dist/entitlement/require.js +1 -1
- package/dist/error/cause.d.ts +16 -116
- package/dist/error/cause.d.ts.map +1 -1
- package/dist/error/cause.js +19 -153
- package/dist/error/http.d.ts +40 -0
- package/dist/error/http.d.ts.map +1 -1
- package/dist/error/payload.d.ts +80 -0
- package/dist/error/payload.d.ts.map +1 -1
- package/dist/error/payload.js +26 -0
- package/dist/error/pithyError.d.ts +44 -0
- package/dist/error/pithyError.d.ts.map +1 -1
- package/dist/error/pithyError.js +56 -1
- package/dist/error/unresolved.d.ts +265 -0
- package/dist/error/unresolved.d.ts.map +1 -0
- package/dist/error/unresolved.js +599 -0
- package/dist/error/wire.d.ts +20 -0
- package/dist/error/wire.d.ts.map +1 -0
- package/dist/error/wire.js +19 -0
- package/dist/http/oidcWebhook.d.ts +3 -3
- package/dist/http/oidcWebhook.js +3 -3
- package/dist/http/routeContract.js +1 -1
- package/dist/http/routeSpec.d.ts +66 -0
- package/dist/http/routeSpec.d.ts.map +1 -0
- package/dist/http/routeSpec.js +40 -0
- package/dist/http/sameOrigin.d.ts +1 -1
- package/dist/http/sameOrigin.js +1 -1
- package/dist/http/signedWebhook.d.ts +3 -3
- package/dist/http/signedWebhook.js +3 -3
- package/dist/http/socket.d.ts +52 -0
- package/dist/http/socket.d.ts.map +1 -0
- package/dist/http/socket.js +2 -0
- package/dist/http/subprotocol.d.ts +29 -0
- package/dist/http/subprotocol.d.ts.map +1 -0
- package/dist/http/subprotocol.js +37 -0
- package/dist/http/validation.d.ts +40 -8
- package/dist/http/validation.d.ts.map +1 -1
- package/dist/http/validation.js +25 -1
- package/dist/index.js +2 -2
- package/dist/logger/record.d.ts +23 -0
- package/dist/logger/record.d.ts.map +1 -1
- package/dist/migrations/bookkeeping.d.ts +21 -0
- package/dist/migrations/bookkeeping.d.ts.map +1 -1
- package/dist/migrations/bookkeeping.js +32 -3
- package/dist/migrations/groups.d.ts +140 -0
- package/dist/migrations/groups.d.ts.map +1 -0
- package/dist/migrations/groups.js +191 -0
- package/dist/migrations/migrateStep.d.ts +13 -0
- package/dist/migrations/migrateStep.d.ts.map +1 -0
- package/dist/migrations/migrateStep.js +20 -0
- package/dist/migrations/owner.d.ts +7 -0
- package/dist/migrations/owner.d.ts.map +1 -1
- package/dist/migrations/owner.js +11 -7
- package/dist/migrations/retained.js +2 -2
- package/dist/migrations/runner.d.ts +76 -5
- package/dist/migrations/runner.d.ts.map +1 -1
- package/dist/migrations/runner.js +130 -19
- package/dist/naming/domains.d.ts +17 -0
- package/dist/naming/domains.d.ts.map +1 -1
- package/dist/naming/domains.js +62 -4
- package/dist/naming/environment.d.ts.map +1 -1
- package/dist/naming/environment.js +2 -1
- package/dist/naming/packageName.d.ts +17 -0
- package/dist/naming/packageName.d.ts.map +1 -0
- package/dist/naming/packageName.js +22 -0
- package/dist/naming/provisionScope.d.ts.map +1 -1
- package/dist/naming/provisionScope.js +2 -1
- package/dist/openapi/document.d.ts +106 -0
- package/dist/openapi/document.d.ts.map +1 -0
- package/dist/openapi/document.js +314 -0
- package/dist/openapi/routeGroups.d.ts +8 -0
- package/dist/openapi/routeGroups.d.ts.map +1 -0
- package/dist/openapi/routeGroups.js +23 -0
- package/dist/text/comments.js +66 -4
- package/dist/text/literals.d.ts +43 -0
- package/dist/text/literals.d.ts.map +1 -0
- package/dist/text/literals.js +293 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.d.ts.map +1 -1
- package/dist/version.generated.js +1 -1
- package/dist/workflow/dispatchRoute.d.ts.map +1 -1
- package/dist/workflow/dispatchRoute.js +12 -6
- package/dist/workflow/faults.d.ts.map +1 -1
- package/dist/workflow/faults.js +2 -3
- package/dist/workflow/hostEnv.d.ts +1 -0
- package/dist/workflow/hostEnv.d.ts.map +1 -1
- package/dist/workflow/hostEnv.js +4 -2
- package/dist/workflow/loopback.d.ts.map +1 -1
- package/dist/workflow/loopback.js +2 -1
- package/package.json +3 -3
- package/src/asyncapi/document.ts +164 -0
- package/src/capability/capability.ts +7 -0
- package/src/capability/composition.ts +2 -1
- package/src/capability/settings.ts +19 -2
- package/src/cli/command.ts +865 -0
- package/src/cli/commandCatalog.generated.ts +2533 -0
- package/src/cli/commandFacts.ts +219 -0
- package/src/controlPlane/error/errors.ts +10 -3
- package/src/controlPlane/http/guard.ts +14 -2
- package/src/controlPlane/http/routes.ts +57 -9
- package/src/createBackend.ts +35 -2
- package/src/entitlement/require.ts +1 -1
- package/src/error/cause.ts +18 -181
- package/src/error/payload.ts +59 -0
- package/src/error/pithyError.ts +76 -0
- package/src/error/unresolved.ts +853 -0
- package/src/error/wire.ts +40 -0
- package/src/http/oidcWebhook.ts +3 -3
- package/src/http/routeContract.ts +1 -1
- package/src/http/routeSpec.ts +81 -0
- package/src/http/sameOrigin.ts +1 -1
- package/src/http/signedWebhook.ts +3 -3
- package/src/http/socket.ts +55 -0
- package/src/http/subprotocol.ts +47 -0
- package/src/http/validation.ts +50 -8
- package/src/migrations/bookkeeping.ts +39 -2
- package/src/migrations/groups.ts +295 -0
- package/src/migrations/migrateStep.ts +19 -0
- package/src/migrations/owner.ts +10 -6
- package/src/migrations/retained.ts +2 -2
- package/src/migrations/runner.ts +214 -22
- package/src/naming/domains.ts +75 -16
- package/src/naming/environment.ts +2 -1
- package/src/naming/packageName.ts +20 -0
- package/src/naming/provisionScope.ts +2 -1
- package/src/openapi/document.ts +412 -0
- package/src/openapi/routeGroups.ts +25 -0
- package/src/text/comments.ts +56 -4
- package/src/text/literals.ts +294 -0
- package/src/version.generated.ts +1 -1
- package/src/workflow/dispatchRoute.ts +13 -6
- package/src/workflow/faults.ts +5 -3
- package/src/workflow/hostEnv.ts +9 -1
- package/src/workflow/loopback.ts +2 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* **What the catalog cannot say about a `pithy` command, written down once (#711).**
|
|
6
|
+
*
|
|
7
|
+
* `commandCatalog.generated.ts` is the parser's own account of every command: its arguments, its flags, which
|
|
8
|
+
* are required, which have defaults, which go together. Four facts are not in any parser, and each was the
|
|
9
|
+
* fault behind a line that did not run as written:
|
|
10
|
+
*
|
|
11
|
+
* - **Which commands act on one Worker**, and are refused `input/required` without `--worker` where a project
|
|
12
|
+
* has several. `packages/cli/src/ci/runnableCommands.test.ts` proves every entry by running it in a
|
|
13
|
+
* two-Worker project, and fails on a command that takes `--worker` and is not classified here.
|
|
14
|
+
* - **Which flag's default changes what the command acts on.** `pithy vector provision` with no `--env`
|
|
15
|
+
* provisions `dev`, so a line about staging that leaves it off sends the reader to the wrong environment.
|
|
16
|
+
* - **Which commands destroy something**, and are never a remedy for a smaller fault. `pithy feature destroy`
|
|
17
|
+
* was offered as the fix for one mis-shaped vector index.
|
|
18
|
+
* - **Which flag needs another beside it** that the parser does not enforce: `pithy provision --env` is refused
|
|
19
|
+
* without `--yes`, at run time.
|
|
20
|
+
*
|
|
21
|
+
* `command.ts` builds every command a line names from these and the catalog, and refuses one that breaks them.
|
|
22
|
+
* Nothing here imports anything, so a Worker that names a command pays for two tables and nothing more.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The commands that act on exactly one Worker, and refuse `input/required` without `--worker` when a project
|
|
27
|
+
* has several and the run cannot ask. Every line that names one names the Worker, by its `apps/` directory.
|
|
28
|
+
*/
|
|
29
|
+
export const WORKER_SCOPED = [
|
|
30
|
+
"add",
|
|
31
|
+
"dashboard connect",
|
|
32
|
+
"email provision",
|
|
33
|
+
"media provision",
|
|
34
|
+
"payments provision",
|
|
35
|
+
"storage provision",
|
|
36
|
+
"support provision",
|
|
37
|
+
"testers provision",
|
|
38
|
+
"turnstile deprovision",
|
|
39
|
+
"turnstile provision",
|
|
40
|
+
"ui add",
|
|
41
|
+
"ui sync",
|
|
42
|
+
"vector provision",
|
|
43
|
+
"vector reprocess",
|
|
44
|
+
"vector reset",
|
|
45
|
+
"worker sync",
|
|
46
|
+
] as const;
|
|
47
|
+
|
|
48
|
+
/** A command that acts on one Worker. */
|
|
49
|
+
export type WorkerScopedPath = (typeof WORKER_SCOPED)[number];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The commands that take `--worker` and do not need it: each fans out over every Worker, or falls back to the
|
|
53
|
+
* first that answers, and the flag narrows.
|
|
54
|
+
*/
|
|
55
|
+
export const WORKER_NARROWS = [
|
|
56
|
+
"contract",
|
|
57
|
+
"dashboard disconnect",
|
|
58
|
+
"dashboard revoke-key",
|
|
59
|
+
"dashboard rotate",
|
|
60
|
+
"dashboard status",
|
|
61
|
+
"doctor",
|
|
62
|
+
"env",
|
|
63
|
+
"init",
|
|
64
|
+
"migrate",
|
|
65
|
+
"seed",
|
|
66
|
+
"support deprovision",
|
|
67
|
+
"upgrade",
|
|
68
|
+
] as const;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A command only a person runs, at a terminal, where the Worker is asked for. `pithy remove` refuses every run
|
|
72
|
+
* that cannot ask (`core/person_required`).
|
|
73
|
+
*/
|
|
74
|
+
export const PERSON_ONLY = ["remove"] as const;
|
|
75
|
+
|
|
76
|
+
/** A flag that turns a Worker-scoped command into one that acts on no Worker: `pithy add --list` reads the catalog. */
|
|
77
|
+
export const NO_WORKER_MODES: Readonly<Record<string, readonly string[]>> = { add: ["--list"] };
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* **A flag whose default decides what the command acts on.** Left off a line, the command still runs — on the
|
|
81
|
+
* default, which is rarely the environment the line was about. Every `--env` with a default is one: `dev` for
|
|
82
|
+
* `vector provision`, `migrate` and `testers list`, `staging` for `payments reconcile`. A line names it, always.
|
|
83
|
+
*/
|
|
84
|
+
export const MEANING_FLAGS = ["--env"] as const;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The commands whose `--env` decides nothing until another flag asks it to: `pithy remove` touches no database
|
|
88
|
+
* without `--drop`, and `pithy upgrade` migrates none without `--migrate`. Without that flag a line need not
|
|
89
|
+
* name the environment; with it, it must.
|
|
90
|
+
*/
|
|
91
|
+
export const MEANING_ONLY_WITH = { remove: "--drop", upgrade: "--migrate" } as const;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* **The commands that destroy something, by what they destroy.** None is ever built as a remedy: a line that
|
|
95
|
+
* names one says it is a person's decision and what it deletes (`command.ts`'s `personDecision`), and carries
|
|
96
|
+
* no `fix`. `packages/core/src/cli/command.test.ts` holds every command the catalog has to this list or to
|
|
97
|
+
* {@link NOT_DESTRUCTIVE}, so a new one cannot arrive unexamined.
|
|
98
|
+
*/
|
|
99
|
+
export const DESTRUCTIVE_COMMANDS = {
|
|
100
|
+
"dashboard disconnect": "the environment's dashboard connection and the key it signs with",
|
|
101
|
+
"dashboard revoke-key": "a signing key the dashboard holds",
|
|
102
|
+
"email deprovision": "the email Workers, and with --suppression the suppression database",
|
|
103
|
+
"feature destroy": "the feature's worktree, its branch and every resource it provisioned",
|
|
104
|
+
"media deprovision": "the media Worker, and with --storage its bucket",
|
|
105
|
+
remove: "a capability's wiring",
|
|
106
|
+
"secrets deprovision": "the secrets manager, and with --keys the store's keys",
|
|
107
|
+
"secrets rm": "a stored secret",
|
|
108
|
+
"storage deprovision": "the storage Worker, and with --storage its bucket",
|
|
109
|
+
"support deprovision": "the support Workers, and with --storage its attachments",
|
|
110
|
+
"testers deprovision": "the testers Worker",
|
|
111
|
+
"token revoke": "an API token",
|
|
112
|
+
"turnstile deprovision": "the Turnstile widget, whose sitekey every client embeds",
|
|
113
|
+
"vector reset": "every vector in the index",
|
|
114
|
+
"worker remove": "a Worker's directory",
|
|
115
|
+
} as const;
|
|
116
|
+
|
|
117
|
+
/** A command that destroys something. */
|
|
118
|
+
export type DestructivePath = keyof typeof DESTRUCTIVE_COMMANDS;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* **The flags that make a command destroy something**, on any command that declares them. Each is refused by
|
|
122
|
+
* the builder; a line that needs one is a person's decision.
|
|
123
|
+
*/
|
|
124
|
+
export const DESTRUCTIVE_FLAGS = {
|
|
125
|
+
"--destroy-retained": "a resource kept for recovery",
|
|
126
|
+
"--drop": "a capability's tables",
|
|
127
|
+
"--redo": "the data a seed wrote",
|
|
128
|
+
"--rollback": "the schema a migration group applied",
|
|
129
|
+
} as const;
|
|
130
|
+
|
|
131
|
+
/** A flag that makes a command destroy something. */
|
|
132
|
+
export type DestructiveFlag = keyof typeof DESTRUCTIVE_FLAGS;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The commands whose name reads as destructive and which are not, and why. A command named here is built like
|
|
136
|
+
* any other.
|
|
137
|
+
*/
|
|
138
|
+
export const NOT_DESTRUCTIVE: Readonly<Record<string, string>> = {
|
|
139
|
+
"cloudflare disconnect": "revokes a sign-in and deletes no data, which `cloudflare connect` gives back",
|
|
140
|
+
"docs disconnect": "removes the docs server from an editor's config, which `docs connect` restores",
|
|
141
|
+
"feature prune": "forgets worktrees that are already gone",
|
|
142
|
+
"testers close": "stops a cohort accruing, and keeps its history",
|
|
143
|
+
"testers remove": "takes one tester off a roster, which `testers invite` reverses",
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* **A flag whose value is a person's confirmation**, never written into a line an agent reads: a phrase spelled
|
|
148
|
+
* in a remedy is a confirmation nobody gave. A person's decision names the flag and leaves the phrase to them.
|
|
149
|
+
*/
|
|
150
|
+
export const CONFIRM_FLAGS = ["--confirm", "--confirm-production", "--confirm-reset", "--confirm-rollback"] as const;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* When a command asks for a confirmation: always, when a flag is passed (`when`), or in every environment but the
|
|
154
|
+
* ones it trusts (`unlessEnv`) — `vector reset` asks nothing of `dev`, whose index is a laptop's.
|
|
155
|
+
*/
|
|
156
|
+
export const CONFIRMATIONS: readonly { path: string; when?: string; unlessEnv?: readonly string[]; flag: string }[] = [
|
|
157
|
+
{ path: "vector reset", unlessEnv: ["dev"], flag: "--confirm-reset" },
|
|
158
|
+
{ path: "migrate", when: "--rollback", flag: "--confirm-rollback" },
|
|
159
|
+
{ path: "seed", when: "--redo", flag: "--confirm-reset" },
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* **A flag whose value is a credential**, never written into a line: an error's action reaches logs, a terminal
|
|
164
|
+
* scrollback and a `--json` consumer, none of which should hold a key. A run named again carries the flag's name
|
|
165
|
+
* and leaves its value to whoever passed it.
|
|
166
|
+
*/
|
|
167
|
+
export const CREDENTIAL_FLAGS = [
|
|
168
|
+
"--api-token",
|
|
169
|
+
"--r2-access-key-id",
|
|
170
|
+
"--r2-api-token",
|
|
171
|
+
"--r2-secret-access-key",
|
|
172
|
+
] as const;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The environments every project treats as production. A project can name more in `seed.productionEnvironments`;
|
|
176
|
+
* a builder that has them passes them.
|
|
177
|
+
*/
|
|
178
|
+
export const PRODUCTION_ENVIRONMENTS = ["prod", "production"] as const;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* **What a production run of a command needs from a person**, by command: the confirmation it asks for, or `null`
|
|
182
|
+
* for one that asks none. A production provision or seed is never a remedy — a line names it as a person's
|
|
183
|
+
* decision either way, and names a confirmation only when the command declares it: `testers provision` and
|
|
184
|
+
* `vector provision` take no `--confirm`, and a line that told a person to pass one would be refused.
|
|
185
|
+
*/
|
|
186
|
+
export const PRODUCTION_CONFIRMS = {
|
|
187
|
+
provision: "--confirm",
|
|
188
|
+
seed: "--confirm-production",
|
|
189
|
+
"secrets provision": null,
|
|
190
|
+
"testers provision": null,
|
|
191
|
+
"vector provision": null,
|
|
192
|
+
} as const satisfies Readonly<Record<string, string | null>>;
|
|
193
|
+
|
|
194
|
+
/** A command whose production run is a person's decision. */
|
|
195
|
+
export type ProductionPath = keyof typeof PRODUCTION_CONFIRMS;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* **A command that acts on every environment when its `--env` is left off (#711)**, production among them. `pithy
|
|
199
|
+
* testers provision` with no `--env` provisions every declared environment, so the bare line touches production as
|
|
200
|
+
* surely as `--env prod` does, and is a person's decision for the same reason. Each declares `--env` with no
|
|
201
|
+
* default; `command.test.ts` holds that against the catalog.
|
|
202
|
+
*/
|
|
203
|
+
export const EVERY_ENVIRONMENT_WITHOUT_ENV = ["testers provision"] as const satisfies readonly ProductionPath[];
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* **A command that acts on every environment on every run (#711)**, production among them, with no `--env` to narrow
|
|
207
|
+
* it. `pithy secrets provision` deploys each declared environment's manager and mints its store entries, so every line
|
|
208
|
+
* naming it touches production and is a person's decision — never the fix for one binding, one database or one
|
|
209
|
+
* setting. None declares `--env`; `command.test.ts` holds that against the catalog.
|
|
210
|
+
*/
|
|
211
|
+
export const EVERY_ENVIRONMENT_ALWAYS = ["secrets provision"] as const satisfies readonly ProductionPath[];
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* A flag a command refuses to run without, beside another, that the parser does not enforce. `pithy provision
|
|
215
|
+
* --env <env>` with no `--yes` is refused before it does anything; a dry run needs neither.
|
|
216
|
+
*/
|
|
217
|
+
export const REQUIRED_BESIDE: readonly { path: string; with: string; needs: string; unless: string }[] = [
|
|
218
|
+
{ path: "provision", with: "--env", needs: "--yes", unless: "--dry-run" },
|
|
219
|
+
];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { commandName } from "../../cli/command";
|
|
4
5
|
import { PithyError } from "../../error/pithyError";
|
|
5
6
|
import type { MessageParams } from "../../i18n/catalog";
|
|
6
7
|
|
|
@@ -40,7 +41,9 @@ export class ControlPlaneNotConnectedError extends PithyError {
|
|
|
40
41
|
code: "controlplane/not_connected",
|
|
41
42
|
status: 403,
|
|
42
43
|
message: args.message ?? "No management client is connected to this environment.",
|
|
43
|
-
action:
|
|
44
|
+
action:
|
|
45
|
+
args.action ??
|
|
46
|
+
`Register one for this environment with ${commandName("dashboard connect")}, naming it with --env.`,
|
|
44
47
|
detail: args.detail,
|
|
45
48
|
params: args.params,
|
|
46
49
|
},
|
|
@@ -60,7 +63,9 @@ export class ControlPlaneInvalidCredentialError extends PithyError {
|
|
|
60
63
|
code: "controlplane/invalid_credential",
|
|
61
64
|
status: 401,
|
|
62
65
|
message: args.message ?? "That credential is not valid here.",
|
|
63
|
-
action:
|
|
66
|
+
action:
|
|
67
|
+
args.action ??
|
|
68
|
+
`Rotate the connection's key, or update this environment's connection with ${commandName("dashboard connect")} and its --update flag.`,
|
|
64
69
|
detail: args.detail,
|
|
65
70
|
params: args.params,
|
|
66
71
|
},
|
|
@@ -77,7 +82,9 @@ export class ControlPlaneInsufficientScopeError extends PithyError {
|
|
|
77
82
|
code: "controlplane/insufficient_scope",
|
|
78
83
|
status: 403,
|
|
79
84
|
message: args.message ?? "This connection is not scoped for that operation.",
|
|
80
|
-
action:
|
|
85
|
+
action:
|
|
86
|
+
args.action ??
|
|
87
|
+
`Update this environment's connection with ${commandName("dashboard connect")} and its --update flag, granting the scope this call needs.`,
|
|
81
88
|
detail: args.detail,
|
|
82
89
|
params: args.params,
|
|
83
90
|
},
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import type { MiddlewareHandler } from "hono";
|
|
5
5
|
import type { PithyHonoEnv } from "../../capability/capability";
|
|
6
|
+
import { commandName, remedy } from "../../cli/command";
|
|
7
|
+
import { type AmbientEnv, compositionEnvironment } from "../../env/ambient";
|
|
6
8
|
import { PithyError } from "../../error/pithyError";
|
|
7
9
|
import { workerVersionMetadata } from "../../worker/identity";
|
|
8
10
|
import { ControlPlaneAuditActions, safeEmit } from "../audit/actions";
|
|
@@ -55,7 +57,7 @@ export type ControlPlaneVerifier = (
|
|
|
55
57
|
*/
|
|
56
58
|
export function createControlPlaneVerifier(deps: ControlPlaneVerifyDeps): ControlPlaneVerifier {
|
|
57
59
|
return async (request, requirement) => {
|
|
58
|
-
// Clone before reading. The handler still has to parse this body through `
|
|
60
|
+
// Clone before reading. The handler still has to parse this body through `validate`, and a stream
|
|
59
61
|
// consumed here would reach it empty — the digest check would pass and the request would then fail
|
|
60
62
|
// validation for no visible reason.
|
|
61
63
|
const body = new Uint8Array(await request.clone().arrayBuffer());
|
|
@@ -138,7 +140,7 @@ export function requireControlPlane(requirement: ControlPlaneRequirement): Middl
|
|
|
138
140
|
if (!verify) {
|
|
139
141
|
const denial = new ControlPlaneNotConnectedError({
|
|
140
142
|
message: "This deployment does not accept management-client calls.",
|
|
141
|
-
action:
|
|
143
|
+
action: `Add \`controlplane()\` to this Worker's pithy.config.ts, then ${connectStep(compositionEnvironment(c.env as unknown as AmbientEnv))}.`,
|
|
142
144
|
detail: "no control-plane verifier on the request — the controlplane capability is not composed",
|
|
143
145
|
});
|
|
144
146
|
await auditDenial(c, requirement, denial);
|
|
@@ -221,3 +223,13 @@ async function auditDenial(
|
|
|
221
223
|
c.var.log,
|
|
222
224
|
);
|
|
223
225
|
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The step that connects a management client, as this deployed Worker can name it: with its own environment when
|
|
229
|
+
* it knows it, and never with a Worker — it cannot know the `apps/` directory that provisioned it (#711).
|
|
230
|
+
*/
|
|
231
|
+
function connectStep(env: string | undefined): string {
|
|
232
|
+
if (env === undefined)
|
|
233
|
+
return `connect one with ${commandName("dashboard connect")}, naming this environment with --env`;
|
|
234
|
+
return remedy("dashboard connect", { flags: { "--env": env } }, { runtime: true }).say((command) => `run ${command}`);
|
|
235
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import { zValidator } from "@hono/zod-validator";
|
|
5
4
|
import type { Hono } from "hono";
|
|
6
5
|
import type { PithyHonoEnv } from "../../capability/capability";
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
6
|
+
import { describeRoute } from "../../http/routeSpec";
|
|
7
|
+
import { validate } from "../../http/validation";
|
|
8
|
+
import { type AdminRoute, ControlPlaneManifest } from "../discovery/adminRoute";
|
|
9
9
|
import { ANY_VERIFIED_CALLER, KEYS_ROTATE_SCOPE, MANIFEST_READ_SCOPE } from "../scope/scope";
|
|
10
10
|
import { requireControlPlane } from "./guard";
|
|
11
11
|
import {
|
|
@@ -16,6 +16,12 @@ import {
|
|
|
16
16
|
pingHandler,
|
|
17
17
|
registerKeyHandler,
|
|
18
18
|
} from "./handlers";
|
|
19
|
+
import {
|
|
20
|
+
ControlPlaneKeysResponse,
|
|
21
|
+
ControlPlanePingResponse,
|
|
22
|
+
ExpireKeyResponse,
|
|
23
|
+
RegisterKeyResponse,
|
|
24
|
+
} from "./responses";
|
|
19
25
|
import { ExpireKeyParams, ExpireKeyRequest, RegisterKeyRequest } from "./schemas";
|
|
20
26
|
|
|
21
27
|
/**
|
|
@@ -92,24 +98,66 @@ export function registerControlPlaneRoutes(
|
|
|
92
98
|
basePath: string,
|
|
93
99
|
deps: ControlPlaneHandlerDeps,
|
|
94
100
|
): void {
|
|
95
|
-
app.get(
|
|
101
|
+
app.get(
|
|
102
|
+
`${basePath}/ping`,
|
|
103
|
+
describeRoute({
|
|
104
|
+
summary: "Prove the connection and the key it signs with.",
|
|
105
|
+
verification: "control-plane",
|
|
106
|
+
responses: { 200: ControlPlanePingResponse },
|
|
107
|
+
}),
|
|
108
|
+
requireControlPlane(ANY_VERIFIED_CALLER),
|
|
109
|
+
pingHandler(deps),
|
|
110
|
+
);
|
|
96
111
|
|
|
97
|
-
app.get(
|
|
112
|
+
app.get(
|
|
113
|
+
`${basePath}/manifest`,
|
|
114
|
+
describeRoute({
|
|
115
|
+
summary: "Describe what this Worker composes and how to call its admin surface.",
|
|
116
|
+
verification: "control-plane",
|
|
117
|
+
scopes: [MANIFEST_READ_SCOPE],
|
|
118
|
+
responses: { 200: ControlPlaneManifest },
|
|
119
|
+
}),
|
|
120
|
+
requireControlPlane(MANIFEST_READ_SCOPE),
|
|
121
|
+
manifestHandler(deps),
|
|
122
|
+
);
|
|
98
123
|
|
|
99
|
-
app.get(
|
|
124
|
+
app.get(
|
|
125
|
+
`${basePath}/keys`,
|
|
126
|
+
describeRoute({
|
|
127
|
+
summary: "Read the connection's key registration state.",
|
|
128
|
+
verification: "control-plane",
|
|
129
|
+
scopes: [KEYS_ROTATE_SCOPE],
|
|
130
|
+
responses: { 200: ControlPlaneKeysResponse },
|
|
131
|
+
}),
|
|
132
|
+
requireControlPlane(KEYS_ROTATE_SCOPE),
|
|
133
|
+
listKeysHandler(deps),
|
|
134
|
+
);
|
|
100
135
|
|
|
101
136
|
app.post(
|
|
102
137
|
`${basePath}/keys`,
|
|
138
|
+
describeRoute({
|
|
139
|
+
summary: "Register a key for the connection.",
|
|
140
|
+
verification: "control-plane",
|
|
141
|
+
scopes: [KEYS_ROTATE_SCOPE],
|
|
142
|
+
responses: { 201: RegisterKeyResponse },
|
|
143
|
+
}),
|
|
103
144
|
requireControlPlane(KEYS_ROTATE_SCOPE),
|
|
104
|
-
|
|
145
|
+
validate("json", RegisterKeyRequest),
|
|
105
146
|
(c) => registerKeyHandler(deps)(c, c.req.valid("json")),
|
|
106
147
|
);
|
|
107
148
|
|
|
108
149
|
app.post(
|
|
109
150
|
`${basePath}/keys/:keyId/expire`,
|
|
151
|
+
describeRoute({
|
|
152
|
+
summary: "Retire a superseded key.",
|
|
153
|
+
description: "Must be signed with the successor it names as proven.",
|
|
154
|
+
verification: "control-plane",
|
|
155
|
+
scopes: [KEYS_ROTATE_SCOPE],
|
|
156
|
+
responses: { 200: ExpireKeyResponse },
|
|
157
|
+
}),
|
|
110
158
|
requireControlPlane(KEYS_ROTATE_SCOPE),
|
|
111
|
-
|
|
112
|
-
|
|
159
|
+
validate("param", ExpireKeyParams),
|
|
160
|
+
validate("json", ExpireKeyRequest),
|
|
113
161
|
(c) => expireKeyHandler(deps)(c, c.req.valid("param"), c.req.valid("json")),
|
|
114
162
|
);
|
|
115
163
|
}
|
package/src/createBackend.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { Hono } from "hono";
|
|
5
|
+
import { z } from "zod";
|
|
5
6
|
import { noopEmit } from "./audit/recorder";
|
|
6
7
|
import { BindingSpec } from "./capability/bindings";
|
|
7
8
|
import type {
|
|
@@ -14,17 +15,21 @@ import type {
|
|
|
14
15
|
} from "./capability/capability";
|
|
15
16
|
import { recordComposition } from "./capability/composition";
|
|
16
17
|
import { validateBindings } from "./capability/validateBindings";
|
|
18
|
+
import { pithyCommandOf } from "./cli/command";
|
|
17
19
|
import { isControlPlaneCapability } from "./controlPlane/capability";
|
|
18
20
|
import { allowedOriginSet, corsSurface, registerControlPlaneCors } from "./controlPlane/http/cors";
|
|
19
21
|
import { buildDbRegistry, composeDatabases, type DbRegistry } from "./data/databases";
|
|
20
22
|
import { noEntitlementProvider } from "./entitlement/entitlement";
|
|
21
23
|
import { ValidationError } from "./error/pithyError";
|
|
24
|
+
import { describeRoute } from "./http/routeSpec";
|
|
22
25
|
import { catalogFor, composeMessages } from "./i18n/registry";
|
|
23
26
|
import { bakedTranslator, DEFAULT_LOCALE } from "./i18n/translator";
|
|
24
27
|
import { buildKvRegistry, composeKv, type KvRegistry } from "./kv/namespaces";
|
|
25
28
|
import { loggingErrorHandler } from "./logger/errorHandler";
|
|
26
29
|
import type { Logger } from "./logger/logger";
|
|
27
30
|
import { bindRequestContext, createWorkerLogger } from "./logger/worker";
|
|
31
|
+
import type { RouteGroup } from "./openapi/document";
|
|
32
|
+
import { recordRouteGroups } from "./openapi/routeGroups";
|
|
28
33
|
import { HEALTH_PATH } from "./worker/health";
|
|
29
34
|
import { workerVersion } from "./worker/identity";
|
|
30
35
|
import { registeredWorkflowBinding } from "./workflow/bindings";
|
|
@@ -103,6 +108,18 @@ function envNameOf(env: Record<string, unknown>, fallback: string | undefined):
|
|
|
103
108
|
return typeof env.ENVIRONMENT === "string" && env.ENVIRONMENT.length > 0 ? env.ENVIRONMENT : (fallback ?? "unknown");
|
|
104
109
|
}
|
|
105
110
|
|
|
111
|
+
/** What `GET /health` answers. */
|
|
112
|
+
export const HealthBody = z
|
|
113
|
+
.object({
|
|
114
|
+
status: z.literal("ok").describe("Always `ok`: an answer at all is the liveness signal."),
|
|
115
|
+
version: z
|
|
116
|
+
.string()
|
|
117
|
+
.nullable()
|
|
118
|
+
.describe("The Cloudflare version id of the build answering, or null where the Worker cannot say."),
|
|
119
|
+
})
|
|
120
|
+
.describe("Liveness, and which build is answering.");
|
|
121
|
+
export type HealthBody = z.infer<typeof HealthBody>;
|
|
122
|
+
|
|
106
123
|
/**
|
|
107
124
|
* Assemble capabilities into a deployable Hono app — a valid Worker `fetch` handler.
|
|
108
125
|
*
|
|
@@ -135,7 +152,7 @@ export function createBackend<
|
|
|
135
152
|
if (!present.has(dep)) {
|
|
136
153
|
throw new ValidationError({
|
|
137
154
|
message: `Capability "${cap.name}" requires the "${dep}" capability, which is not composed.`,
|
|
138
|
-
action: `Add ${dep}() to createBackend's capabilities (run
|
|
155
|
+
action: `Add ${dep}() to createBackend's capabilities (run \`${pithyCommandOf("add", { args: [dep], flags: { "--with-prerequisites": true } }, { runtime: true })}\`).`,
|
|
139
156
|
});
|
|
140
157
|
}
|
|
141
158
|
}
|
|
@@ -283,14 +300,30 @@ export function createBackend<
|
|
|
283
300
|
* before `version_metadata` was declared reports "I cannot tell you", and `deploy` reports the check
|
|
284
301
|
* as inconclusive instead of failing it.
|
|
285
302
|
*/
|
|
286
|
-
|
|
303
|
+
const groups: RouteGroup[] = [];
|
|
304
|
+
const healthStart = app.routes.length;
|
|
305
|
+
app.get(
|
|
306
|
+
HEALTH_PATH,
|
|
307
|
+
describeRoute({
|
|
308
|
+
summary: "Report liveness, and which build is answering.",
|
|
309
|
+
verification: "public",
|
|
310
|
+
responses: { 200: HealthBody },
|
|
311
|
+
}),
|
|
312
|
+
(c) => c.json({ status: "ok", version: workerVersion(c.env) } satisfies HealthBody),
|
|
313
|
+
);
|
|
314
|
+
groups.push({ tag: "core", routes: app.routes.slice(healthStart) });
|
|
287
315
|
|
|
288
316
|
for (const cap of all) {
|
|
289
317
|
for (const middleware of cap.middleware ?? []) middleware(app);
|
|
290
318
|
}
|
|
319
|
+
// Each hook's slice of the route table is noted as it mounts, so the OpenAPI contract can tag every
|
|
320
|
+
// operation with the capability that owns it (`openapi/routeGroups.ts`).
|
|
291
321
|
for (const cap of all) {
|
|
322
|
+
const start = app.routes.length;
|
|
292
323
|
cap.routes?.(app);
|
|
324
|
+
groups.push({ tag: cap.name, routes: app.routes.slice(start) });
|
|
293
325
|
}
|
|
326
|
+
recordRouteGroups(app, groups);
|
|
294
327
|
|
|
295
328
|
return app as unknown as Hono<BackendEnv<readonly [...Caps, App]>>;
|
|
296
329
|
}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
* `verification`-strategy sibling every paid route carries: it says what the caller must *hold*, the
|
|
17
17
|
* way `requireAuth()` says who the caller must *be*, and it belongs on the route line beside it.
|
|
18
18
|
*
|
|
19
|
-
* app.get("/reports", requireAuth(), requireEntitlement("pro"),
|
|
19
|
+
* app.get("/reports", requireAuth(), requireEntitlement("pro"), validate(…), handler)
|
|
20
20
|
*
|
|
21
21
|
* It lives in `@pithy-sh/core` rather than in `@pithy-sh/payments` for the same reason `requireAuth()`
|
|
22
22
|
* is copied into each capability instead of imported from `@pithy-sh/auth`: a gate that arrives with a
|