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,216 +0,0 @@
1
- import { CloudflareRequestError } from './cloudflare.js';
2
- export const serviceEndpoint = (service) => {
3
- const id = encodeURIComponent(service.kind === 'r2' ? (service.name ?? service.id) : service.id);
4
- return {
5
- d1: `/d1/database/${id}`,
6
- r2: `/r2/buckets/${id}`,
7
- worker: `/workers/scripts/${id}/settings`,
8
- }[service.kind];
9
- };
10
- export function record(value) {
11
- if (!value || typeof value !== 'object' || Array.isArray(value))
12
- throw new Error('Unsupported service response.');
13
- return value;
14
- }
15
- export async function observeService(service, request) {
16
- const fetchedAt = new Date().toISOString();
17
- try {
18
- const value = record((await request('GET', serviceEndpoint(service))).result);
19
- const id = service.kind === 'd1' ? value.uuid : undefined;
20
- if (service.kind !== 'worker' && service.kind !== 'r2' && id !== service.id)
21
- throw new Error('Provider resource identity differs from the source.');
22
- const name = value.name ?? value.title ?? value.queue_name;
23
- if (name !== undefined &&
24
- (typeof name !== 'string' ||
25
- name.length > 256 ||
26
- (service.name !== null && name !== service.name)))
27
- throw new Error('Provider resource name differs from the source.');
28
- return {
29
- state: 'available',
30
- fetchedAt,
31
- ...(typeof name === 'string' ? { name } : {}),
32
- ...(service.kind === 'd1' &&
33
- typeof value.file_size === 'number' &&
34
- Number.isSafeInteger(value.file_size) &&
35
- value.file_size >= 0
36
- ? { storageBytes: value.file_size }
37
- : {}),
38
- message: 'Provider confirmed this resource exists. Application health is separate.',
39
- };
40
- }
41
- catch (error) {
42
- const status = error instanceof CloudflareRequestError ? error.status : undefined;
43
- return {
44
- state: status === 404
45
- ? 'not-found'
46
- : status === 401 || status === 403
47
- ? 'permission-required'
48
- : 'unavailable',
49
- fetchedAt,
50
- message: status === 404
51
- ? 'Resource not found in the selected account.'
52
- : status === 401 || status === 403
53
- ? 'Sign in with the required resource-read permissions.'
54
- : 'Service could not be verified. Check identity, connectivity, and provider availability.',
55
- };
56
- }
57
- }
58
- async function d1Query(service, request, sql, params = []) {
59
- const value = (await request('POST', `${serviceEndpoint(service)}/query`, { sql, params }))
60
- .result;
61
- if (!Array.isArray(value) || value.length !== 1)
62
- throw new Error('Unsupported database response.');
63
- const result = record(value[0]);
64
- const meta = record(result.meta ?? {});
65
- if (result.success !== true ||
66
- meta.changed_db === true ||
67
- (typeof meta.changes === 'number' && meta.changes !== 0))
68
- throw new Error('Read-only data operation did not complete safely.');
69
- if (!Array.isArray(result.results) || result.results.length > 1001)
70
- throw new Error('Database output exceeded its row limit.');
71
- return result.results.map(record);
72
- }
73
- export async function listServiceTables(service, request) {
74
- if (service.kind !== 'd1')
75
- throw new Error('Schema browsing is supported for D1 databases.');
76
- const rows = await d1Query(service, request, "SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT GLOB 'sqlite_*' AND name NOT GLOB '_cf_*' ORDER BY name LIMIT 1001");
77
- if (rows.length > 1000)
78
- throw new Error('Database schema exceeds its table limit.');
79
- return rows.map((row) => {
80
- if (typeof row.name !== 'string' || !/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(row.name))
81
- throw new Error('Unsupported table identifier.');
82
- return row.name;
83
- });
84
- }
85
- export async function browseServiceData(service, request, table, offset = 0, limit = 25, cursor) {
86
- if (!Number.isSafeInteger(offset) ||
87
- offset < 0 ||
88
- offset > 10_000 ||
89
- !Number.isInteger(limit) ||
90
- limit < 1 ||
91
- limit > 100)
92
- throw new Error('Choose a bounded data page.');
93
- if (cursor !== undefined && (cursor.length > 4096 || /[\x00-\x1f\x7f]/.test(cursor)))
94
- throw new Error('Choose a bounded metadata cursor.');
95
- if (cursor !== undefined)
96
- throw new Error('Database pages use offsets, not metadata cursors.');
97
- if (service.kind !== 'd1' ||
98
- !/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(table) ||
99
- !(await listServiceTables(service, request)).includes(table))
100
- throw new Error('Choose an existing supported database table.');
101
- const fields = await d1Query(service, request, `PRAGMA table_info("${table}")`);
102
- if (!fields.length || fields.length > 50)
103
- throw new Error('Table exceeds its supported column limit.');
104
- const columns = fields.map((field) => {
105
- if (typeof field.name !== 'string' || !/^[a-zA-Z_][a-zA-Z0-9_]{0,127}$/.test(field.name))
106
- throw new Error('Unsupported database column.');
107
- return field.name;
108
- });
109
- const sensitive = /password|secret|token|email|phone|address|authorization|cookie|session|private|credential/i;
110
- const projection = columns
111
- .map((column) => sensitive.test(column)
112
- ? `'[masked]' AS "${column}"`
113
- : `CASE WHEN typeof("${column}") IN ('text', 'blob') THEN substr(CAST("${column}" AS TEXT), 1, 1000) ELSE "${column}" END AS "${column}"`)
114
- .join(', ');
115
- const ordering = columns.map((_, index) => index + 1).join(', ');
116
- const rows = await d1Query(service, request, `SELECT ${projection} FROM "${table}" ORDER BY ${ordering} LIMIT ? OFFSET ?`, [limit + 1, offset]);
117
- let masked = columns.some((column) => sensitive.test(column));
118
- const outputRows = rows.slice(0, limit).map((row) => columns.map((column) => {
119
- const value = row[column];
120
- if (sensitive.test(column)) {
121
- masked = true;
122
- return '[masked]';
123
- }
124
- if (value === null || typeof value === 'boolean' || typeof value === 'number')
125
- return value;
126
- if (typeof value === 'string') {
127
- if (/^(?:sk[-_]|rk[-_]|whsec[-_]|Bearer )/i.test(value)) {
128
- masked = true;
129
- return '[masked]';
130
- }
131
- return value.slice(0, 1000);
132
- }
133
- return '[complex value]';
134
- }));
135
- return {
136
- fetchedAt: new Date().toISOString(),
137
- columns,
138
- offset,
139
- hasMore: rows.length > limit,
140
- masked,
141
- rows: outputRows,
142
- };
143
- }
144
- export async function readServiceMetrics(service, analytics, hours = 24) {
145
- if (![1, 24, 168].includes(hours) ||
146
- !['worker', 'd1'].includes(service.kind) ||
147
- (service.kind === 'd1' && hours === 1))
148
- throw new Error('Unsupported service or analytics window.');
149
- const worker = service.kind === 'worker';
150
- const end = worker
151
- ? new Date().toISOString()
152
- : new Date(new Date().toISOString().slice(0, 10) + 'T00:00:00.000Z').toISOString();
153
- const start = new Date(Date.parse(end) - hours * 3600000).toISOString();
154
- const query = worker
155
- ? `query($accountTag: string!, $id: string!, $start: string!, $end: string!) { viewer { accounts(filter: {accountTag: $accountTag}) { workersInvocationsAdaptive(limit: 1000, filter: {scriptName: $id, datetime_geq: $start, datetime_leq: $end}) { dimensions { datetime scriptName } sum { requests errors } quantiles { cpuTimeP50 cpuTimeP99 } } } } }`
156
- : `query($accountTag: string!, $id: string!, $start: Date!, $end: Date!) { viewer { accounts(filter: {accountTag: $accountTag}) { d1AnalyticsAdaptiveGroups(limit: 1000, filter: {databaseId: $id, date_geq: $start, date_leq: $end}, orderBy: [date_ASC]) { dimensions { date databaseId } sum { readQueries writeQueries } quantiles { queryBatchTimeMsP90 } } } } }`;
157
- const response = record((await analytics('POST', '/graphql', {
158
- query,
159
- variables: {
160
- accountTag: service.accountId,
161
- id: service.id,
162
- start: worker ? start : start.slice(0, 10),
163
- end: worker ? end : new Date(Date.parse(end) - 1).toISOString().slice(0, 10),
164
- },
165
- })).result);
166
- const accounts = record(response.viewer).accounts;
167
- if (!Array.isArray(accounts) || accounts.length !== 1)
168
- throw new Error('Analytics account response is unavailable.');
169
- const rows = record(accounts[0])[worker ? 'workersInvocationsAdaptive' : 'd1AnalyticsAdaptiveGroups'];
170
- if (!Array.isArray(rows) || rows.length >= 1000)
171
- throw new Error('Analytics is truncated or unavailable; choose a smaller window.');
172
- const names = worker ? ['requests', 'errors'] : ['readQueries', 'writeQueries'];
173
- const points = rows
174
- .map((entry) => {
175
- const value = record(entry);
176
- const dimensions = record(value.dimensions);
177
- const sum = record(value.sum);
178
- if (dimensions[worker ? 'scriptName' : 'databaseId'] !== service.id)
179
- throw new Error('Analytics resource identity differs from the selection.');
180
- const time = dimensions[worker ? 'datetime' : 'date'];
181
- if (typeof time !== 'string' ||
182
- !Number.isFinite(Date.parse(time)) ||
183
- Date.parse(time) < Date.parse(start) ||
184
- Date.parse(time) > Date.parse(end))
185
- throw new Error('Invalid analytics time.');
186
- const values = {};
187
- for (const name of names) {
188
- if (typeof sum[name] !== 'number' || !Number.isFinite(sum[name]) || Number(sum[name]) < 0)
189
- throw new Error('Invalid analytics count.');
190
- values[name] = Number(sum[name]);
191
- }
192
- const quantiles = record(value.quantiles ?? {});
193
- for (const name of worker ? ['cpuTimeP50', 'cpuTimeP99'] : ['queryBatchTimeMsP90'])
194
- if (typeof quantiles[name] === 'number' &&
195
- Number.isFinite(quantiles[name]) &&
196
- Number(quantiles[name]) >= 0)
197
- values[name] = Number(quantiles[name]);
198
- return { time, values };
199
- })
200
- .sort((a, b) => a.time.localeCompare(b.time));
201
- return {
202
- fetchedAt: new Date().toISOString(),
203
- start,
204
- end,
205
- timezone: 'UTC',
206
- source: worker ? 'Cloudflare Workers GraphQL' : 'Cloudflare D1 GraphQL (daily buckets)',
207
- sampled: true,
208
- points,
209
- units: {
210
- ...Object.fromEntries(names.map((name) => [name, 'count'])),
211
- ...(worker
212
- ? { cpuTimeP50: 'microseconds', cpuTimeP99: 'microseconds' }
213
- : { queryBatchTimeMsP90: 'milliseconds' }),
214
- },
215
- };
216
- }
@@ -1,39 +0,0 @@
1
- export declare function runServiceCommand(root: string, input: string[]): Promise<string[] | import("./service-model.js").ServiceObservation | import("./service-model.js").ServiceMetrics | import("./service-model.js").ServiceData | import("./service-deletion.js").DeletionPlan | {
2
- state: "deleted" | "uncertain";
3
- resourceId: string;
4
- message: string;
5
- } | {
6
- services: ({
7
- key: string;
8
- provider: keyof import("./index.js").ProviderSettingsById;
9
- capabilities: {
10
- status: boolean;
11
- metrics: boolean;
12
- data: boolean;
13
- delete: boolean;
14
- };
15
- state?: undefined;
16
- } | {
17
- capabilities: {
18
- status: boolean;
19
- metrics: boolean;
20
- data: boolean;
21
- delete: boolean;
22
- };
23
- key: string;
24
- kind: import("./service-model.js").ServiceKind;
25
- id: string;
26
- name: string | null;
27
- accountId: string;
28
- projectId: string;
29
- applications: string[];
30
- ownership: "created" | "reused" | "unknown";
31
- provider?: undefined;
32
- state?: undefined;
33
- } | {
34
- key: string;
35
- capabilities: null;
36
- state: string;
37
- provider?: undefined;
38
- })[];
39
- } | undefined>;
@@ -1,96 +0,0 @@
1
- import path from 'node:path';
2
- import { CliArgumentError } from './cli-arguments.js';
3
- import { resolveIntegrationService } from './integration-service-readers.js';
4
- import { inspectApplication } from './project-inspector.js';
5
- import { resolveService, serviceCapabilities, unboundResourceSelectors, } from './service-descriptor.js';
6
- import { ServiceDeletionStore } from './service-deletion.js';
7
- import { catalogDirectory } from './catalog-registration.js';
8
- import { serviceOperation } from './service-operations.js';
9
- const argumentError = (message) => new CliArgumentError(message, 'Run anhedral services --help.');
10
- export async function runServiceCommand(root, input) {
11
- const args = input.filter((arg) => arg !== '--json');
12
- const action = args.shift();
13
- const actions = ['list', 'status', 'metrics', 'tables', 'data', 'delete-plan', 'delete'];
14
- if (!action || !actions.includes(action))
15
- throw argumentError('Choose a supported services operation.');
16
- if (action === 'list') {
17
- if (args.length)
18
- throw argumentError('services list accepts no service selector.');
19
- const inspection = inspectApplication(root);
20
- const keys = [
21
- ...inspection.setupProviders.data
22
- .filter((provider) => !['cloudflare', 'expo'].includes(provider.id))
23
- .map((provider) => `provider:${provider.id}`),
24
- ...inspection.integrations.data.flatMap((provider) => provider.operations.map((operation) => `integration:${provider.provider}:${operation.operation}`)),
25
- ...inspection.targets.data.map((target) => `target:${target.provider}:${target.id}`),
26
- ...inspection.configuration.data.bindings.map((binding) => `binding:${binding.application}:${binding.kind}:${binding.name}`),
27
- ...unboundResourceSelectors(inspection),
28
- ];
29
- return {
30
- services: keys.map((key) => {
31
- try {
32
- if (key.startsWith('provider:') || key.startsWith('integration:')) {
33
- const service = resolveIntegrationService(root, key);
34
- return {
35
- key,
36
- provider: service.provider,
37
- capabilities: {
38
- status: true,
39
- metrics: false,
40
- data: false,
41
- delete: false,
42
- },
43
- };
44
- }
45
- const service = resolveService(root, key);
46
- return { ...service, capabilities: serviceCapabilities(service.kind) };
47
- }
48
- catch {
49
- return { key, capabilities: null, state: 'unsupported-or-unconfigured' };
50
- }
51
- }),
52
- };
53
- }
54
- const key = args.shift();
55
- if (!key || key.startsWith('-') || key.length > 1024)
56
- throw argumentError('Choose the exact service key from services list.');
57
- const options = {};
58
- for (let i = 0; i < args.length; i += 2) {
59
- if (!['--hours', '--table', '--offset', '--token', '--confirm-name', '--cursor'].includes(args[i]) ||
60
- options[args[i]] !== undefined ||
61
- !args[i + 1] ||
62
- args[i + 1].startsWith('-'))
63
- throw argumentError('Invalid services options.');
64
- options[args[i]] = args[i + 1];
65
- }
66
- const allowed = {
67
- status: [],
68
- metrics: ['--hours'],
69
- tables: [],
70
- data: ['--table', '--offset', '--cursor'],
71
- 'delete-plan': [],
72
- delete: ['--token', '--confirm-name'],
73
- };
74
- if (Object.keys(options).some((option) => !allowed[action].includes(option)))
75
- throw argumentError('This services operation does not accept that option.');
76
- if (action === 'delete' && (!options['--token'] || !options['--confirm-name']))
77
- throw argumentError('Deletion requires its plan token and exact resource name.');
78
- const result = await serviceOperation(root, action, key, {
79
- hours: options['--hours'] === undefined ? undefined : Number(options['--hours']),
80
- table: options['--table'],
81
- offset: options['--offset'] === undefined ? undefined : Number(options['--offset']),
82
- cursor: options['--cursor'],
83
- token: options['--token'],
84
- typedName: options['--confirm-name'],
85
- }, action === 'delete-plan' || action === 'delete'
86
- ? {
87
- deletions: new ServiceDeletionStore(path.join(catalogDirectory(), 'service-confirmations')),
88
- }
89
- : {});
90
- return (result.status ??
91
- result.metrics ??
92
- result.tables ??
93
- result.data ??
94
- result.plan ??
95
- result.deletion);
96
- }
package/dist/ship.d.ts DELETED
@@ -1,35 +0,0 @@
1
- import { type DeliveryRunner } from './project-state.js';
2
- import { planProvisioning, provisionApplication } from './provision.js';
3
- import type { CloudflareRequest } from './cloudflare.js';
4
- import { planProviderProvisioning, provisionSelectedProviders } from './providers/provision.js';
5
- export declare function shipCloudflareApplication(root: string, dryRun?: boolean, run?: DeliveryRunner, request?: CloudflareRequest, send?: typeof fetch, providerEnvironment?: NodeJS.ProcessEnv): Promise<{
6
- projectId: string;
7
- release: import("./delivery-evidence.js").Release;
8
- managementFile: string;
9
- productVerification: string;
10
- management: string;
11
- } | ({
12
- project: import("./project-state.js").ApplicationProject;
13
- checks: string[][];
14
- deployments: {
15
- target: string;
16
- directory: string;
17
- command: string[];
18
- }[];
19
- resourcesProvisioned: boolean;
20
- audience: "unconfigured" | "public" | "private";
21
- } & {
22
- provisioning: ReturnType<typeof planProvisioning>;
23
- mutation: false;
24
- integrations: ReturnType<typeof planProviderProvisioning>;
25
- }) | {
26
- state: "configuration-required";
27
- resources: Awaited<ReturnType<typeof provisionApplication>>;
28
- deployed: false;
29
- nextAction: string;
30
- } | {
31
- state: "provider-configuration-required";
32
- deployed: false;
33
- integrations: Awaited<ReturnType<typeof provisionSelectedProviders>>;
34
- }>;
35
- export declare const shipSelectedStack: typeof shipCloudflareApplication;
package/dist/ship.js DELETED
@@ -1,107 +0,0 @@
1
- import { realpathSync, writeFileSync, rmSync } from 'node:fs';
2
- import path from 'node:path';
3
- import { tmpdir } from 'node:os';
4
- import { randomUUID } from 'node:crypto';
5
- import { defaultRunner } from './project-state.js';
6
- import { withLifecycleOperation } from './lifecycle.js';
7
- import { planDelivery, shipApplication } from './delivery.js';
8
- import { planProvisioning, provisionApplication } from './provision.js';
9
- import { planProviderProvisioning, provisionSelectedProviders } from './providers/provision.js';
10
- import { applicationRuntime, configuredRuntime, runtimeTargets, RUNTIME_KEYS, } from './providers/runtime.js';
11
- import { CREDENTIALS } from './providers/api.js';
12
- /** Provisioning can change tracked binding IDs; never silently commit that change. */
13
- async function executeCloudflareApplication(root, dryRun = false, run = defaultRunner, request, send = fetch, providerEnvironment = process.env, session) {
14
- root = realpathSync(root);
15
- const deployment = planDelivery(root, true);
16
- const provisioning = planProvisioning(root);
17
- const integrations = planProviderProvisioning(root);
18
- if (dryRun)
19
- return {
20
- ...deployment,
21
- provisioning,
22
- integrations,
23
- mutation: false,
24
- };
25
- if (deployment.project.audience === 'unconfigured' || !deployment.project.accountId)
26
- throw new Error('Connect the intended account and audience before shipping.');
27
- const environment = runtimeEnvironment(providerEnvironment);
28
- const providerRun = (command, args, cwd, env, input) => run(command, args, cwd, runtimeEnvironment(env), input);
29
- if (realpathSync((await run('git', ['rev-parse', '--show-toplevel'], root, environment)).trim()) !==
30
- root ||
31
- (await run('git', ['status', '--porcelain'], root, environment)).trim())
32
- throw new Error('Shipping requires a clean application repository before provisioning.');
33
- const commit = (await run('git', ['rev-parse', 'HEAD'], root, environment)).trim();
34
- const application = await phase(session, 'application-runtime', () => applicationRuntime(root, providerRun));
35
- await phase(session, 'checks', () => run('pnpm', ['run', 'check'], root, environment));
36
- if ((await run('git', ['status', '--porcelain'], root, environment)).trim() ||
37
- (await run('git', ['rev-parse', 'HEAD'], root, environment)).trim() !== commit)
38
- throw new Error('Source changed during checks; provisioning was not started.');
39
- const configured = await phase(session, 'integrations', () => provisionSelectedProviders(root, false, providerRun, send, providerEnvironment));
40
- if (!configured.ready)
41
- return { state: 'provider-configuration-required', deployed: false, integrations: configured };
42
- if ((await run('git', ['status', '--porcelain'], root, environment)).trim() ||
43
- (await run('git', ['rev-parse', 'HEAD'], root, environment)).trim() !== commit)
44
- throw new Error('Source changed during provider configuration; provisioning was stopped.');
45
- const resources = await phase(session, 'resources', () => provisionApplication(root, false, providerRun, request));
46
- if ((await run('git', ['status', '--porcelain'], root, environment)).trim()) {
47
- return {
48
- state: 'configuration-required',
49
- resources,
50
- deployed: false,
51
- nextAction: 'Review and commit the resolved resource bindings, then run anhedral ship again. No source commit or deployment was performed automatically.',
52
- };
53
- }
54
- if ((await run('git', ['rev-parse', 'HEAD'], root, environment)).trim() !== commit)
55
- throw new Error('Source changed during provider configuration; deployment was not started.');
56
- const runtime = configuredRuntime(root);
57
- const environments = mergeRuntimeTargets(runtimeTargets(root, runtime), application);
58
- const buildRunner = async (command, args, cwd, env) => {
59
- const relative = path.relative(root, cwd).split(path.sep).join('/');
60
- const values = environments[`${relative}/.env`] ??
61
- environments[`${relative}/.dev.vars`] ??
62
- environments[`${relative}/.env.local`];
63
- const environment = runtimeEnvironment(env, values);
64
- if (command !== 'pnpm' ||
65
- args.join(' ') !== 'run deploy' ||
66
- !values ||
67
- !Object.keys(values).length)
68
- return run(command, args, cwd, environment);
69
- const file = path.join(tmpdir(), `anhedral-secrets-${randomUUID()}.json`);
70
- try {
71
- writeFileSync(file, JSON.stringify(values), { mode: 0o600, flag: 'wx' });
72
- return await run(command, [...args, '--secrets-file', file], cwd, environment);
73
- }
74
- finally {
75
- rmSync(file, { force: true });
76
- }
77
- };
78
- return phase(session, 'deployment', () => shipApplication(root, buildRunner, request));
79
- }
80
- function phase(session, name, action) {
81
- return session ? session.phase(name, action) : action();
82
- }
83
- export async function shipCloudflareApplication(root, dryRun = false, run = defaultRunner, request, send = fetch, providerEnvironment = process.env) {
84
- if (dryRun)
85
- return executeCloudflareApplication(root, true, run, request, send, providerEnvironment, undefined);
86
- return withLifecycleOperation(root, 'cloudflare', run, (session) => executeCloudflareApplication(root, false, run, request, send, providerEnvironment, session));
87
- }
88
- function runtimeEnvironment(base, values = {}) {
89
- const environment = { ...base, CI: '1', NO_COLOR: '1' };
90
- for (const name of Object.values(CREDENTIALS))
91
- delete environment[name];
92
- for (const name of RUNTIME_KEYS)
93
- if (!name.startsWith('NEXT_PUBLIC_') && !name.startsWith('EXPO_PUBLIC_'))
94
- delete environment[name];
95
- for (const name of Object.keys(environment))
96
- if (!name.startsWith('EXPO_PUBLIC_') &&
97
- /SECRET|PASSWORD|ADMIN_KEY|API_KEY|DATABASE_URL|AUTHORIZATION/.test(name))
98
- delete environment[name];
99
- return { ...environment, ...values };
100
- }
101
- function mergeRuntimeTargets(providers, application) {
102
- const targets = { ...providers };
103
- for (const [file, values] of Object.entries(application))
104
- targets[file] = { ...targets[file], ...values };
105
- return targets;
106
- }
107
- export const shipSelectedStack = shipCloudflareApplication;