anhedral 0.15.0 → 0.17.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.
Files changed (246) hide show
  1. package/README.md +82 -34
  2. package/assets/stack/ai-schema.ts.txt +5 -0
  3. package/assets/stack/ai.ts.txt +30 -0
  4. package/assets/stack/api-index.ts.txt +15 -0
  5. package/assets/stack/auth-features.ts.txt +4 -0
  6. package/assets/stack/auth-journal.json.txt +13 -0
  7. package/assets/stack/auth-migration.sql.txt +53 -0
  8. package/assets/stack/auth-routes.ts.txt +11 -0
  9. package/assets/stack/auth-schema.ts.txt +64 -0
  10. package/assets/stack/auth-snapshot.json.txt +346 -0
  11. package/assets/stack/auth.ts.txt +32 -0
  12. package/assets/stack/billing-mode.ts.txt +8 -0
  13. package/assets/stack/billing-schema.ts.txt +11 -0
  14. package/assets/stack/desktop.rs.txt +21 -0
  15. package/assets/stack/entitlement-guard.ts.txt +32 -0
  16. package/assets/stack/entitlements.ts.txt +8 -0
  17. package/assets/stack/events-schema.ts.txt +12 -0
  18. package/assets/stack/events.ts.txt +59 -0
  19. package/assets/stack/mobile-auth.ts.txt +25 -0
  20. package/assets/stack/mobile-billing.tsx.txt +63 -0
  21. package/assets/stack/mobile-session.tsx.txt +83 -0
  22. package/assets/stack/native-button.tsx.txt +108 -0
  23. package/assets/stack/native-global.css.txt +4 -0
  24. package/assets/stack/native-lib-utils.ts.txt +5 -0
  25. package/assets/stack/native-metro.config.js.txt +6 -0
  26. package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
  27. package/assets/stack/native-tailwind.config.js.txt +73 -0
  28. package/assets/stack/native-text.tsx.txt +89 -0
  29. package/assets/stack/purchases.ts.txt +65 -0
  30. package/assets/stack/revenuecat.ts.txt +88 -0
  31. package/assets/stack/rtc-schema.ts.txt +10 -0
  32. package/assets/stack/rtc.ts.txt +122 -0
  33. package/assets/stack/security.ts.txt +31 -0
  34. package/assets/stack/storage.ts.txt +36 -0
  35. package/assets/stack/stripe.ts.txt +126 -0
  36. package/assets/stack/web-sign-in.tsx.txt +51 -0
  37. package/assets/ui/LICENSE.react-native-reusables +21 -0
  38. package/assets/ui/UPSTREAM.json +0 -11
  39. package/assets/ui/catalog.json +891 -0
  40. package/assets/ui/extensions/registry.json +6 -0
  41. package/dist/bin.js +7 -12
  42. package/dist/capabilities.d.ts +4 -33
  43. package/dist/capabilities.js +2 -66
  44. package/dist/capability-catalog.d.ts +83 -0
  45. package/dist/capability-catalog.js +121 -0
  46. package/dist/capability-command.d.ts +3 -0
  47. package/dist/capability-command.js +188 -0
  48. package/dist/capability-editor.d.ts +17 -0
  49. package/dist/capability-editor.js +97 -0
  50. package/dist/capability-recipes.d.ts +4 -0
  51. package/dist/capability-recipes.js +520 -0
  52. package/dist/capability-references.d.ts +4 -0
  53. package/dist/capability-references.js +7 -0
  54. package/dist/cli-commands.d.ts +1 -2
  55. package/dist/cli-commands.js +10 -104
  56. package/dist/cli-output.d.ts +1 -2
  57. package/dist/cli-output.js +6 -251
  58. package/dist/command-schema.js +39 -322
  59. package/dist/dependencies.d.ts +29 -9
  60. package/dist/dependencies.js +57 -64
  61. package/dist/index.d.ts +1 -42
  62. package/dist/index.js +1 -27
  63. package/dist/platforms/web.d.ts +1 -1
  64. package/dist/platforms/web.js +27 -75
  65. package/dist/project-config.d.ts +2 -13
  66. package/dist/project-config.js +10 -82
  67. package/dist/registry/options.js +1 -5
  68. package/dist/registry/resolve.d.ts +1 -1
  69. package/dist/registry/resolve.js +4 -10
  70. package/dist/registry/usage.js +3 -9
  71. package/dist/scaffold/backend.js +0 -3
  72. package/dist/scaffold/database.js +2 -1
  73. package/dist/scaffold/documentation.js +56 -25
  74. package/dist/scaffold/stack-documentation.js +1 -1
  75. package/dist/scaffold/storage.d.ts +2 -0
  76. package/dist/scaffold/storage.js +21 -0
  77. package/dist/scaffold/workspace.js +21 -22
  78. package/dist/stack-registry.d.ts +2 -10
  79. package/dist/stack-registry.js +12 -98
  80. package/dist/standard.js +1 -11
  81. package/dist/ui-catalog.d.ts +26 -0
  82. package/dist/ui-catalog.js +31 -0
  83. package/dist/ui-command.d.ts +3 -0
  84. package/dist/ui-command.js +219 -0
  85. package/dist/ui-project.d.ts +22 -0
  86. package/dist/ui-project.js +110 -0
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/docs/anhedral-stack.md +12 -23
  90. package/docs/assets/anhedral-stack-light.png +0 -0
  91. package/docs/assets/anhedral-stack.png +0 -0
  92. package/docs/capabilities.md +110 -0
  93. package/docs/native-ui.md +47 -0
  94. package/docs/software-factory.md +35 -50
  95. package/docs/stack-standard.md +19 -70
  96. package/docs/ui.md +33 -0
  97. package/docs/verification.md +6 -876
  98. package/package.json +21 -16
  99. package/assets/ui/native/button.tsx +0 -85
  100. package/assets/ui/native/card.tsx +0 -33
  101. package/assets/ui/native/dialog.tsx +0 -75
  102. package/assets/ui/native/input.tsx +0 -27
  103. package/assets/ui/native/label.tsx +0 -4
  104. package/assets/ui/native/layout.tsx +0 -26
  105. package/assets/ui/native/text.tsx +0 -20
  106. package/assets/ui/native/theme-switcher.tsx +0 -22
  107. package/assets/ui/theme-storage.ts +0 -25
  108. package/assets/ui/theme.tsx +0 -66
  109. package/dist/access.d.ts +0 -10
  110. package/dist/access.js +0 -93
  111. package/dist/auth-schema-snapshot.d.ts +0 -346
  112. package/dist/auth-schema-snapshot.js +0 -347
  113. package/dist/auth-schema.d.ts +0 -1
  114. package/dist/auth-schema.js +0 -57
  115. package/dist/capability-contract.d.ts +0 -47
  116. package/dist/capability-contract.js +0 -129
  117. package/dist/catalog-model.d.ts +0 -24
  118. package/dist/catalog-model.js +0 -1
  119. package/dist/catalog-registration.d.ts +0 -16
  120. package/dist/catalog-registration.js +0 -22
  121. package/dist/catalog-snapshot.d.ts +0 -5
  122. package/dist/catalog-snapshot.js +0 -97
  123. package/dist/cli-delivery.d.ts +0 -3
  124. package/dist/cli-delivery.js +0 -112
  125. package/dist/cloudflare.d.ts +0 -25
  126. package/dist/cloudflare.js +0 -226
  127. package/dist/delivery-evidence.d.ts +0 -62
  128. package/dist/delivery-evidence.js +0 -157
  129. package/dist/delivery.d.ts +0 -82
  130. package/dist/delivery.js +0 -489
  131. package/dist/inspector-model.d.ts +0 -123
  132. package/dist/inspector-model.js +0 -1
  133. package/dist/integration-service-readers.d.ts +0 -12
  134. package/dist/integration-service-readers.js +0 -92
  135. package/dist/lifecycle-model.d.ts +0 -15
  136. package/dist/lifecycle-model.js +0 -20
  137. package/dist/lifecycle.d.ts +0 -11
  138. package/dist/lifecycle.js +0 -91
  139. package/dist/management.d.ts +0 -3
  140. package/dist/management.js +0 -47
  141. package/dist/mobile-delivery.d.ts +0 -77
  142. package/dist/mobile-delivery.js +0 -370
  143. package/dist/platforms/mobile.d.ts +0 -2
  144. package/dist/platforms/mobile.js +0 -156
  145. package/dist/project-catalog.d.ts +0 -41
  146. package/dist/project-catalog.js +0 -288
  147. package/dist/project-inspector.d.ts +0 -4
  148. package/dist/project-inspector.js +0 -671
  149. package/dist/project-lifecycle.d.ts +0 -25
  150. package/dist/project-lifecycle.js +0 -57
  151. package/dist/project-state.d.ts +0 -47
  152. package/dist/project-state.js +0 -480
  153. package/dist/provider-auth.d.ts +0 -41
  154. package/dist/provider-auth.js +0 -180
  155. package/dist/provider-readiness.d.ts +0 -30
  156. package/dist/provider-readiness.js +0 -85
  157. package/dist/providers/adapters.d.ts +0 -17
  158. package/dist/providers/adapters.js +0 -103
  159. package/dist/providers/api.d.ts +0 -29
  160. package/dist/providers/api.js +0 -253
  161. package/dist/providers/config.d.ts +0 -15
  162. package/dist/providers/config.js +0 -136
  163. package/dist/providers/definitions.d.ts +0 -115
  164. package/dist/providers/definitions.js +0 -42
  165. package/dist/providers/provision.d.ts +0 -24
  166. package/dist/providers/provision.js +0 -76
  167. package/dist/providers/receipts.d.ts +0 -20
  168. package/dist/providers/receipts.js +0 -56
  169. package/dist/providers/recovery-verification.d.ts +0 -7
  170. package/dist/providers/recovery-verification.js +0 -52
  171. package/dist/providers/recovery.d.ts +0 -30
  172. package/dist/providers/recovery.js +0 -34
  173. package/dist/providers/runtime.d.ts +0 -10
  174. package/dist/providers/runtime.js +0 -234
  175. package/dist/providers/schema.d.ts +0 -28
  176. package/dist/providers/schema.js +0 -49
  177. package/dist/providers/state.d.ts +0 -55
  178. package/dist/providers/state.js +0 -283
  179. package/dist/provision.d.ts +0 -47
  180. package/dist/provision.js +0 -208
  181. package/dist/r2-service-data.d.ts +0 -2
  182. package/dist/r2-service-data.js +0 -136
  183. package/dist/readiness.d.ts +0 -23
  184. package/dist/readiness.js +0 -117
  185. package/dist/registry/add.d.ts +0 -24
  186. package/dist/registry/add.js +0 -210
  187. package/dist/registry/bootstrap.d.ts +0 -3
  188. package/dist/registry/bootstrap.js +0 -5
  189. package/dist/registry/commands.d.ts +0 -3
  190. package/dist/registry/commands.js +0 -83
  191. package/dist/registry/preview.d.ts +0 -11
  192. package/dist/registry/preview.js +0 -91
  193. package/dist/registry/receipt.d.ts +0 -3
  194. package/dist/registry/receipt.js +0 -68
  195. package/dist/repository.d.ts +0 -24
  196. package/dist/repository.js +0 -96
  197. package/dist/scaffold/auth.d.ts +0 -2
  198. package/dist/scaffold/auth.js +0 -76
  199. package/dist/scaffold/billing-config.d.ts +0 -1
  200. package/dist/scaffold/billing-config.js +0 -73
  201. package/dist/scaffold/billing-contracts.d.ts +0 -2
  202. package/dist/scaffold/billing-contracts.js +0 -48
  203. package/dist/scaffold/billing-providers.d.ts +0 -1
  204. package/dist/scaffold/billing-providers.js +0 -249
  205. package/dist/scaffold/billing-schema.d.ts +0 -1
  206. package/dist/scaffold/billing-schema.js +0 -34
  207. package/dist/scaffold/billing-security.d.ts +0 -1
  208. package/dist/scaffold/billing-security.js +0 -46
  209. package/dist/scaffold/billing-server.d.ts +0 -1
  210. package/dist/scaffold/billing-server.js +0 -139
  211. package/dist/scaffold/billing-store.d.ts +0 -1
  212. package/dist/scaffold/billing-store.js +0 -72
  213. package/dist/scaffold/billing.d.ts +0 -2
  214. package/dist/scaffold/billing.js +0 -208
  215. package/dist/scaffold/expo-auth.d.ts +0 -3
  216. package/dist/scaffold/expo-auth.js +0 -203
  217. package/dist/scaffold/expo-billing.d.ts +0 -3
  218. package/dist/scaffold/expo-billing.js +0 -257
  219. package/dist/scaffold/expo-runtime.d.ts +0 -3
  220. package/dist/scaffold/expo-runtime.js +0 -43
  221. package/dist/scaffold/integrations.d.ts +0 -2
  222. package/dist/scaffold/integrations.js +0 -11
  223. package/dist/scaffold/managed-email.d.ts +0 -3
  224. package/dist/scaffold/managed-email.js +0 -47
  225. package/dist/scaffold/native-ui.d.ts +0 -2
  226. package/dist/scaffold/native-ui.js +0 -69
  227. package/dist/scaffold/password-reset.d.ts +0 -1
  228. package/dist/scaffold/password-reset.js +0 -99
  229. package/dist/scaffold/private-files.d.ts +0 -2
  230. package/dist/scaffold/private-files.js +0 -78
  231. package/dist/scaffold/web-billing.d.ts +0 -2
  232. package/dist/scaffold/web-billing.js +0 -48
  233. package/dist/service-deletion.d.ts +0 -29
  234. package/dist/service-deletion.js +0 -195
  235. package/dist/service-descriptor.d.ts +0 -10
  236. package/dist/service-descriptor.js +0 -71
  237. package/dist/service-model.d.ts +0 -49
  238. package/dist/service-model.js +0 -8
  239. package/dist/service-operations.d.ts +0 -29
  240. package/dist/service-operations.js +0 -48
  241. package/dist/service-readers.d.ts +0 -8
  242. package/dist/service-readers.js +0 -216
  243. package/dist/services-command.d.ts +0 -39
  244. package/dist/services-command.js +0 -96
  245. package/dist/ship.d.ts +0 -35
  246. package/dist/ship.js +0 -107
