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,226 +0,0 @@
1
- const ORIGIN = 'https://api.cloudflare.com';
2
- const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
3
- export class CloudflareRequestError extends Error {
4
- status;
5
- constructor(message, status) {
6
- super(message);
7
- this.status = status;
8
- }
9
- }
10
- function object(value) {
11
- return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
12
- }
13
- function cancelBody(response) {
14
- try {
15
- void response.body?.cancel().catch(() => undefined);
16
- }
17
- catch {
18
- /* Best effort cancellation never exposes provider diagnostics. */
19
- }
20
- }
21
- async function boundedJson(response, signal) {
22
- if (signal.aborted) {
23
- cancelBody(response);
24
- throw new Error();
25
- }
26
- const reader = response.body?.getReader();
27
- if (!reader)
28
- throw new Error();
29
- const cancel = () => {
30
- void reader.cancel().catch(() => undefined);
31
- };
32
- signal.addEventListener('abort', cancel, { once: true });
33
- const chunks = [];
34
- let bytes = 0;
35
- try {
36
- for (;;) {
37
- const chunk = await reader.read();
38
- if (chunk.done)
39
- break;
40
- bytes += chunk.value.length;
41
- if (bytes > MAX_RESPONSE_BYTES || signal.aborted)
42
- throw new Error();
43
- chunks.push(chunk.value);
44
- }
45
- return JSON.parse(Buffer.concat(chunks).toString('utf8'));
46
- }
47
- catch {
48
- cancel();
49
- throw new Error();
50
- }
51
- finally {
52
- signal.removeEventListener('abort', cancel);
53
- reader.releaseLock();
54
- }
55
- }
56
- function responseInfo(value) {
57
- if (value === undefined || value === null)
58
- return undefined;
59
- if (!object(value))
60
- throw new Error('Cloudflare returned unsupported pagination.');
61
- const info = {};
62
- if (value.cursor !== undefined) {
63
- if (typeof value.cursor !== 'string' ||
64
- value.cursor.length > 4096 ||
65
- /[\x00-\x1f\x7f]/.test(value.cursor))
66
- throw new Error('Cloudflare returned an invalid pagination cursor.');
67
- info.cursor = value.cursor;
68
- }
69
- for (const field of ['page', 'total_pages', 'count', 'per_page']) {
70
- const entry = value[field];
71
- if (entry !== undefined) {
72
- if (typeof entry !== 'number' || !Number.isSafeInteger(entry) || entry < 0)
73
- throw new Error('Cloudflare returned unsupported pagination.');
74
- info[field] = entry;
75
- }
76
- }
77
- return info;
78
- }
79
- /** Credentials stay in this closure. Fixed account paths, bounded response reads and
80
- * a whole-request deadline apply to reads and mutations; mutations never retry. */
81
- export async function cloudflareRequest(project, directory, run, env, options = {}) {
82
- const account = project.accountId;
83
- if (typeof account !== 'string' || !/^[a-f0-9]{32}$/.test(account))
84
- throw new Error('Select a valid Cloudflare account before provider requests.');
85
- const timeoutMs = options.timeoutMs ?? 30_000;
86
- if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 30_000)
87
- throw new Error('Invalid bounded Cloudflare request deadline.');
88
- const send = options.send ?? fetch;
89
- let credentials;
90
- try {
91
- const raw = await run('pnpm', ['exec', 'wrangler', 'auth', 'token', '--json'], directory, env);
92
- if (Buffer.byteLength(raw) > 64 * 1024)
93
- throw new Error();
94
- credentials = JSON.parse(raw);
95
- }
96
- catch {
97
- throw new Error('Cannot retrieve structured Wrangler credentials; update Wrangler and check authentication.');
98
- }
99
- if (!object(credentials) ||
100
- typeof credentials.type !== 'string' ||
101
- !['oauth', 'api_token'].includes(credentials.type) ||
102
- typeof credentials.token !== 'string' ||
103
- !/^[\x21-\x7e]{1,16384}$/.test(credentials.token))
104
- throw new Error('Cloudflare operations require scoped API-token or Wrangler OAuth access.');
105
- const token = credentials.token;
106
- const prefix = `/client/v4/accounts/${account}`;
107
- return async (method, endpoint, body) => {
108
- let url;
109
- try {
110
- if (typeof endpoint !== 'string')
111
- throw new Error();
112
- const decodedPath = decodeURIComponent(endpoint.split('?')[0]);
113
- if (!['GET', 'POST', 'DELETE'].includes(method) ||
114
- endpoint.length > 4096 ||
115
- !endpoint.startsWith('/') ||
116
- endpoint.startsWith('//') ||
117
- /[\x00-\x20\x7f#\\]/.test(endpoint) ||
118
- decodedPath.includes('..') ||
119
- /[\x00-\x20\x7f#\\%]/.test(decodedPath))
120
- throw new Error();
121
- if (options.analytics) {
122
- if (endpoint !== '/graphql' ||
123
- method !== 'POST' ||
124
- !object(body) ||
125
- !object(body.variables) ||
126
- body.variables.accountTag !== account)
127
- throw new Error();
128
- url = new URL('/client/v4/graphql', ORIGIN);
129
- }
130
- else {
131
- url = new URL(`${prefix}${endpoint}`, ORIGIN);
132
- if (url.origin !== ORIGIN || !url.pathname.startsWith(`${prefix}/`))
133
- throw new Error();
134
- }
135
- }
136
- catch {
137
- throw new Error('Invalid account-scoped provider request.');
138
- }
139
- const controller = new AbortController();
140
- let timer;
141
- const timeout = new Promise((_resolve, reject) => {
142
- timer = setTimeout(() => {
143
- controller.abort();
144
- reject(new Error('Cloudflare request deadline exceeded; inspect remote status before retrying.'));
145
- }, timeoutMs);
146
- });
147
- try {
148
- return await Promise.race([
149
- (async () => {
150
- let response;
151
- try {
152
- response = await send(url.href, {
153
- method,
154
- headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
155
- body: body === undefined ? undefined : JSON.stringify(body),
156
- redirect: 'error',
157
- signal: controller.signal,
158
- });
159
- }
160
- catch {
161
- throw new Error('Cloudflare request failed; check connectivity and account permissions.');
162
- }
163
- let data;
164
- try {
165
- data = await boundedJson(response, controller.signal);
166
- }
167
- catch {
168
- throw new Error(`Cloudflare returned unsupported output (HTTP ${response.status}).`);
169
- }
170
- if (!object(data))
171
- throw new Error(`Cloudflare returned unsupported output (HTTP ${response.status}).`);
172
- if (!response.ok ||
173
- (options.analytics
174
- ? data.errors != null && (!Array.isArray(data.errors) || data.errors.length > 0)
175
- : data.success !== true)) {
176
- const codes = Array.isArray(data.errors)
177
- ? data.errors
178
- .slice(0, 20)
179
- .filter(object)
180
- .map((item) => item.code)
181
- .filter((code) => typeof code === 'number' &&
182
- Number.isSafeInteger(code) &&
183
- code >= 0 &&
184
- code <= 1_000_000)
185
- .join(',')
186
- : '';
187
- throw new CloudflareRequestError(`Cloudflare operation failed (HTTP ${response.status}${codes ? `; codes ${codes}` : ''}). Check scoped permissions and service eligibility; no paid plan is activated automatically.`, response.status);
188
- }
189
- if (options.analytics)
190
- return { result: data.data };
191
- if (!Object.hasOwn(data, 'result'))
192
- throw new Error('Cloudflare returned no operation result.');
193
- return { result: data.result, result_info: responseInfo(data.result_info) };
194
- })(),
195
- timeout,
196
- ]);
197
- }
198
- finally {
199
- clearTimeout(timer);
200
- }
201
- };
202
- }
203
- export async function listCloudflare(request, endpoint) {
204
- const result = [];
205
- let bytes = 0;
206
- for (let page = 1; page <= 1000; page++) {
207
- const response = await request('GET', `${endpoint}${endpoint.includes('?') ? '&' : '?'}page=${page}&per_page=100`);
208
- if (!Array.isArray(response.result) ||
209
- response.result.length > 100 ||
210
- response.result.some((item) => !object(item)))
211
- throw new Error('Unsupported provider resource list.');
212
- try {
213
- bytes += Buffer.byteLength(JSON.stringify(response.result));
214
- }
215
- catch {
216
- throw new Error('Unsupported provider resource list.');
217
- }
218
- if (result.length + response.result.length > 10_000 || bytes > 10 * 1024 * 1024)
219
- throw new Error('Provider resource listing exceeded its collection limit.');
220
- result.push(...response.result);
221
- const info = responseInfo(response.result_info);
222
- if (info?.total_pages !== undefined ? page >= info.total_pages : response.result.length < 100)
223
- return result;
224
- }
225
- throw new Error('Provider resource listing exceeded pagination limit.');
226
- }
@@ -1,62 +0,0 @@
1
- import { type CloudflareRequest } from './cloudflare.js';
2
- import { defaultRunner, type ApplicationProject, type DeploymentTarget } from './project-state.js';
3
- export interface TargetRelease {
4
- target: string;
5
- versionId: string;
6
- urls: string[];
7
- providerConfirmed: boolean;
8
- }
9
- export interface Release {
10
- id: string;
11
- commit: string;
12
- startedAt: string;
13
- finishedAt?: string;
14
- state: 'running' | 'checked' | 'deployed' | 'configuration-required' | 'failed';
15
- targets: TargetRelease[];
16
- failure?: string;
17
- configurationChanges?: string[];
18
- operation?: 'ship' | 'rollback';
19
- restoredReleaseId?: string;
20
- verification?: {
21
- state: 'passed' | 'failed';
22
- checkedAt: string;
23
- command: 'pnpm run test:live';
24
- };
25
- }
26
- export interface ReleaseHistory {
27
- schemaVersion: 1;
28
- projectId: string;
29
- releases: Release[];
30
- }
31
- export declare function history(root: string, project: ApplicationProject): ReleaseHistory;
32
- export declare function checkTargets(root: string, project: ApplicationProject, allowResourcePlaceholders?: boolean): void;
33
- export declare function configurationFingerprint(root: string, project: ApplicationProject): string;
34
- export declare function planDelivery(root: string, allowResourcePlaceholders?: boolean): {
35
- project: ApplicationProject;
36
- checks: string[][];
37
- deployments: {
38
- target: string;
39
- directory: string;
40
- command: string[];
41
- }[];
42
- resourcesProvisioned: boolean;
43
- audience: "unconfigured" | "public" | "private";
44
- };
45
- export declare function parseDeploymentOutput(source: string, target: DeploymentTarget): TargetRelease;
46
- export interface ActiveVersion {
47
- versionId: string;
48
- percentage: number;
49
- }
50
- export declare function activeVersions(value: unknown): ActiveVersion[];
51
- export declare function providerStatus(root: string, project: ApplicationProject, target: DeploymentTarget, run: typeof defaultRunner, _request?: CloudflareRequest): Promise<unknown>;
52
- export declare function fullyActive(versions: ActiveVersion[], versionId: string): boolean;
53
- export declare function describeArchitecture(root: string, project: ApplicationProject): {
54
- target: string;
55
- workerName: string;
56
- directory: string;
57
- bindings: {
58
- kind: string;
59
- binding: string;
60
- }[];
61
- scheduled: string[];
62
- }[];
@@ -1,157 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { existsSync, readFileSync } from 'node:fs';
3
- import path from 'node:path';
4
- import { projectConfigPath } from './project-config.js';
5
- import {} from './cloudflare.js';
6
- import { configurationFile, defaultRunner, environment, readApplication, readConfig, targetDirectory, } from './project-state.js';
7
- const stateDirectory = '.anhedral';
8
- export function history(root, project) {
9
- const file = path.join(root, stateDirectory, 'releases.json');
10
- if (!existsSync(file))
11
- return { schemaVersion: 1, projectId: project.id, releases: [] };
12
- const value = JSON.parse(readFileSync(file, 'utf8'));
13
- if (value.schemaVersion !== 1 || value.projectId !== project.id || !Array.isArray(value.releases))
14
- throw new Error('Release history belongs to a different or unsupported project.');
15
- return value;
16
- }
17
- export function checkTargets(root, project, allowResourcePlaceholders = false) {
18
- if (!project.targets.length)
19
- throw new Error('No Cloudflare targets; native applications require their platform delivery tools.');
20
- for (const target of project.targets) {
21
- const directory = targetDirectory(root, target);
22
- const config = readConfig(directory);
23
- if (config.name !== target.workerName ||
24
- (config.env && Object.keys(config.env).length))
25
- throw new Error('Worker name or environment changed; reconcile the application manifest before shipping.');
26
- if (config.account_id && config.account_id !== project.accountId)
27
- throw new Error('Wrangler configuration account conflicts with the registered account.');
28
- const pending = structuredClone(config);
29
- if (allowResourcePlaceholders) {
30
- for (const [field, id] of [['d1_databases', 'database_id']]) {
31
- const entries = pending[field];
32
- if (Array.isArray(entries))
33
- for (const entry of entries) {
34
- if (entry && typeof entry[id] === 'string' && entry[id].startsWith('REPLACE_WITH_'))
35
- entry[id] = 'pending-resource';
36
- }
37
- }
38
- }
39
- if (/REPLACE_WITH_|YOUR_[A-Z_]+/.test(allowResourcePlaceholders
40
- ? JSON.stringify(pending)
41
- : readFileSync(configurationFile(directory), 'utf8')))
42
- throw new Error('Configure selected resources before shipping; placeholder bindings remain.');
43
- const pkg = JSON.parse(readFileSync(path.join(directory, 'package.json'), 'utf8'));
44
- if (typeof pkg.scripts?.deploy !== 'string')
45
- throw new Error('Deployment target has no deploy script.');
46
- }
47
- }
48
- export function configurationFingerprint(root, project) {
49
- const hash = createHash('sha256').update(readFileSync(projectConfigPath(root)));
50
- for (const target of project.targets) {
51
- const directory = targetDirectory(root, target);
52
- hash.update(readFileSync(configurationFile(directory)));
53
- }
54
- return hash.digest('hex');
55
- }
56
- export function planDelivery(root, allowResourcePlaceholders = false) {
57
- const project = readApplication(root);
58
- checkTargets(root, project, allowResourcePlaceholders);
59
- return {
60
- project,
61
- checks: [['pnpm', 'run', 'check']],
62
- deployments: project.targets.map((target) => ({
63
- target: target.id,
64
- directory: target.directory,
65
- command: ['pnpm', 'run', 'deploy'],
66
- })),
67
- resourcesProvisioned: false,
68
- audience: project.audience,
69
- };
70
- }
71
- export function parseDeploymentOutput(source, target) {
72
- const entries = source
73
- .split('\n')
74
- .filter((line) => line.trim())
75
- .map((line) => JSON.parse(line));
76
- const deploy = entries.findLast((entry) => entry.type === 'deploy' && entry.version === 1 && entry.worker_name === target.workerName);
77
- if (!deploy || typeof deploy.version_id !== 'string' || !deploy.version_id)
78
- throw new Error('No matching structured Wrangler deployment receipt. Deployment may have occurred; inspect provider status before retrying.');
79
- const urls = Array.isArray(deploy.targets)
80
- ? deploy.targets.filter((url) => {
81
- if (typeof url !== 'string')
82
- return false;
83
- try {
84
- const value = new URL(url);
85
- return value.protocol === 'https:' && !value.username && !value.password;
86
- }
87
- catch {
88
- return false;
89
- }
90
- })
91
- : [];
92
- return { target: target.id, versionId: deploy.version_id, urls, providerConfirmed: false };
93
- }
94
- export function activeVersions(value) {
95
- if (!value || typeof value !== 'object')
96
- return [];
97
- const record = value;
98
- // Read only the active deployment's versions, never arbitrary historical IDs.
99
- if (!Array.isArray(record.versions))
100
- throw new Error('Unsupported provider deployment status; active versions are missing.');
101
- const versions = record.versions
102
- .map((entry) => {
103
- if (!entry || typeof entry !== 'object')
104
- throw new Error('Invalid provider version.');
105
- const item = entry;
106
- if (typeof item.version_id !== 'string' ||
107
- !item.version_id ||
108
- typeof item.percentage !== 'number' ||
109
- !Number.isFinite(item.percentage) ||
110
- item.percentage < 0 ||
111
- item.percentage > 100)
112
- throw new Error('Invalid provider traffic allocation.');
113
- return { versionId: item.version_id, percentage: item.percentage };
114
- })
115
- .filter((entry) => entry.percentage > 0);
116
- if (new Set(versions.map((entry) => entry.versionId)).size !== versions.length ||
117
- Math.abs(versions.reduce((sum, entry) => sum + entry.percentage, 0) - 100) > 0.001)
118
- throw new Error('Invalid provider traffic allocation.');
119
- return versions;
120
- }
121
- export async function providerStatus(root, project, target, run, _request) {
122
- return JSON.parse(await run('pnpm', ['exec', 'wrangler', 'deployments', 'status', '--json'], targetDirectory(root, target), environment(project)));
123
- }
124
- export function fullyActive(versions, versionId) {
125
- return (versions.length === 1 && versions[0].versionId === versionId && versions[0].percentage === 100);
126
- }
127
- export function describeArchitecture(root, project) {
128
- return project.targets.map((target) => {
129
- const config = readConfig(targetDirectory(root, target));
130
- const bindings = [];
131
- for (const kind of [
132
- 'd1_databases',
133
- 'r2_buckets',
134
- 'kv_namespaces',
135
- 'hyperdrive',
136
- 'services',
137
- 'workflows',
138
- ]) {
139
- const entries = config[kind];
140
- if (Array.isArray(entries))
141
- for (const entry of entries)
142
- if (typeof entry?.binding === 'string')
143
- bindings.push({ kind, binding: entry.binding });
144
- }
145
- return {
146
- target: target.id,
147
- workerName: target.workerName,
148
- directory: target.directory,
149
- bindings,
150
- scheduled: typeof config.triggers === 'object' &&
151
- config.triggers !== null &&
152
- Array.isArray(config.triggers.crons)
153
- ? config.triggers.crons.filter((cron) => typeof cron === 'string')
154
- : [],
155
- };
156
- });
157
- }
@@ -1,82 +0,0 @@
1
- import { type Release, type ActiveVersion } from './delivery-evidence.js';
2
- export { planDelivery, parseDeploymentOutput } from './delivery-evidence.js';
3
- export type { Release } from './delivery-evidence.js';
4
- import { type CloudflareRequest } from './cloudflare.js';
5
- import { type ApplicationProject } from './project-state.js';
6
- export { registerApplication, readApplication, defaultRunner, environment, targetDirectory, } from './project-state.js';
7
- export type { ApplicationProject, DeploymentTarget, DeliveryRunner } from './project-state.js';
8
- export declare function connectApplication(root: string, accountId: string | undefined, audience: 'public' | 'private' | undefined, run?: import("./project-state.js").DeliveryRunner, emails?: string[]): Promise<ApplicationProject>;
9
- export declare function shipApplication(root: string, run?: import("./project-state.js").DeliveryRunner, suppliedRequest?: CloudflareRequest): Promise<{
10
- projectId: string;
11
- release: Release;
12
- managementFile: string;
13
- productVerification: string;
14
- management: string;
15
- }>;
16
- export declare function applicationStatus(root: string, refresh?: boolean, run?: import("./project-state.js").DeliveryRunner): Promise<{
17
- project: ApplicationProject;
18
- access: import("./access.js").AccessReceipt[] | undefined;
19
- architecture: {
20
- target: string;
21
- workerName: string;
22
- directory: string;
23
- bindings: {
24
- kind: string;
25
- binding: string;
26
- }[];
27
- scheduled: string[];
28
- }[];
29
- releases: Release[];
30
- provider: {
31
- target: string;
32
- activeRecordedVersion: boolean;
33
- versions: ActiveVersion[];
34
- }[];
35
- evidence: string;
36
- productVerification: string;
37
- management: string | null;
38
- }>;
39
- export declare function verifyApplication(root: string, run?: import("./project-state.js").DeliveryRunner): Promise<{
40
- projectId: string;
41
- releaseId: string;
42
- verification: {
43
- state: "passed" | "failed";
44
- checkedAt: string;
45
- command: "pnpm run test:live";
46
- };
47
- managementFile: string;
48
- }>;
49
- export declare function rollbackApplication(root: string, releaseId: string, dataCompatible: boolean, run?: import("./project-state.js").DeliveryRunner, suppliedRequest?: CloudflareRequest): Promise<{
50
- projectId: string;
51
- release: Release;
52
- managementFile: string;
53
- productVerification: string;
54
- dataRestored: boolean;
55
- }>;
56
- /** Recover current provider evidence, never fabricate a historical release or source-to-version mapping. */
57
- export declare function recoverApplication(root: string, run?: import("./project-state.js").DeliveryRunner, suppliedRequest?: CloudflareRequest): Promise<{
58
- schemaVersion: number;
59
- projectId: string;
60
- accountId: string | null;
61
- checkedAt: string;
62
- evidence: string;
63
- localCommit: string;
64
- sourceProvenance: string;
65
- replayableReleaseId: string | null;
66
- productVerification: string;
67
- provider: {
68
- target: string;
69
- versions: ActiveVersion[];
70
- bindingsConfirmed: boolean;
71
- }[];
72
- resources: {
73
- kind: string;
74
- name: string;
75
- id: string;
76
- target: string;
77
- }[];
78
- access: import("./access.js").AccessReceipt[] | undefined;
79
- audience: "public" | "private";
80
- audienceEvidence: string;
81
- limitations: string[];
82
- }>;