anhedral 0.11.0 → 0.11.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/README.md +50 -170
- package/assets/patches/LICENSE.braces +21 -0
- package/assets/patches/LICENSE.node-forge +50 -0
- package/assets/patches/audit-deps.mjs +167 -0
- package/assets/patches/braces@3.0.3.patch +127 -0
- package/assets/patches/node-forge@1.4.0.patch +41 -0
- package/dist/auth-schema.js +3 -3
- package/dist/bin.js +15 -11
- package/dist/capabilities.d.ts +4 -4
- package/dist/capabilities.js +6 -2
- package/dist/capability-contract.js +22 -5
- package/dist/catalog-model.d.ts +24 -0
- package/dist/catalog-model.js +1 -0
- package/dist/catalog-registration.d.ts +16 -0
- package/dist/catalog-registration.js +22 -0
- package/dist/catalog-snapshot.d.ts +5 -0
- package/dist/catalog-snapshot.js +97 -0
- package/dist/cli-arguments.js +1 -1
- package/dist/cli-output.js +27 -2
- package/dist/cloudflare.d.ts +7 -1
- package/dist/cloudflare.js +36 -6
- package/dist/command-schema.js +49 -5
- package/dist/delivery.d.ts +10 -3
- package/dist/delivery.js +154 -37
- package/dist/dependencies.d.ts +24 -0
- package/dist/dependencies.js +48 -0
- package/dist/dependency-patches.d.ts +7 -0
- package/dist/dependency-patches.js +125 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/inspector-model.d.ts +9 -1
- package/dist/integration-service-readers.d.ts +13 -0
- package/dist/integration-service-readers.js +173 -0
- package/dist/lifecycle.d.ts +0 -1
- package/dist/lifecycle.js +0 -1
- package/dist/neon-service-data.d.ts +8 -0
- package/dist/neon-service-data.js +117 -0
- package/dist/pnpm-policy.d.ts +2 -2
- package/dist/pnpm-policy.js +19 -45
- package/dist/project-catalog.d.ts +41 -0
- package/dist/project-catalog.js +288 -0
- package/dist/project-config.d.ts +14 -0
- package/dist/project-config.js +89 -0
- package/dist/project-inspector.js +73 -17
- package/dist/project-lifecycle.d.ts +25 -0
- package/dist/project-lifecycle.js +57 -0
- package/dist/project-state.d.ts +5 -1
- package/dist/project-state.js +122 -16
- package/dist/provider-auth.js +2 -3
- package/dist/provider-readiness.js +27 -10
- package/dist/providers/adapters.js +4 -1
- package/dist/providers/api.d.ts +1 -0
- package/dist/providers/api.js +1 -0
- package/dist/providers/config.js +6 -8
- package/dist/providers/provision.js +1 -1
- package/dist/providers/recovery.d.ts +1 -1
- package/dist/providers/runtime.d.ts +1 -1
- package/dist/providers/runtime.js +46 -23
- package/dist/providers/state.d.ts +1 -2
- package/dist/providers/state.js +14 -54
- package/dist/provision.d.ts +9 -0
- package/dist/provision.js +30 -1
- package/dist/r2-service-data.d.ts +2 -0
- package/dist/r2-service-data.js +136 -0
- package/dist/readiness.js +9 -13
- package/dist/registry/add.js +64 -21
- package/dist/registry/commands.js +7 -9
- package/dist/registry/options.d.ts +1 -1
- package/dist/registry/options.js +4 -4
- package/dist/registry/receipt.d.ts +1 -0
- package/dist/registry/receipt.js +19 -4
- package/dist/registry/resolve.js +5 -1
- package/dist/registry/usage.js +1 -5
- package/dist/render.d.ts +2 -0
- package/dist/render.js +6 -0
- package/dist/runtime-policy.d.ts +4 -0
- package/dist/runtime-policy.js +21 -0
- package/dist/scaffold/bootstrap.js +2 -2
- package/dist/scaffold/compose.js +9 -3
- package/dist/scaffold/database.js +107 -25
- package/dist/scaffold/documentation.js +18 -13
- package/dist/scaffold/lint.d.ts +4 -0
- package/dist/scaffold/lint.js +56 -0
- package/dist/scaffold/neon-realtime.d.ts +2 -0
- package/dist/scaffold/neon-realtime.js +97 -0
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/void.d.ts +4 -0
- package/dist/scaffold/void.js +256 -0
- package/dist/scaffold/web.js +7 -1
- package/dist/scaffold/workspace.js +120 -29
- package/dist/service-deletion.d.ts +29 -0
- package/dist/service-deletion.js +195 -0
- package/dist/service-descriptor.d.ts +10 -0
- package/dist/service-descriptor.js +78 -0
- package/dist/service-model.d.ts +49 -0
- package/dist/service-model.js +8 -0
- package/dist/service-operations.d.ts +29 -0
- package/dist/service-operations.js +78 -0
- package/dist/service-readers.d.ts +8 -0
- package/dist/service-readers.js +247 -0
- package/dist/services-command.d.ts +39 -0
- package/dist/services-command.js +100 -0
- package/dist/ship.d.ts +36 -8
- package/dist/ship.js +39 -13
- package/dist/stack-registry.d.ts +4 -2
- package/dist/stack-registry.js +41 -11
- package/dist/standard.js +23 -4
- package/dist/transaction.d.ts +2 -0
- package/dist/transaction.js +10 -0
- package/dist/util.js +17 -2
- package/dist/vercel.d.ts +2 -0
- package/dist/vercel.js +69 -13
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vinext.d.ts +1 -0
- package/dist/vinext.js +13 -1
- package/dist/void-execution.d.ts +10 -0
- package/dist/void-execution.js +94 -0
- package/dist/void-migrations.d.ts +6 -0
- package/dist/void-migrations.js +110 -0
- package/dist/void-state.d.ts +16 -0
- package/dist/void-state.js +65 -0
- package/dist/void.d.ts +3 -0
- package/dist/void.js +5 -0
- package/docs/cli-design.md +2 -2
- package/docs/plugin-ui.md +51 -10
- package/docs/provider-configuration.md +10 -11
- package/docs/software-factory.md +192 -0
- package/docs/stack-standard.md +142 -0
- package/docs/void-verification.md +185 -0
- package/package.json +23 -21
- package/assets/anhedral-mark.svg +0 -4
- package/assets/anhedral-stack-technical.svg +0 -322
- package/assets/anhedral-stack.svg +0 -322
- package/assets/anhedral.svg +0 -4
- package/assets/favicon.ico +0 -0
- package/assets/security/LICENSES.txt +0 -63
- package/assets/security/audit-deps.mjs +0 -300
- package/assets/security/braces-regression.mjs +0 -102
- package/assets/security/braces@3.0.3.patch +0 -285
- package/assets/security/decode-uri-component@0.2.2.patch +0 -149
- package/assets/security/decoder-regression.mjs +0 -37
- package/assets/security/forge-regression.mjs +0 -46
- package/assets/security/manifest.json +0 -53
- package/assets/security/node-forge@1.4.0.patch +0 -26
- package/dist/security-backports.d.ts +0 -3
- package/dist/security-backports.js +0 -26
- package/docs/application-stack-standard.md +0 -75
- package/docs/delivery-workflow.md +0 -97
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readProjectSection, writeProjectSection, hasProjectSection } from '../project-config.js';
|
|
2
|
+
import { STACK_DEPENDENCIES, WORKSPACE_NODE_ENGINE, SECURITY_OVERRIDE_DEPENDENCIES, GLOB_10_OVERRIDE_VERSION, GLOB_11_OVERRIDE_VERSION, BRACE_EXPANSION_1_OVERRIDE_VERSION, BRACE_EXPANSION_2_OVERRIDE_VERSION, BRACE_EXPANSION_5_OVERRIDE_VERSION, } from '../dependencies.js';
|
|
3
|
+
import { writeDependencyAudit } from '../dependency-patches.js';
|
|
4
|
+
import { usesVoidSelection } from '../runtime-policy.js';
|
|
5
|
+
import { VOID_NODE_ENGINE } from '../void.js';
|
|
2
6
|
import { setPnpmPolicy } from '../pnpm-policy.js';
|
|
3
|
-
import { writeSecurityBackports } from '../security-backports.js';
|
|
4
7
|
import { BOOTSTRAP_COMMAND } from '../registry/bootstrap.js';
|
|
5
8
|
import { appendGitignore } from '../util.js';
|
|
6
9
|
import { PACKAGE_MANAGER } from '../dependencies.js';
|
|
@@ -10,40 +13,69 @@ import { writeSetupDocumentation, workerBuildSuffix } from './documentation.js';
|
|
|
10
13
|
import { writeStackDocumentation } from './stack-documentation.js';
|
|
11
14
|
import { writeEnvironmentExample } from './environment.js';
|
|
12
15
|
import { providerConfigurationTemplate } from '../providers/config.js';
|
|
13
|
-
import { existsSync } from 'node:fs';
|
|
16
|
+
import { existsSync, readdirSync, rmSync } from 'node:fs';
|
|
14
17
|
import path from 'node:path';
|
|
15
18
|
function securityOverrides(options) {
|
|
16
19
|
const has = (value) => options.products.includes(value);
|
|
17
20
|
return {
|
|
18
|
-
...(has('wxt')
|
|
19
|
-
|
|
21
|
+
...(has('wxt')
|
|
22
|
+
? {
|
|
23
|
+
'@wxt-dev/module-react>@vitejs/plugin-react': SECURITY_OVERRIDE_DEPENDENCIES['@vitejs/plugin-react'],
|
|
24
|
+
}
|
|
25
|
+
: {}),
|
|
26
|
+
...(has('next') || has('vinext')
|
|
27
|
+
? { 'sharp@<0.35.5': SECURITY_OVERRIDE_DEPENDENCIES.sharp }
|
|
28
|
+
: {}),
|
|
20
29
|
...(options.products.some((product) => ['vinext', 'next', 'expo', 'electron', 'wxt', 'neon', 'd1'].includes(product))
|
|
21
|
-
? { 'source-map-js@<1.2.2': '
|
|
30
|
+
? { 'source-map-js@<1.2.2': SECURITY_OVERRIDE_DEPENDENCIES['source-map-js'] }
|
|
22
31
|
: {}),
|
|
23
32
|
...(has('next') && options.hosting === 'cloudflare'
|
|
24
|
-
? {
|
|
33
|
+
? {
|
|
34
|
+
'glob@>=10.2.0 <10.5.0': GLOB_10_OVERRIDE_VERSION,
|
|
35
|
+
'glob@>=11.0.0 <11.1.0': GLOB_11_OVERRIDE_VERSION,
|
|
36
|
+
}
|
|
25
37
|
: {}),
|
|
26
38
|
...(has('wxt')
|
|
27
|
-
? {
|
|
39
|
+
? {
|
|
40
|
+
'shell-quote@<1.12.0': SECURITY_OVERRIDE_DEPENDENCIES['shell-quote'],
|
|
41
|
+
'tmp@<0.2.7': SECURITY_OVERRIDE_DEPENDENCIES.tmp,
|
|
42
|
+
'adm-zip@<0.6.1': SECURITY_OVERRIDE_DEPENDENCIES['adm-zip'],
|
|
43
|
+
}
|
|
28
44
|
: {}),
|
|
29
|
-
'baseline-browser-mapping@<2.11.0': '
|
|
30
|
-
'browserslist@<4.28.7':
|
|
45
|
+
'baseline-browser-mapping@<2.11.0': SECURITY_OVERRIDE_DEPENDENCIES['baseline-browser-mapping'],
|
|
46
|
+
'browserslist@<4.28.7': SECURITY_OVERRIDE_DEPENDENCIES.browserslist,
|
|
31
47
|
...(((has('next') || has('vinext')) && options.hosting === 'cloudflare') ||
|
|
32
48
|
has('hono') ||
|
|
33
49
|
has('electron') ||
|
|
34
50
|
has('wxt')
|
|
35
|
-
? { 'esbuild@<0.25.0':
|
|
51
|
+
? { 'esbuild@<0.25.0': SECURITY_OVERRIDE_DEPENDENCIES.esbuild }
|
|
36
52
|
: {}),
|
|
37
|
-
'brace-expansion@<2':
|
|
38
|
-
'brace-expansion@>=2 <3':
|
|
39
|
-
'brace-expansion@>=
|
|
40
|
-
'brace-expansion@>=4 <5.0.12': '5.0.12',
|
|
53
|
+
'brace-expansion@<2': BRACE_EXPANSION_1_OVERRIDE_VERSION,
|
|
54
|
+
'brace-expansion@>=2 <3': BRACE_EXPANSION_2_OVERRIDE_VERSION,
|
|
55
|
+
'brace-expansion@>=4 <5.0.12': BRACE_EXPANSION_5_OVERRIDE_VERSION,
|
|
41
56
|
};
|
|
42
57
|
}
|
|
43
58
|
function writeTurboConfiguration(root, registry) {
|
|
44
|
-
const turbo =
|
|
59
|
+
const turbo = existsSync(path.join(root, 'turbo.json'))
|
|
60
|
+
? readJson(root, 'turbo.json')
|
|
61
|
+
: { tasks: {} };
|
|
62
|
+
turbo.$schema = 'https://turbo.build/schema.json';
|
|
63
|
+
turbo.globalDependencies = [
|
|
64
|
+
...new Set([
|
|
65
|
+
...(turbo.globalDependencies ?? []),
|
|
66
|
+
'**/.env',
|
|
67
|
+
'**/.env.*',
|
|
68
|
+
'**/.dev.vars',
|
|
69
|
+
'**/.dev.vars.*',
|
|
70
|
+
]),
|
|
71
|
+
];
|
|
45
72
|
turbo.globalEnv = [
|
|
46
|
-
...new Set([
|
|
73
|
+
...new Set([
|
|
74
|
+
...(turbo.globalEnv ?? []),
|
|
75
|
+
'VOID_CLOUDFLARE_DEPLOY_BUILD',
|
|
76
|
+
'npm_execpath',
|
|
77
|
+
...registry.items.flatMap((item) => item.environment),
|
|
78
|
+
]),
|
|
47
79
|
].sort();
|
|
48
80
|
turbo.tasks = {
|
|
49
81
|
...turbo.tasks,
|
|
@@ -51,10 +83,22 @@ function writeTurboConfiguration(root, registry) {
|
|
|
51
83
|
lint: { ...turbo.tasks.lint, dependsOn: ['^lint'] },
|
|
52
84
|
typecheck: { ...turbo.tasks.typecheck, dependsOn: ['^typecheck'] },
|
|
53
85
|
test: { dependsOn: ['^build'], outputs: ['coverage/**'] },
|
|
86
|
+
'db:generate': { cache: false },
|
|
87
|
+
'db:migrate': {
|
|
88
|
+
cache: false,
|
|
89
|
+
passThroughEnv: ['CLOUDFLARE_API_TOKEN', 'CLOUDFLARE_ACCOUNT_ID'],
|
|
90
|
+
},
|
|
54
91
|
build: {
|
|
55
92
|
...turbo.tasks.build,
|
|
56
93
|
dependsOn: [...new Set(['^build', ...(turbo.tasks.build?.dependsOn ?? [])])],
|
|
57
|
-
outputs: [
|
|
94
|
+
outputs: [
|
|
95
|
+
'.next/**',
|
|
96
|
+
'!.next/cache/**',
|
|
97
|
+
'!.next/dev/**',
|
|
98
|
+
'.open-next/**',
|
|
99
|
+
'dist/**',
|
|
100
|
+
'.output/**',
|
|
101
|
+
],
|
|
58
102
|
},
|
|
59
103
|
};
|
|
60
104
|
json(root, 'turbo.json', turbo);
|
|
@@ -66,7 +110,11 @@ export function writeStandardRoot(root, options, registry, updating = false) {
|
|
|
66
110
|
name: options.name,
|
|
67
111
|
private: true,
|
|
68
112
|
packageManager: PACKAGE_MANAGER,
|
|
69
|
-
engines: {
|
|
113
|
+
engines: {
|
|
114
|
+
node: usesVoidSelection(options.products, options.hosting)
|
|
115
|
+
? VOID_NODE_ENGINE
|
|
116
|
+
: WORKSPACE_NODE_ENGINE,
|
|
117
|
+
},
|
|
70
118
|
scripts: {
|
|
71
119
|
dev: 'turbo dev',
|
|
72
120
|
build: 'turbo build',
|
|
@@ -76,18 +124,25 @@ export function writeStandardRoot(root, options, registry, updating = false) {
|
|
|
76
124
|
lint: 'turbo lint',
|
|
77
125
|
typecheck: 'turbo typecheck',
|
|
78
126
|
test: 'turbo test',
|
|
127
|
+
...(has('neon') || has('d1')
|
|
128
|
+
? {
|
|
129
|
+
'db:generate': 'turbo run db:generate --filter=@workspace/db',
|
|
130
|
+
'db:migrate': 'turbo run db:migrate --filter=@workspace/db',
|
|
131
|
+
}
|
|
132
|
+
: {}),
|
|
79
133
|
audit: 'node scripts/audit.mjs',
|
|
80
134
|
'audit:full': 'fallow --fail-on-issues',
|
|
81
|
-
'audit:deps': 'node scripts/
|
|
135
|
+
'audit:deps': 'node scripts/audit-deps.mjs',
|
|
82
136
|
check: `pnpm lint && pnpm typecheck && pnpm run audit && pnpm audit:deps && pnpm test && pnpm build${workerBuildSuffix(options)}`,
|
|
83
137
|
},
|
|
84
|
-
devDependencies: { fallow: STACK_DEPENDENCIES['fallow'] },
|
|
138
|
+
devDependencies: { turbo: STACK_DEPENDENCIES['turbo'], fallow: STACK_DEPENDENCIES['fallow'] },
|
|
85
139
|
// Upstream starter lockfiles can retain vulnerable transitive versions. Keep fixes within compatible majors.
|
|
86
140
|
pnpm: {
|
|
87
141
|
...existing.pnpm,
|
|
88
142
|
overrides: { ...existing.pnpm?.overrides, ...securityOverrides(options) },
|
|
89
143
|
},
|
|
90
144
|
});
|
|
145
|
+
writeDependencyAudit(root, updating);
|
|
91
146
|
put(root, 'scripts/audit.mjs', `import { spawnSync } from 'node:child_process';
|
|
92
147
|
const base = process.env.AUDIT_BASE;
|
|
93
148
|
const hasBase = base || ['origin/main', 'main'].find((ref) => spawnSync('git', ['rev-parse', '--verify', ref], { stdio: 'ignore' }).status === 0);
|
|
@@ -99,7 +154,15 @@ if (result.error) throw result.error;
|
|
|
99
154
|
process.exitCode = result.status ?? 1;
|
|
100
155
|
`);
|
|
101
156
|
json(root, '.fallowrc.json', {
|
|
102
|
-
|
|
157
|
+
// Void loads these contracts outside the JavaScript import graph. Declare
|
|
158
|
+
// them as roots so their application dependencies remain fully audited.
|
|
159
|
+
entry: [
|
|
160
|
+
'apps/*/void.config.ts',
|
|
161
|
+
'apps/*/env.ts',
|
|
162
|
+
'apps/*/src/void-entry.ts',
|
|
163
|
+
'apps/*/crons/**/*.{ts,mts,js,mjs}',
|
|
164
|
+
...(has('electron') ? ['apps/desktop/src/main/preload.cts'] : []),
|
|
165
|
+
],
|
|
103
166
|
// Expo web export and NativeWind load these runtime dependencies dynamically.
|
|
104
167
|
...(has('expo')
|
|
105
168
|
? {
|
|
@@ -112,9 +175,16 @@ process.exitCode = result.status ?? 1;
|
|
|
112
175
|
}
|
|
113
176
|
: {}),
|
|
114
177
|
ignorePatterns: [
|
|
178
|
+
// Maintained bundled tooling is regression-tested in the CLI repository;
|
|
179
|
+
// app audits cover customer code without re-auditing vendored CLI helpers.
|
|
180
|
+
'scripts/audit.mjs',
|
|
181
|
+
'scripts/audit-deps.mjs',
|
|
182
|
+
'scripts/void-migrations.mjs',
|
|
183
|
+
'scripts/prepare-void-migrations.mjs',
|
|
115
184
|
'**/next-env.d.ts',
|
|
116
185
|
'**/.next/**',
|
|
117
186
|
'**/.open-next/**',
|
|
187
|
+
'**/.vinext/**',
|
|
118
188
|
'**/.wrangler/**',
|
|
119
189
|
'**/dist/**',
|
|
120
190
|
'**/worker-configuration.d.ts',
|
|
@@ -123,6 +193,8 @@ process.exitCode = result.status ?? 1;
|
|
|
123
193
|
});
|
|
124
194
|
writeTurboConfiguration(root, registry);
|
|
125
195
|
setPnpmPolicy(root, {
|
|
196
|
+
...(!updating ? { packages: ['apps/*', 'packages/*'] } : {}),
|
|
197
|
+
sharedWorkspaceLockfile: true,
|
|
126
198
|
allowBuilds: undefined,
|
|
127
199
|
onlyBuiltDependencies: [
|
|
128
200
|
'esbuild',
|
|
@@ -132,11 +204,30 @@ process.exitCode = result.status ?? 1;
|
|
|
132
204
|
...(has('electron') ? ['electron'] : []),
|
|
133
205
|
],
|
|
134
206
|
});
|
|
135
|
-
|
|
207
|
+
// Upstream app/package lockfiles would create competing dependency authorities.
|
|
208
|
+
if (!updating) {
|
|
209
|
+
for (const parent of ['apps', 'packages']) {
|
|
210
|
+
const directory = path.join(root, parent);
|
|
211
|
+
if (!existsSync(directory))
|
|
212
|
+
continue;
|
|
213
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
214
|
+
if (!entry.isDirectory())
|
|
215
|
+
continue;
|
|
216
|
+
for (const lock of ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock'])
|
|
217
|
+
rmSync(path.join(directory, entry.name, lock), { force: true });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
for (const lock of ['package-lock.json', 'yarn.lock'])
|
|
221
|
+
rmSync(path.join(root, lock), { force: true });
|
|
222
|
+
}
|
|
136
223
|
appendGitignore(root, [
|
|
137
224
|
'node_modules/',
|
|
138
225
|
'.open-next/',
|
|
226
|
+
'.vinext/',
|
|
139
227
|
'.wrangler/',
|
|
228
|
+
'.void/',
|
|
229
|
+
'.void-wrangler.jsonc',
|
|
230
|
+
'/apps/*/db/migrations/',
|
|
140
231
|
'.dev.vars',
|
|
141
232
|
'.dev.vars.*',
|
|
142
233
|
'!.dev.vars.example',
|
|
@@ -149,13 +240,13 @@ process.exitCode = result.status ?? 1;
|
|
|
149
240
|
]);
|
|
150
241
|
writeEnvironmentExample(root, registry);
|
|
151
242
|
writeStackDocumentation(root, registry);
|
|
152
|
-
|
|
243
|
+
writeProjectSection(root, 'standard', {
|
|
153
244
|
schemaVersion: 1,
|
|
154
245
|
standard: 'anhedral-application-stack',
|
|
155
246
|
products: options.products,
|
|
156
247
|
hosting: has('next') || has('vinext') ? options.hosting : null,
|
|
157
248
|
bootstrap: updating
|
|
158
|
-
?
|
|
249
|
+
? readProjectSection(root, 'standard').bootstrap
|
|
159
250
|
: {
|
|
160
251
|
command: BOOTSTRAP_COMMAND.join(' '),
|
|
161
252
|
upstreamPackageManager: existing.packageManager,
|
|
@@ -163,12 +254,12 @@ process.exitCode = result.status ?? 1;
|
|
|
163
254
|
status: 'starter',
|
|
164
255
|
resourcesProvisioned: false,
|
|
165
256
|
});
|
|
166
|
-
|
|
257
|
+
writeProjectSection(root, 'setup', createSetupPlan({ ...options, dryRun: false }, registry));
|
|
167
258
|
const providers = providerConfigurationTemplate(options.products, options.name);
|
|
168
|
-
const prior = updating &&
|
|
169
|
-
?
|
|
259
|
+
const prior = updating && hasProjectSection(root, 'providers')
|
|
260
|
+
? readProjectSection(root, 'providers')
|
|
170
261
|
: undefined;
|
|
171
|
-
|
|
262
|
+
writeProjectSection(root, 'providers', {
|
|
172
263
|
...providers,
|
|
173
264
|
providers: { ...providers.providers, ...prior?.providers },
|
|
174
265
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CloudflareRequest } from './cloudflare.js';
|
|
2
|
+
export interface DeletionPlan {
|
|
3
|
+
token: string;
|
|
4
|
+
name: string;
|
|
5
|
+
accountId: string;
|
|
6
|
+
resourceId: string;
|
|
7
|
+
kind: string;
|
|
8
|
+
applications: string[];
|
|
9
|
+
expiresAt: string;
|
|
10
|
+
impact: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class ServiceDeletionStore {
|
|
13
|
+
readonly directory: string;
|
|
14
|
+
constructor(directory: string);
|
|
15
|
+
plan(root: string, key: string, request: CloudflareRequest): Promise<DeletionPlan>;
|
|
16
|
+
execute(root: string, key: string, token: string, typedName: string, request: CloudflareRequest): Promise<{
|
|
17
|
+
state: "deleted";
|
|
18
|
+
resourceId: string;
|
|
19
|
+
message: string;
|
|
20
|
+
} | {
|
|
21
|
+
state: "uncertain";
|
|
22
|
+
resourceId: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export declare function assertNoDeletedServices(root: string, resources: {
|
|
27
|
+
kind: string;
|
|
28
|
+
name: string;
|
|
29
|
+
}[]): void;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, realpathSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { readBoundedFile } from './bounded-file.js';
|
|
6
|
+
import { atomicJson, readApplication, withApplicationLock } from './project-state.js';
|
|
7
|
+
import { inspectApplication } from './project-inspector.js';
|
|
8
|
+
import { resolveService } from './service-descriptor.js';
|
|
9
|
+
import { observeService, record, serviceEndpoint } from './service-readers.js';
|
|
10
|
+
const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
11
|
+
const actionSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
schemaVersion: z.literal(1),
|
|
14
|
+
root: z.string(),
|
|
15
|
+
serviceKey: z.string().max(1024),
|
|
16
|
+
fingerprint: z.string().regex(/^[a-f0-9]{64}$/),
|
|
17
|
+
name: z.string().max(256),
|
|
18
|
+
expiresAt: z.number(),
|
|
19
|
+
state: z.enum(['prepared', 'pending', 'deleted', 'uncertain', 'rejected']),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
function fingerprint(root, service) {
|
|
23
|
+
const inspection = inspectApplication(root);
|
|
24
|
+
return digest(JSON.stringify({
|
|
25
|
+
service,
|
|
26
|
+
project: readApplication(root),
|
|
27
|
+
configuration: inspection.configuration,
|
|
28
|
+
receipts: inspection.cloudflareResources,
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
async function assertDeletionScope(root, service, request) {
|
|
32
|
+
if (!['d1', 'kv'].includes(service.kind) ||
|
|
33
|
+
service.ownership !== 'created' ||
|
|
34
|
+
!service.name ||
|
|
35
|
+
service.applications.length > 1)
|
|
36
|
+
throw new Error('Deletion requires a supported, recorded project-created resource with at most one owning application. Reused, shared, or unverified resources cannot be deleted here.');
|
|
37
|
+
const observation = await observeService(service, request);
|
|
38
|
+
if (observation.state !== 'available' || observation.name !== service.name)
|
|
39
|
+
throw new Error('The exact resource identity must be confirmed before deletion.');
|
|
40
|
+
const scripts = await request('GET', '/workers/scripts?per_page=100');
|
|
41
|
+
if (!Array.isArray(scripts.result) ||
|
|
42
|
+
scripts.result.length >= 100 ||
|
|
43
|
+
(scripts.result_info?.total_pages ?? 1) > 1)
|
|
44
|
+
throw new Error('Worker dependency listing is incomplete; deletion is blocked.');
|
|
45
|
+
const project = readApplication(root);
|
|
46
|
+
const allowed = new Set(project.targets
|
|
47
|
+
.filter((target) => service.applications.includes(target.directory))
|
|
48
|
+
.map((target) => target.workerName));
|
|
49
|
+
for (const raw of scripts.result) {
|
|
50
|
+
const script = record(raw);
|
|
51
|
+
if (typeof script.id !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,62}$/.test(script.id))
|
|
52
|
+
throw new Error('Worker dependency identity is unavailable.');
|
|
53
|
+
const settings = record((await request('GET', `/workers/scripts/${script.id}/settings`)).result);
|
|
54
|
+
if (!Array.isArray(settings.bindings) || settings.bindings.length > 500)
|
|
55
|
+
throw new Error('Worker dependencies could not be verified.');
|
|
56
|
+
for (const rawBinding of settings.bindings) {
|
|
57
|
+
const binding = record(rawBinding);
|
|
58
|
+
if ((binding.type === 'd1' && typeof binding.id !== 'string') ||
|
|
59
|
+
(binding.type === 'kv_namespace' && typeof binding.namespace_id !== 'string'))
|
|
60
|
+
throw new Error('Worker dependency identities are incomplete.');
|
|
61
|
+
const uses = service.kind === 'd1'
|
|
62
|
+
? binding.type === 'd1' && binding.id === service.id
|
|
63
|
+
: binding.type === 'kv_namespace' && binding.namespace_id === service.id;
|
|
64
|
+
if (uses && !allowed.has(script.id))
|
|
65
|
+
throw new Error('Another Worker uses this resource. Shared resources cannot be deleted here.');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export class ServiceDeletionStore {
|
|
70
|
+
directory;
|
|
71
|
+
constructor(directory) {
|
|
72
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
73
|
+
this.directory = realpathSync(directory);
|
|
74
|
+
}
|
|
75
|
+
async plan(root, key, request) {
|
|
76
|
+
root = realpathSync(root);
|
|
77
|
+
const service = resolveService(root, key);
|
|
78
|
+
const before = fingerprint(root, service);
|
|
79
|
+
await assertDeletionScope(root, service, request);
|
|
80
|
+
if (before !== fingerprint(root, resolveService(root, key)))
|
|
81
|
+
throw new Error('Source changed during deletion planning.');
|
|
82
|
+
const token = randomBytes(32).toString('base64url');
|
|
83
|
+
const expiresAt = Date.now() + 5 * 60_000;
|
|
84
|
+
writeFileSync(path.join(this.directory, `${digest(token)}.json`), JSON.stringify({
|
|
85
|
+
schemaVersion: 1,
|
|
86
|
+
root,
|
|
87
|
+
serviceKey: key,
|
|
88
|
+
fingerprint: before,
|
|
89
|
+
name: service.name,
|
|
90
|
+
expiresAt,
|
|
91
|
+
state: 'prepared',
|
|
92
|
+
}), { mode: 0o600, flag: 'wx' });
|
|
93
|
+
return {
|
|
94
|
+
token,
|
|
95
|
+
name: service.name,
|
|
96
|
+
accountId: service.accountId,
|
|
97
|
+
resourceId: service.id,
|
|
98
|
+
kind: service.kind,
|
|
99
|
+
applications: service.applications,
|
|
100
|
+
expiresAt: new Date(expiresAt).toISOString(),
|
|
101
|
+
impact: 'Permanently removes this resource and its stored data. Existing source bindings remain and must be reviewed before shipping.',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async execute(root, key, token, typedName, request) {
|
|
105
|
+
if (!/^[a-zA-Z0-9_-]{43}$/.test(token))
|
|
106
|
+
throw new Error('Invalid deletion confirmation.');
|
|
107
|
+
const file = path.join(this.directory, `${digest(token)}.json`);
|
|
108
|
+
return withApplicationLock(root, async () => {
|
|
109
|
+
const saved = actionSchema.parse(JSON.parse(readBoundedFile(file, 16384).toString('utf8')));
|
|
110
|
+
root = realpathSync(root);
|
|
111
|
+
if (saved.root !== root ||
|
|
112
|
+
saved.serviceKey !== key ||
|
|
113
|
+
saved.name !== typedName ||
|
|
114
|
+
saved.expiresAt < Date.now() ||
|
|
115
|
+
saved.state !== 'prepared')
|
|
116
|
+
throw new Error('Deletion confirmation is expired, already used, or does not match this resource.');
|
|
117
|
+
const service = resolveService(root, key);
|
|
118
|
+
if (saved.fingerprint !== fingerprint(root, service))
|
|
119
|
+
throw new Error('Service identity or dependencies changed. Review a new deletion plan.');
|
|
120
|
+
await assertDeletionScope(root, service, request);
|
|
121
|
+
if (saved.fingerprint !== fingerprint(root, resolveService(root, key)))
|
|
122
|
+
throw new Error('Source changed before deletion.');
|
|
123
|
+
saved.state = 'pending';
|
|
124
|
+
atomicJson(file, saved);
|
|
125
|
+
const journal = path.join(root, '.anhedral/service-deletions.json');
|
|
126
|
+
const writeReceipt = (state) => {
|
|
127
|
+
let entries = [];
|
|
128
|
+
if (existsSync(journal)) {
|
|
129
|
+
const previous = record(JSON.parse(readBoundedFile(journal, 256 * 1024).toString('utf8')));
|
|
130
|
+
if (previous.projectId !== service.projectId ||
|
|
131
|
+
previous.accountId !== service.accountId ||
|
|
132
|
+
!Array.isArray(previous.entries) ||
|
|
133
|
+
previous.entries.length >= 500)
|
|
134
|
+
throw new Error('Deletion journal is invalid or full.');
|
|
135
|
+
entries = previous.entries.filter((entry) => record(entry).resourceId !== service.id);
|
|
136
|
+
}
|
|
137
|
+
atomicJson(journal, {
|
|
138
|
+
schemaVersion: 1,
|
|
139
|
+
projectId: service.projectId,
|
|
140
|
+
accountId: service.accountId,
|
|
141
|
+
entries: [
|
|
142
|
+
...entries,
|
|
143
|
+
{
|
|
144
|
+
resourceId: service.id,
|
|
145
|
+
kind: service.kind,
|
|
146
|
+
name: service.name,
|
|
147
|
+
state,
|
|
148
|
+
recordedAt: new Date().toISOString(),
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
writeReceipt('pending');
|
|
154
|
+
try {
|
|
155
|
+
await request('DELETE', serviceEndpoint(service));
|
|
156
|
+
if ((await observeService(service, request)).state !== 'not-found')
|
|
157
|
+
throw new Error('Deletion could not be confirmed.');
|
|
158
|
+
saved.state = 'deleted';
|
|
159
|
+
atomicJson(file, saved);
|
|
160
|
+
writeReceipt('deleted');
|
|
161
|
+
return {
|
|
162
|
+
state: 'deleted',
|
|
163
|
+
resourceId: service.id,
|
|
164
|
+
message: 'Provider confirmed deletion. Review the remaining source bindings before shipping.',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
saved.state = 'uncertain';
|
|
169
|
+
atomicJson(file, saved);
|
|
170
|
+
writeReceipt('uncertain');
|
|
171
|
+
return {
|
|
172
|
+
state: 'uncertain',
|
|
173
|
+
resourceId: service.id,
|
|
174
|
+
message: 'Deletion outcome is uncertain. Refresh provider status; no automatic deletion retry is performed.',
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export function assertNoDeletedServices(root, resources) {
|
|
181
|
+
const file = path.join(root, '.anhedral/service-deletions.json');
|
|
182
|
+
if (!existsSync(file))
|
|
183
|
+
return;
|
|
184
|
+
const saved = record(JSON.parse(readBoundedFile(file, 256 * 1024).toString('utf8')));
|
|
185
|
+
const project = readApplication(root);
|
|
186
|
+
if (saved.projectId !== project.id ||
|
|
187
|
+
saved.accountId !== project.accountId ||
|
|
188
|
+
!Array.isArray(saved.entries))
|
|
189
|
+
throw new Error('Deletion history cannot be verified before provisioning.');
|
|
190
|
+
for (const raw of saved.entries) {
|
|
191
|
+
const entry = record(raw);
|
|
192
|
+
if (resources.some((resource) => resource.kind === entry.kind && resource.name === entry.name))
|
|
193
|
+
throw new Error('A selected resource has a recorded deletion attempt. Review source bindings and remote state before provisioning; deleted services are not recreated automatically.');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ServiceDescriptor, ServiceKind } from './service-model.js';
|
|
2
|
+
import type { ProjectInspection } from './inspector-model.js';
|
|
3
|
+
export declare function unboundResourceSelectors(inspection: ProjectInspection): string[];
|
|
4
|
+
export declare function resolveService(root: string, key: string): ServiceDescriptor;
|
|
5
|
+
export declare function serviceCapabilities(kind: ServiceKind): {
|
|
6
|
+
status: boolean;
|
|
7
|
+
metrics: boolean;
|
|
8
|
+
data: boolean;
|
|
9
|
+
delete: boolean;
|
|
10
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { inspectApplication } from './project-inspector.js';
|
|
2
|
+
import { readApplication } from './project-state.js';
|
|
3
|
+
const kinds = {
|
|
4
|
+
D1: 'd1',
|
|
5
|
+
KV: 'kv',
|
|
6
|
+
R2: 'r2',
|
|
7
|
+
'Queue producer': 'queue',
|
|
8
|
+
'Queue consumer': 'queue',
|
|
9
|
+
};
|
|
10
|
+
export function unboundResourceSelectors(inspection) {
|
|
11
|
+
return inspection.cloudflareResources.data
|
|
12
|
+
.filter((resource) => !inspection.configuration.data.bindings.some((binding) => kinds[binding.kind] === resource.kind &&
|
|
13
|
+
(binding.resourceId === resource.id ||
|
|
14
|
+
(['r2', 'queue'].includes(resource.kind) && binding.resourceId === resource.name))))
|
|
15
|
+
.map((resource) => `receipt:${resource.kind}:${resource.id}`);
|
|
16
|
+
}
|
|
17
|
+
export function resolveService(root, key) {
|
|
18
|
+
const inspection = inspectApplication(root);
|
|
19
|
+
const project = readApplication(root);
|
|
20
|
+
if (!project.accountId ||
|
|
21
|
+
inspection.targets.state !== 'available' ||
|
|
22
|
+
inspection.configuration.state !== 'available')
|
|
23
|
+
throw new Error('Validated service configuration and a connected account are required.');
|
|
24
|
+
const target = inspection.targets.data.find((item) => key === `target:${item.provider}:${item.id}` && item.provider === 'cloudflare' && !item.error);
|
|
25
|
+
if (target) {
|
|
26
|
+
const configured = project.targets.find((item) => item.directory === target.application);
|
|
27
|
+
if (!configured)
|
|
28
|
+
throw new Error('Service target identity changed.');
|
|
29
|
+
return {
|
|
30
|
+
key,
|
|
31
|
+
kind: 'worker',
|
|
32
|
+
id: configured.workerName,
|
|
33
|
+
name: configured.workerName,
|
|
34
|
+
accountId: project.accountId,
|
|
35
|
+
projectId: project.id,
|
|
36
|
+
applications: [target.application],
|
|
37
|
+
ownership: 'unknown',
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const binding = inspection.configuration.data.bindings.find((item) => key === `binding:${item.application}:${item.kind}:${item.name}`);
|
|
41
|
+
const record = inspection.cloudflareResources.data.find((item) => key === `receipt:${item.kind}:${item.id}`);
|
|
42
|
+
const kind = binding ? kinds[binding.kind] : record?.kind;
|
|
43
|
+
const id = binding?.resourceId ?? record?.id;
|
|
44
|
+
if (!kind ||
|
|
45
|
+
!['d1', 'kv', 'r2', 'queue'].includes(kind) ||
|
|
46
|
+
!id ||
|
|
47
|
+
!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,254}$/.test(id))
|
|
48
|
+
throw new Error('This service has no supported provider resource identity.');
|
|
49
|
+
const receipt = record ??
|
|
50
|
+
inspection.cloudflareResources.data.find((item) => item.kind === kind &&
|
|
51
|
+
(item.id === id || (['r2', 'queue'].includes(kind) && item.name === id)));
|
|
52
|
+
const references = inspection.configuration.data.bindings.filter((item) => kinds[item.kind] === kind &&
|
|
53
|
+
(item.resourceId === id ||
|
|
54
|
+
(receipt && [receipt.name, receipt.id].includes(item.resourceId ?? ''))));
|
|
55
|
+
return {
|
|
56
|
+
key,
|
|
57
|
+
kind,
|
|
58
|
+
id: receipt?.id ?? id,
|
|
59
|
+
name: receipt?.name ?? (kind === 'r2' ? id : null),
|
|
60
|
+
accountId: project.accountId,
|
|
61
|
+
projectId: project.id,
|
|
62
|
+
applications: [...new Set(references.map((item) => item.application))].sort(),
|
|
63
|
+
ownership: inspection.cloudflareResources.state === 'available' &&
|
|
64
|
+
(receipt?.createdByProject === true || receipt?.reused === false)
|
|
65
|
+
? 'created'
|
|
66
|
+
: receipt?.reused === true
|
|
67
|
+
? 'reused'
|
|
68
|
+
: 'unknown',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function serviceCapabilities(kind) {
|
|
72
|
+
return {
|
|
73
|
+
status: true,
|
|
74
|
+
metrics: kind === 'd1' || kind === 'worker',
|
|
75
|
+
data: kind === 'd1' || kind === 'kv' || kind === 'r2',
|
|
76
|
+
delete: kind === 'd1' || kind === 'kv',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export declare const SERVICE_TOOL_ACTIONS: {
|
|
2
|
+
readonly refresh_service: "status";
|
|
3
|
+
readonly get_service_metrics: "metrics";
|
|
4
|
+
readonly list_service_tables: "tables";
|
|
5
|
+
readonly browse_service_data: "data";
|
|
6
|
+
readonly plan_service_deletion: "delete-plan";
|
|
7
|
+
readonly delete_service: "delete";
|
|
8
|
+
};
|
|
9
|
+
export type ServiceAction = (typeof SERVICE_TOOL_ACTIONS)[keyof typeof SERVICE_TOOL_ACTIONS];
|
|
10
|
+
export type ServiceKind = 'worker' | 'd1' | 'kv' | 'r2' | 'queue';
|
|
11
|
+
export interface ServiceDescriptor {
|
|
12
|
+
key: string;
|
|
13
|
+
kind: ServiceKind;
|
|
14
|
+
id: string;
|
|
15
|
+
name: string | null;
|
|
16
|
+
accountId: string;
|
|
17
|
+
projectId: string;
|
|
18
|
+
applications: string[];
|
|
19
|
+
ownership: 'created' | 'reused' | 'unknown';
|
|
20
|
+
}
|
|
21
|
+
export interface ServiceObservation {
|
|
22
|
+
state: 'available' | 'not-found' | 'permission-required' | 'unavailable';
|
|
23
|
+
fetchedAt: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
storageBytes?: number;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ServiceMetrics {
|
|
29
|
+
fetchedAt: string;
|
|
30
|
+
start: string;
|
|
31
|
+
end: string;
|
|
32
|
+
timezone: 'UTC';
|
|
33
|
+
source: string;
|
|
34
|
+
sampled: boolean;
|
|
35
|
+
points: {
|
|
36
|
+
time: string;
|
|
37
|
+
values: Record<string, number>;
|
|
38
|
+
}[];
|
|
39
|
+
units: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
export interface ServiceData {
|
|
42
|
+
fetchedAt: string;
|
|
43
|
+
columns: string[];
|
|
44
|
+
rows: (string | number | boolean | null)[][];
|
|
45
|
+
offset: number;
|
|
46
|
+
hasMore: boolean;
|
|
47
|
+
masked: boolean;
|
|
48
|
+
nextCursor?: string;
|
|
49
|
+
}
|