@@ -1,2 +0,0 @@
1
- import type { RecipeContext } from '../registry/types.js';
2
- export declare function scaffoldWebBilling({ root }: RecipeContext): void;
@@ -1,48 +0,0 @@
1
- import { put } from './files.js';
2
- export function scaffoldWebBilling({ root }) {
3
- put(root, 'apps/web/components/billing.tsx', WEB_BILLING);
4
- put(root, 'apps/web/app/account/page.tsx', `import { headers } from 'next/headers';
5
- import { redirect } from 'next/navigation';
6
- import { sessionSchema } from '@workspace/contracts';
7
- import { apiRequest } from '@/lib/server-api';
8
- import { SignOut } from '@/components/sign-out';
9
- import { Billing } from '@/components/billing';
10
- export default async function Account() {
11
- const incoming = await headers();
12
- const response = await apiRequest(new Request('https://app.internal/api/session', { headers: { cookie: incoming.get('cookie') ?? '' } }));
13
- if (response.status === 401) redirect('/sign-in');
14
- if (!response.ok) throw Error('Session verification is unavailable.');
15
- const { user } = sessionSchema.parse(await response.json());
16
- return <section className="stack"><h1>Account</h1><p>{user.email}</p><Billing key={user.id} /><SignOut /></section>;
17
- }
18
- `);
19
- }
20
- const WEB_BILLING = `'use client';
21
- import { useEffect, useRef, useState } from 'react';
22
- import { createBillingClient, type BillingIdentity, type BillingEntitlements } from '@workspace/contracts';
23
- import { Button } from '@/components/ui/button';
24
- const api = createBillingClient();
25
- function navigate(value: string) {
26
- const url = new URL(value);
27
- const invalid = [url.protocol !== 'https:', !['checkout.stripe.com', 'billing.stripe.com'].includes(url.hostname), url.username, url.password];
28
- if (invalid.some(Boolean)) throw Error('Unrecognized billing destination.');
29
- window.location.assign(url.href);
30
- }
31
- export function Billing() {
32
- const [identity, setIdentity] = useState<BillingIdentity | null>(null);
33
- const [entitlements, setEntitlements] = useState<BillingEntitlements | null>(null);
34
- const [pending, setPending] = useState(false); const [error, setError] = useState('');
35
- const intents = useRef(new Map<string, string>());
36
- useEffect(() => { let active = true; void Promise.all([api.identity(), api.entitlements()]).then(([user, access]) => { if (active) { setIdentity(user); setEntitlements(access); } }).catch(() => { if (active) setError('Unable to verify subscriptions.'); }); return () => { active = false; }; }, []);
37
- function checkoutIntent(plan: string) { const key = intents.current.get(plan) ?? crypto.randomUUID(); intents.current.set(plan, key); return key; }
38
- async function checkout(plan: string) {
39
- if (pending || !identity) return;
40
- setPending(true); setError('');
41
- // Keep one intent through uncertain retries. The server controls customer, price and return URL.
42
- const key = checkoutIntent(plan);
43
- try { navigate((await api.checkout(plan, key)).url); } catch { setError('Checkout is unavailable. Retry to resume the same checkout.'); } finally { setPending(false); }
44
- }
45
- async function portal() { if (pending || !identity) return; setPending(true); setError(''); try { navigate((await api.portal()).url); } catch { setError('Billing management is unavailable.'); } finally { setPending(false); } }
46
- return <section className="stack" aria-label="Subscription"><h2>Subscription</h2><p>{entitlements?.entitlements.some((grant) => grant.active) ? 'Active access' : 'No verified subscription'}</p>{identity?.providers.stripe && <>{identity.plans.map((plan) => <Button key={plan.id} disabled={pending} onClick={() => void checkout(plan.id)}>{plan.label}</Button>)}<Button disabled={pending} onClick={() => void portal()}>Manage web subscription</Button></>}<p role="status">{error}</p></section>;
47
- }
48
- `;
@@ -1,29 +0,0 @@
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;
@@ -1,195 +0,0 @@
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 (service.kind !== 'd1' ||
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
- }
@@ -1,10 +0,0 @@
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
- };
@@ -1,71 +0,0 @@
1
- import { inspectApplication } from './project-inspector.js';
2
- import { readApplication } from './project-state.js';
3
- const kinds = {
4
- D1: 'd1',
5
- R2: 'r2',
6
- };
7
- export function unboundResourceSelectors(inspection) {
8
- return inspection.cloudflareResources.data
9
- .filter((resource) => !inspection.configuration.data.bindings.some((binding) => kinds[binding.kind] === resource.kind &&
10
- (binding.resourceId === resource.id ||
11
- (resource.kind === 'r2' && binding.resourceId === resource.name))))
12
- .map((resource) => `receipt:${resource.kind}:${resource.id}`);
13
- }
14
- export function resolveService(root, key) {
15
- const inspection = inspectApplication(root);
16
- const project = readApplication(root);
17
- if (!project.accountId ||
18
- inspection.targets.state !== 'available' ||
19
- inspection.configuration.state !== 'available')
20
- throw new Error('Validated service configuration and a connected account are required.');
21
- const target = inspection.targets.data.find((item) => key === `target:${item.provider}:${item.id}` && item.provider === 'cloudflare' && !item.error);
22
- if (target) {
23
- const configured = project.targets.find((item) => item.directory === target.application);
24
- if (!configured)
25
- throw new Error('Service target identity changed.');
26
- return {
27
- key,
28
- kind: 'worker',
29
- id: configured.workerName,
30
- name: configured.workerName,
31
- accountId: project.accountId,
32
- projectId: project.id,
33
- applications: [target.application],
34
- ownership: 'unknown',
35
- };
36
- }
37
- const binding = inspection.configuration.data.bindings.find((item) => key === `binding:${item.application}:${item.kind}:${item.name}`);
38
- const record = inspection.cloudflareResources.data.find((item) => key === `receipt:${item.kind}:${item.id}`);
39
- const kind = binding ? kinds[binding.kind] : record?.kind;
40
- const id = binding?.resourceId ?? record?.id;
41
- if (!kind || !['d1', 'r2'].includes(kind) || !id || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,254}$/.test(id))
42
- throw new Error('This service has no supported provider resource identity.');
43
- const receipt = record ??
44
- inspection.cloudflareResources.data.find((item) => item.kind === kind && (item.id === id || (kind === 'r2' && item.name === id)));
45
- const references = inspection.configuration.data.bindings.filter((item) => kinds[item.kind] === kind &&
46
- (item.resourceId === id ||
47
- (receipt && [receipt.name, receipt.id].includes(item.resourceId ?? ''))));
48
- return {
49
- key,
50
- kind,
51
- id: receipt?.id ?? id,
52
- name: receipt?.name ?? (kind === 'r2' ? id : null),
53
- accountId: project.accountId,
54
- projectId: project.id,
55
- applications: [...new Set(references.map((item) => item.application))].sort(),
56
- ownership: inspection.cloudflareResources.state === 'available' &&
57
- (receipt?.createdByProject === true || receipt?.reused === false)
58
- ? 'created'
59
- : receipt?.reused === true
60
- ? 'reused'
61
- : 'unknown',
62
- };
63
- }
64
- export function serviceCapabilities(kind) {
65
- return {
66
- status: true,
67
- metrics: kind === 'd1' || kind === 'worker',
68
- data: kind === 'd1' || kind === 'r2',
69
- delete: kind === 'd1',
70
- };
71
- }
@@ -1,49 +0,0 @@
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' | 'r2';
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
- }
@@ -1,8 +0,0 @@
1
- export const SERVICE_TOOL_ACTIONS = {
2
- refresh_service: 'status',
3
- get_service_metrics: 'metrics',
4
- list_service_tables: 'tables',
5
- browse_service_data: 'data',
6
- plan_service_deletion: 'delete-plan',
7
- delete_service: 'delete',
8
- };
@@ -1,29 +0,0 @@
1
- import { type CloudflareRequest } from './cloudflare.js';
2
- import type { ServiceDeletionStore, DeletionPlan } from './service-deletion.js';
3
- import type { ServiceData, ServiceMetrics, ServiceObservation, ServiceAction } from './service-model.js';
4
- export interface ServiceOptions {
5
- hours?: number;
6
- table?: string;
7
- offset?: number;
8
- cursor?: string;
9
- token?: string;
10
- typedName?: string;
11
- }
12
- export interface ServiceResult {
13
- status?: ServiceObservation;
14
- metrics?: ServiceMetrics;
15
- tables?: string[];
16
- data?: ServiceData;
17
- plan?: DeletionPlan;
18
- deletion?: {
19
- state: 'deleted' | 'uncertain';
20
- resourceId: string;
21
- message: string;
22
- };
23
- }
24
- export type ServiceRequestFactory = (root: string, analytics: boolean) => Promise<CloudflareRequest>;
25
- /** Shared operations; transports decide how private results are presented. */
26
- export declare function serviceOperation(root: string, action: ServiceAction, key: string, options?: ServiceOptions, context?: {
27
- request?: ServiceRequestFactory;
28
- deletions?: ServiceDeletionStore;
29
- }): Promise<ServiceResult>;
@@ -1,48 +0,0 @@
1
- import { resolveIntegrationService, integrationRequest, observeIntegrationService, } from './integration-service-readers.js';
2
- import { browseR2Objects } from './r2-service-data.js';
3
- import { readApplication, defaultRunner, targetDirectory } from './project-state.js';
4
- import { cloudflareRequest } from './cloudflare.js';
5
- import { resolveService } from './service-descriptor.js';
6
- import { observeService, readServiceMetrics, listServiceTables, browseServiceData, } from './service-readers.js';
7
- const requestFor = async (root, analytics) => {
8
- const project = readApplication(root);
9
- return cloudflareRequest(project, targetDirectory(root, project.targets[0]), defaultRunner, { ...process.env, ANHEDRAL_COMMAND_TIMEOUT_MS: '10000' }, { analytics, timeoutMs: 10000 });
10
- };
11
- /** Shared operations; transports decide how private results are presented. */
12
- export async function serviceOperation(root, action, key, options = {}, context = {}) {
13
- if (key.startsWith('provider:') || key.startsWith('integration:')) {
14
- const service = resolveIntegrationService(root, key);
15
- const api = integrationRequest(service);
16
- if (action === 'status')
17
- return { status: await observeIntegrationService(service, api) };
18
- throw new Error('This integration does not support that operation.');
19
- }
20
- const service = resolveService(root, key);
21
- if (service.kind === 'r2' && action === 'tables')
22
- return { tables: ['objects'] };
23
- if (service.kind === 'r2' && action === 'data') {
24
- if (options.table !== 'objects')
25
- throw new Error('Choose object metadata.');
26
- return { data: await browseR2Objects(service, options.cursor) };
27
- }
28
- const request = await (context.request ?? requestFor)(root, action === 'metrics');
29
- if (action === 'status')
30
- return { status: await observeService(service, request) };
31
- if (action === 'metrics')
32
- return { metrics: await readServiceMetrics(service, request, options.hours ?? 24) };
33
- if (action === 'tables')
34
- return { tables: await listServiceTables(service, request) };
35
- if (action === 'data')
36
- return {
37
- data: await browseServiceData(service, request, options.table ?? '', options.offset ?? 0, 25, options.cursor),
38
- };
39
- if (!context.deletions)
40
- throw new Error('A deletion confirmation store is required.');
41
- if (action === 'delete-plan')
42
- return { plan: await context.deletions.plan(root, key, request) };
43
- if (!options.token || !options.typedName)
44
- throw new Error('Review a deletion plan and type the exact resource name.');
45
- return {
46
- deletion: await context.deletions.execute(root, key, options.token, options.typedName, request),
47
- };
48
- }
@@ -1,8 +0,0 @@
1
- import { type CloudflareRequest } from './cloudflare.js';
2
- import type { ServiceData, ServiceDescriptor, ServiceMetrics, ServiceObservation } from './service-model.js';
3
- export declare const serviceEndpoint: (service: ServiceDescriptor) => string;
4
- export declare function record(value: unknown): Record<string, unknown>;
5
- export declare function observeService(service: ServiceDescriptor, request: CloudflareRequest): Promise<ServiceObservation>;
6
- export declare function listServiceTables(service: ServiceDescriptor, request: CloudflareRequest): Promise<string[]>;
7
- export declare function browseServiceData(service: ServiceDescriptor, request: CloudflareRequest, table: string, offset?: number, limit?: number, cursor?: string): Promise<ServiceData>;
8
- export declare function readServiceMetrics(service: ServiceDescriptor, analytics: CloudflareRequest, hours?: number): Promise<ServiceMetrics>;