anhedral 0.13.0 → 0.16.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 (360) hide show
  1. package/README.md +23 -229
  2. package/assets/patches/audit-deps.mjs +12 -2
  3. package/assets/stack/ai-schema.ts.txt +5 -0
  4. package/assets/stack/ai.ts.txt +30 -0
  5. package/assets/stack/api-index.ts.txt +15 -0
  6. package/assets/stack/auth-features.ts.txt +4 -0
  7. package/assets/stack/auth-journal.json.txt +13 -0
  8. package/assets/stack/auth-migration.sql.txt +53 -0
  9. package/assets/stack/auth-routes.ts.txt +11 -0
  10. package/assets/stack/auth-schema.ts.txt +64 -0
  11. package/assets/stack/auth-snapshot.json.txt +346 -0
  12. package/assets/stack/auth.ts.txt +32 -0
  13. package/assets/stack/billing-mode.ts.txt +8 -0
  14. package/assets/stack/billing-schema.ts.txt +11 -0
  15. package/assets/stack/desktop.rs.txt +21 -0
  16. package/assets/stack/entitlement-guard.ts.txt +32 -0
  17. package/assets/stack/entitlements.ts.txt +8 -0
  18. package/assets/stack/events-schema.ts.txt +12 -0
  19. package/assets/stack/events.ts.txt +59 -0
  20. package/assets/stack/mobile-auth.ts.txt +25 -0
  21. package/assets/stack/mobile-billing.tsx.txt +63 -0
  22. package/assets/stack/mobile-session.tsx.txt +83 -0
  23. package/assets/stack/native-button.tsx.txt +108 -0
  24. package/assets/stack/native-global.css.txt +4 -0
  25. package/assets/stack/native-lib-utils.ts.txt +5 -0
  26. package/assets/stack/native-metro.config.js.txt +6 -0
  27. package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
  28. package/assets/stack/native-tailwind.config.js.txt +73 -0
  29. package/assets/stack/native-text.tsx.txt +89 -0
  30. package/assets/stack/purchases.ts.txt +65 -0
  31. package/assets/stack/revenuecat.ts.txt +88 -0
  32. package/assets/stack/rtc-schema.ts.txt +10 -0
  33. package/assets/stack/rtc.ts.txt +122 -0
  34. package/assets/stack/security.ts.txt +31 -0
  35. package/assets/stack/storage.ts.txt +36 -0
  36. package/assets/stack/stripe.ts.txt +126 -0
  37. package/assets/stack/web-sign-in.tsx.txt +51 -0
  38. package/assets/ui/LICENSE.react-native-reusables +21 -0
  39. package/assets/ui/LICENSE.shadcn +21 -0
  40. package/assets/ui/UPSTREAM.json +39 -0
  41. package/assets/ui/catalog.json +891 -0
  42. package/assets/ui/extensions/registry.json +6 -0
  43. package/assets/ui/native/_controls.tsx +521 -0
  44. package/assets/ui/native/_core.tsx +118 -0
  45. package/assets/ui/native/_data.tsx +200 -0
  46. package/assets/ui/native/_display.tsx +453 -0
  47. package/assets/ui/native/_feedback.tsx +242 -0
  48. package/assets/ui/native/_legacy-dialog.tsx +38 -0
  49. package/assets/ui/native/_motion.tsx +520 -0
  50. package/assets/ui/native/_overlay.tsx +402 -0
  51. package/assets/ui/native/_selection.tsx +366 -0
  52. package/assets/ui/native/accordion.tsx +1 -0
  53. package/assets/ui/native/alert-dialog.tsx +11 -0
  54. package/assets/ui/native/alert.tsx +1 -0
  55. package/assets/ui/native/aspect-ratio.tsx +1 -0
  56. package/assets/ui/native/attachment.tsx +8 -0
  57. package/assets/ui/native/avatar.tsx +8 -0
  58. package/assets/ui/native/badge.tsx +1 -0
  59. package/assets/ui/native/breadcrumb.tsx +9 -0
  60. package/assets/ui/native/bubble.tsx +1 -0
  61. package/assets/ui/native/button-group.tsx +1 -0
  62. package/assets/ui/native/button.tsx +86 -0
  63. package/assets/ui/native/calendar.tsx +170 -0
  64. package/assets/ui/native/card.tsx +44 -0
  65. package/assets/ui/native/carousel.tsx +1 -0
  66. package/assets/ui/native/chart.tsx +193 -0
  67. package/assets/ui/native/checkbox.tsx +1 -0
  68. package/assets/ui/native/code-block.tsx +137 -0
  69. package/assets/ui/native/collapsible.tsx +1 -0
  70. package/assets/ui/native/combobox.tsx +1 -0
  71. package/assets/ui/native/command.tsx +11 -0
  72. package/assets/ui/native/context-menu.tsx +16 -0
  73. package/assets/ui/native/data-table.tsx +1 -0
  74. package/assets/ui/native/date-picker.tsx +43 -0
  75. package/assets/ui/native/dialog.tsx +15 -0
  76. package/assets/ui/native/direction.tsx +1 -0
  77. package/assets/ui/native/drawer.tsx +10 -0
  78. package/assets/ui/native/dropdown-menu.tsx +16 -0
  79. package/assets/ui/native/empty.tsx +8 -0
  80. package/assets/ui/native/field.tsx +13 -0
  81. package/assets/ui/native/hover-card.tsx +1 -0
  82. package/assets/ui/native/input-group.tsx +8 -0
  83. package/assets/ui/native/input-otp.tsx +1 -0
  84. package/assets/ui/native/input.tsx +28 -0
  85. package/assets/ui/native/item.tsx +12 -0
  86. package/assets/ui/native/kbd.tsx +1 -0
  87. package/assets/ui/native/label.tsx +4 -0
  88. package/assets/ui/native/layout.tsx +26 -0
  89. package/assets/ui/native/marker.tsx +1 -0
  90. package/assets/ui/native/menubar.tsx +17 -0
  91. package/assets/ui/native/message-scroller.tsx +6 -0
  92. package/assets/ui/native/message.tsx +10 -0
  93. package/assets/ui/native/native-select.tsx +1 -0
  94. package/assets/ui/native/navigation-menu.tsx +10 -0
  95. package/assets/ui/native/pagination.tsx +9 -0
  96. package/assets/ui/native/popover.tsx +1 -0
  97. package/assets/ui/native/progress.tsx +1 -0
  98. package/assets/ui/native/questionnaire.tsx +130 -0
  99. package/assets/ui/native/radio-group.tsx +1 -0
  100. package/assets/ui/native/registry.json +1103 -0
  101. package/assets/ui/native/resizable.tsx +1 -0
  102. package/assets/ui/native/scroll-area.tsx +1 -0
  103. package/assets/ui/native/select.tsx +11 -0
  104. package/assets/ui/native/separator.tsx +1 -0
  105. package/assets/ui/native/sheet.tsx +10 -0
  106. package/assets/ui/native/sidebar.tsx +22 -0
  107. package/assets/ui/native/skeleton.tsx +1 -0
  108. package/assets/ui/native/slider.tsx +1 -0
  109. package/assets/ui/native/spinner.tsx +1 -0
  110. package/assets/ui/native/switch.tsx +1 -0
  111. package/assets/ui/native/table.tsx +10 -0
  112. package/assets/ui/native/tabs.tsx +1 -0
  113. package/assets/ui/native/text.tsx +20 -0
  114. package/assets/ui/native/textarea.tsx +1 -0
  115. package/assets/ui/native/theme-switcher.tsx +22 -0
  116. package/assets/ui/native/toast.tsx +11 -0
  117. package/assets/ui/native/toggle-group.tsx +1 -0
  118. package/assets/ui/native/toggle.tsx +1 -0
  119. package/assets/ui/native/tooltip.tsx +1 -0
  120. package/assets/ui/native/trace.tsx +20 -0
  121. package/assets/ui/native/typography.tsx +15 -0
  122. package/assets/ui/theme-storage.ts +25 -0
  123. package/assets/ui/theme.tsx +66 -0
  124. package/assets/ui/web/button.tsx +59 -0
  125. package/assets/ui/web/input.tsx +21 -0
  126. package/assets/ui/web/label.tsx +19 -0
  127. package/dist/bin.js +7 -12
  128. package/dist/capabilities.d.ts +4 -33
  129. package/dist/capabilities.js +2 -84
  130. package/dist/capability-catalog.d.ts +83 -0
  131. package/dist/capability-catalog.js +121 -0
  132. package/dist/capability-command.d.ts +3 -0
  133. package/dist/capability-command.js +188 -0
  134. package/dist/capability-editor.d.ts +17 -0
  135. package/dist/capability-editor.js +97 -0
  136. package/dist/capability-recipes.d.ts +4 -0
  137. package/dist/capability-recipes.js +520 -0
  138. package/dist/capability-references.d.ts +4 -0
  139. package/dist/capability-references.js +7 -0
  140. package/dist/cli-commands.d.ts +1 -2
  141. package/dist/cli-commands.js +10 -104
  142. package/dist/cli-output.d.ts +1 -2
  143. package/dist/cli-output.js +6 -251
  144. package/dist/command-schema.js +40 -374
  145. package/dist/dependencies.d.ts +34 -62
  146. package/dist/dependencies.js +112 -199
  147. package/dist/index.d.ts +1 -45
  148. package/dist/index.js +1 -30
  149. package/dist/platforms/mobile.js +29 -139
  150. package/dist/platforms/web.d.ts +3 -0
  151. package/dist/platforms/web.js +251 -0
  152. package/dist/project-config.d.ts +2 -13
  153. package/dist/project-config.js +10 -83
  154. package/dist/registry/context.js +0 -1
  155. package/dist/registry/options.js +6 -40
  156. package/dist/registry/resolve.d.ts +3 -4
  157. package/dist/registry/resolve.js +18 -108
  158. package/dist/registry/types.d.ts +1 -7
  159. package/dist/registry/usage.js +3 -9
  160. package/dist/runtime-policy.d.ts +0 -2
  161. package/dist/runtime-policy.js +0 -16
  162. package/dist/scaffold/backend.d.ts +0 -4
  163. package/dist/scaffold/backend.js +1 -189
  164. package/dist/scaffold/bootstrap.d.ts +2 -3
  165. package/dist/scaffold/bootstrap.js +37 -43
  166. package/dist/scaffold/compose.js +2 -14
  167. package/dist/scaffold/database.d.ts +1 -1
  168. package/dist/scaffold/database.js +19 -126
  169. package/dist/scaffold/documentation.d.ts +0 -1
  170. package/dist/scaffold/documentation.js +82 -84
  171. package/dist/scaffold/expo-runtime.d.ts +2 -2
  172. package/dist/scaffold/expo-runtime.js +9 -101
  173. package/dist/scaffold/native-ui.d.ts +2 -0
  174. package/dist/scaffold/native-ui.js +74 -0
  175. package/dist/scaffold/stack-documentation.d.ts +0 -1
  176. package/dist/scaffold/stack-documentation.js +3 -49
  177. package/dist/scaffold/storage.d.ts +2 -0
  178. package/dist/scaffold/storage.js +21 -0
  179. package/dist/scaffold/styling.d.ts +1 -1
  180. package/dist/scaffold/styling.js +20 -28
  181. package/dist/scaffold/workspace.js +63 -199
  182. package/dist/stack-registry.d.ts +2 -58
  183. package/dist/stack-registry.js +22 -446
  184. package/dist/standard.js +7 -24
  185. package/dist/ui-catalog.d.ts +26 -0
  186. package/dist/ui-catalog.js +31 -0
  187. package/dist/ui-command.d.ts +3 -0
  188. package/dist/ui-command.js +219 -0
  189. package/dist/ui-project.d.ts +22 -0
  190. package/dist/ui-project.js +110 -0
  191. package/dist/version.d.ts +1 -1
  192. package/dist/version.js +1 -1
  193. package/docs/anhedral-stack.md +4 -119
  194. package/docs/capabilities.md +110 -0
  195. package/docs/native-ui.md +102 -0
  196. package/docs/software-factory.md +16 -577
  197. package/docs/stack-standard.md +11 -307
  198. package/docs/ui.md +33 -0
  199. package/docs/verification.md +511 -0
  200. package/package.json +26 -27
  201. package/dist/access.d.ts +0 -10
  202. package/dist/access.js +0 -93
  203. package/dist/auth-schema-snapshot.d.ts +0 -346
  204. package/dist/auth-schema-snapshot.js +0 -347
  205. package/dist/auth-schema.d.ts +0 -1
  206. package/dist/auth-schema.js +0 -57
  207. package/dist/capability-contract.d.ts +0 -47
  208. package/dist/capability-contract.js +0 -168
  209. package/dist/catalog-model.d.ts +0 -24
  210. package/dist/catalog-model.js +0 -1
  211. package/dist/catalog-registration.d.ts +0 -16
  212. package/dist/catalog-registration.js +0 -22
  213. package/dist/catalog-snapshot.d.ts +0 -5
  214. package/dist/catalog-snapshot.js +0 -97
  215. package/dist/cli-delivery.d.ts +0 -3
  216. package/dist/cli-delivery.js +0 -172
  217. package/dist/cloudflare.d.ts +0 -25
  218. package/dist/cloudflare.js +0 -226
  219. package/dist/delivery-evidence.d.ts +0 -62
  220. package/dist/delivery-evidence.js +0 -186
  221. package/dist/delivery.d.ts +0 -88
  222. package/dist/delivery.js +0 -570
  223. package/dist/inspector-model.d.ts +0 -123
  224. package/dist/inspector-model.js +0 -1
  225. package/dist/integration-service-readers.d.ts +0 -13
  226. package/dist/integration-service-readers.js +0 -173
  227. package/dist/lifecycle-model.d.ts +0 -15
  228. package/dist/lifecycle-model.js +0 -20
  229. package/dist/lifecycle.d.ts +0 -11
  230. package/dist/lifecycle.js +0 -91
  231. package/dist/management.d.ts +0 -3
  232. package/dist/management.js +0 -47
  233. package/dist/mobile-delivery.d.ts +0 -77
  234. package/dist/mobile-delivery.js +0 -366
  235. package/dist/neon-service-data.d.ts +0 -8
  236. package/dist/neon-service-data.js +0 -117
  237. package/dist/platforms/desktop.d.ts +0 -2
  238. package/dist/platforms/desktop.js +0 -415
  239. package/dist/platforms/extension.d.ts +0 -2
  240. package/dist/platforms/extension.js +0 -328
  241. package/dist/project-catalog.d.ts +0 -41
  242. package/dist/project-catalog.js +0 -288
  243. package/dist/project-inspector.d.ts +0 -4
  244. package/dist/project-inspector.js +0 -702
  245. package/dist/project-lifecycle.d.ts +0 -25
  246. package/dist/project-lifecycle.js +0 -57
  247. package/dist/project-state.d.ts +0 -49
  248. package/dist/project-state.js +0 -563
  249. package/dist/provider-auth.d.ts +0 -41
  250. package/dist/provider-auth.js +0 -215
  251. package/dist/provider-readiness.d.ts +0 -30
  252. package/dist/provider-readiness.js +0 -104
  253. package/dist/providers/adapters.d.ts +0 -17
  254. package/dist/providers/adapters.js +0 -278
  255. package/dist/providers/api.d.ts +0 -29
  256. package/dist/providers/api.js +0 -253
  257. package/dist/providers/config.d.ts +0 -15
  258. package/dist/providers/config.js +0 -182
  259. package/dist/providers/definitions.d.ts +0 -318
  260. package/dist/providers/definitions.js +0 -127
  261. package/dist/providers/provision.d.ts +0 -24
  262. package/dist/providers/provision.js +0 -76
  263. package/dist/providers/receipts.d.ts +0 -20
  264. package/dist/providers/receipts.js +0 -66
  265. package/dist/providers/recovery-verification.d.ts +0 -7
  266. package/dist/providers/recovery-verification.js +0 -112
  267. package/dist/providers/recovery.d.ts +0 -30
  268. package/dist/providers/recovery.js +0 -34
  269. package/dist/providers/runtime.d.ts +0 -10
  270. package/dist/providers/runtime.js +0 -265
  271. package/dist/providers/schema.d.ts +0 -28
  272. package/dist/providers/schema.js +0 -49
  273. package/dist/providers/state.d.ts +0 -55
  274. package/dist/providers/state.js +0 -289
  275. package/dist/provision.d.ts +0 -55
  276. package/dist/provision.js +0 -284
  277. package/dist/r2-service-data.d.ts +0 -2
  278. package/dist/r2-service-data.js +0 -136
  279. package/dist/readiness.d.ts +0 -23
  280. package/dist/readiness.js +0 -122
  281. package/dist/registry/add.d.ts +0 -24
  282. package/dist/registry/add.js +0 -270
  283. package/dist/registry/bootstrap.d.ts +0 -2
  284. package/dist/registry/bootstrap.js +0 -14
  285. package/dist/registry/commands.d.ts +0 -3
  286. package/dist/registry/commands.js +0 -85
  287. package/dist/registry/presets.d.ts +0 -4
  288. package/dist/registry/presets.js +0 -41
  289. package/dist/registry/preview.d.ts +0 -11
  290. package/dist/registry/preview.js +0 -91
  291. package/dist/registry/receipt.d.ts +0 -3
  292. package/dist/registry/receipt.js +0 -68
  293. package/dist/repository.d.ts +0 -24
  294. package/dist/repository.js +0 -96
  295. package/dist/scaffold/auth.d.ts +0 -3
  296. package/dist/scaffold/auth.js +0 -151
  297. package/dist/scaffold/billing-config.d.ts +0 -1
  298. package/dist/scaffold/billing-config.js +0 -73
  299. package/dist/scaffold/billing-contracts.d.ts +0 -2
  300. package/dist/scaffold/billing-contracts.js +0 -48
  301. package/dist/scaffold/billing-providers.d.ts +0 -1
  302. package/dist/scaffold/billing-providers.js +0 -249
  303. package/dist/scaffold/billing-schema.d.ts +0 -1
  304. package/dist/scaffold/billing-schema.js +0 -34
  305. package/dist/scaffold/billing-security.d.ts +0 -1
  306. package/dist/scaffold/billing-security.js +0 -46
  307. package/dist/scaffold/billing-server.d.ts +0 -1
  308. package/dist/scaffold/billing-server.js +0 -139
  309. package/dist/scaffold/billing-store.d.ts +0 -1
  310. package/dist/scaffold/billing-store.js +0 -72
  311. package/dist/scaffold/billing.d.ts +0 -2
  312. package/dist/scaffold/billing.js +0 -216
  313. package/dist/scaffold/cloudflare-services.d.ts +0 -8
  314. package/dist/scaffold/cloudflare-services.js +0 -198
  315. package/dist/scaffold/expo-auth.d.ts +0 -3
  316. package/dist/scaffold/expo-auth.js +0 -192
  317. package/dist/scaffold/expo-billing.d.ts +0 -3
  318. package/dist/scaffold/expo-billing.js +0 -292
  319. package/dist/scaffold/integrations.d.ts +0 -4
  320. package/dist/scaffold/integrations.js +0 -12
  321. package/dist/scaffold/lint.d.ts +0 -4
  322. package/dist/scaffold/lint.js +0 -56
  323. package/dist/scaffold/neon-realtime.d.ts +0 -2
  324. package/dist/scaffold/neon-realtime.js +0 -97
  325. package/dist/scaffold/services.d.ts +0 -5
  326. package/dist/scaffold/services.js +0 -108
  327. package/dist/scaffold/stream.d.ts +0 -2
  328. package/dist/scaffold/stream.js +0 -114
  329. package/dist/scaffold/void.d.ts +0 -4
  330. package/dist/scaffold/void.js +0 -264
  331. package/dist/scaffold/web.d.ts +0 -2
  332. package/dist/scaffold/web.js +0 -130
  333. package/dist/service-deletion.d.ts +0 -29
  334. package/dist/service-deletion.js +0 -195
  335. package/dist/service-descriptor.d.ts +0 -10
  336. package/dist/service-descriptor.js +0 -78
  337. package/dist/service-model.d.ts +0 -49
  338. package/dist/service-model.js +0 -8
  339. package/dist/service-operations.d.ts +0 -29
  340. package/dist/service-operations.js +0 -78
  341. package/dist/service-readers.d.ts +0 -8
  342. package/dist/service-readers.js +0 -247
  343. package/dist/services-command.d.ts +0 -39
  344. package/dist/services-command.js +0 -102
  345. package/dist/ship.d.ts +0 -348
  346. package/dist/ship.js +0 -239
  347. package/dist/vercel-project.d.ts +0 -101
  348. package/dist/vercel-project.js +0 -305
  349. package/dist/vercel.d.ts +0 -67
  350. package/dist/vercel.js +0 -581
  351. package/dist/vinext.d.ts +0 -2
  352. package/dist/vinext.js +0 -86
  353. package/dist/void-execution.d.ts +0 -10
  354. package/dist/void-execution.js +0 -94
  355. package/dist/void-migrations.d.ts +0 -6
  356. package/dist/void-migrations.js +0 -110
  357. package/dist/void-state.d.ts +0 -16
  358. package/dist/void-state.js +0 -65
  359. package/dist/void.d.ts +0 -3
  360. package/dist/void.js +0 -5
@@ -1,29 +0,0 @@
1
- import type { IntegrationProvider, ProviderSettings } from './config.js';
2
- export type ApiObject = Record<string, unknown>;
3
- export declare function object(value: unknown): ApiObject;
4
- export declare function list(value: unknown): ApiObject[];
5
- export declare function text(value: unknown): string;
6
- export declare function resourceId(value: unknown): string;
7
- /** Stable configuration and operation identity, never a password verifier. */
8
- export declare function digest(value: unknown): string;
9
- export declare const CREDENTIALS: Record<IntegrationProvider, string>;
10
- export interface ApiRequest {
11
- (route: string, method?: 'GET' | 'POST' | 'PATCH', body?: ApiObject, operation?: string): Promise<unknown>;
12
- }
13
- export declare class ProviderRequestError extends Error {
14
- readonly rejected: boolean;
15
- readonly status?: number | undefined;
16
- constructor(message: string, rejected: boolean, status?: number | undefined);
17
- }
18
- export interface ProviderRetryOptions {
19
- /** Reads only; provider mutations always receive exactly one attempt. */
20
- maxAttempts?: number;
21
- totalTimeoutMs?: number;
22
- attemptTimeoutMs?: number;
23
- baseDelayMs?: number;
24
- maxDelayMs?: number;
25
- delay?: (milliseconds: number) => Promise<void>;
26
- }
27
- /** Fixed origins, bounded reads and sanitized errors keep management keys out of output.
28
- * Only GET requests retry transient failures; unknown mutation outcomes never replay. */
29
- export declare function providerApi(id: IntegrationProvider, settings: ProviderSettings, environment: NodeJS.ProcessEnv, send: typeof fetch, options?: ProviderRetryOptions): ApiRequest;
@@ -1,253 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { PROVIDER_DEFINITIONS } from './definitions.js';
3
- export function object(value) {
4
- if (!value || typeof value !== 'object' || Array.isArray(value))
5
- throw new Error('Provider returned an invalid resource.');
6
- return value;
7
- }
8
- export function list(value) {
9
- if (!Array.isArray(value))
10
- throw new Error('Provider returned an invalid resource list.');
11
- return value.map(object);
12
- }
13
- export function text(value) {
14
- if (typeof value !== 'string' || !value || value.length > 16384 || /[\r\n\x00]/.test(value))
15
- throw new Error('Provider returned an invalid resource field.');
16
- return value;
17
- }
18
- export function resourceId(value) {
19
- const id = typeof value === 'number' && Number.isSafeInteger(value) && value > 0
20
- ? String(value)
21
- : text(value);
22
- if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,254}$/.test(id))
23
- throw new Error('Provider returned an invalid resource ID.');
24
- return id;
25
- }
26
- /** Stable configuration and operation identity, never a password verifier. */
27
- export function digest(value) {
28
- const canonical = (item) => Array.isArray(item)
29
- ? item.map(canonical)
30
- : item && typeof item === 'object'
31
- ? Object.fromEntries(Object.entries(item)
32
- .sort(([a], [b]) => a.localeCompare(b))
33
- .map(([key, entry]) => [key, canonical(entry)]))
34
- : item;
35
- return createHash('sha256')
36
- .update(JSON.stringify(canonical(value)))
37
- .digest('hex');
38
- }
39
- export const CREDENTIALS = Object.fromEntries(Object.entries(PROVIDER_DEFINITIONS).map(([id, definition]) => [id, definition.credential]));
40
- export class ProviderRequestError extends Error {
41
- rejected;
42
- status;
43
- constructor(message, rejected, status) {
44
- super(message);
45
- this.rejected = rejected;
46
- this.status = status;
47
- }
48
- }
49
- class TransportFailure extends Error {
50
- }
51
- class RequestTimeout extends TransportFailure {
52
- }
53
- function retryPolicy(options) {
54
- const policy = {
55
- maxAttempts: options.maxAttempts ?? 3,
56
- totalTimeoutMs: options.totalTimeoutMs ?? 30_000,
57
- attemptTimeoutMs: options.attemptTimeoutMs ?? 10_000,
58
- baseDelayMs: options.baseDelayMs ?? 100,
59
- maxDelayMs: options.maxDelayMs ?? 2_000,
60
- delay: options.delay ??
61
- ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds))),
62
- };
63
- if (!Number.isInteger(policy.maxAttempts) ||
64
- policy.maxAttempts < 1 ||
65
- policy.maxAttempts > 5 ||
66
- [policy.totalTimeoutMs, policy.attemptTimeoutMs].some((value) => !Number.isInteger(value) || value < 1 || value > 30_000) ||
67
- [policy.baseDelayMs, policy.maxDelayMs].some((value) => !Number.isInteger(value) || value < 0 || value > 2_000) ||
68
- policy.baseDelayMs > policy.maxDelayMs ||
69
- typeof policy.delay !== 'function')
70
- throw new Error('Invalid bounded provider retry policy.');
71
- return policy;
72
- }
73
- async function deadline(milliseconds, operation) {
74
- const controller = new AbortController();
75
- let timer;
76
- const timeout = new Promise((_resolve, reject) => {
77
- timer = setTimeout(() => {
78
- controller.abort();
79
- reject(new RequestTimeout());
80
- }, milliseconds);
81
- });
82
- try {
83
- return await Promise.race([operation(controller.signal), timeout]);
84
- }
85
- finally {
86
- clearTimeout(timer);
87
- }
88
- }
89
- function cancelBody(response) {
90
- try {
91
- void response.body?.cancel().catch(() => undefined);
92
- }
93
- catch {
94
- /* Cancellation is best effort; diagnostics stay sanitized. */
95
- }
96
- }
97
- async function responseJson(id, response, signal) {
98
- if (signal.aborted) {
99
- cancelBody(response);
100
- throw new RequestTimeout();
101
- }
102
- const reader = response.body?.getReader();
103
- if (!reader)
104
- throw new Error(`${id}: provider returned an empty response.`);
105
- const cancel = () => {
106
- void reader.cancel().catch(() => undefined);
107
- };
108
- signal.addEventListener('abort', cancel, { once: true });
109
- const chunks = [];
110
- let bytes = 0;
111
- try {
112
- for (;;) {
113
- let chunk;
114
- try {
115
- chunk = await reader.read();
116
- }
117
- catch {
118
- throw new TransportFailure();
119
- }
120
- if (chunk.done)
121
- break;
122
- bytes += chunk.value.length;
123
- if (bytes > 2 * 1024 * 1024)
124
- throw new Error('Response exceeded size limit.');
125
- chunks.push(chunk.value);
126
- }
127
- return JSON.parse(Buffer.concat(chunks).toString('utf8'));
128
- }
129
- catch (error) {
130
- cancel();
131
- if (signal.aborted)
132
- throw new RequestTimeout();
133
- if (error instanceof TransportFailure)
134
- throw error;
135
- throw new Error(`${id}: provider returned invalid or oversized JSON.`);
136
- }
137
- finally {
138
- signal.removeEventListener('abort', cancel);
139
- reader.releaseLock();
140
- }
141
- }
142
- function requestedDelay(value, maximum) {
143
- if (!value)
144
- return 0;
145
- const milliseconds = /^\d+(?:\.\d+)?$/.test(value)
146
- ? Number(value) * 1000
147
- : Date.parse(value) - Date.now();
148
- if (!Number.isFinite(milliseconds))
149
- return 0;
150
- // Do not retry sooner than a provider's long waiting requirement. Return the
151
- // sanitized error when that wait exceeds this deliberately short retry budget.
152
- return milliseconds > maximum ? undefined : Math.max(0, Math.ceil(milliseconds));
153
- }
154
- /** Fixed origins, bounded reads and sanitized errors keep management keys out of output.
155
- * Only GET requests retry transient failures; unknown mutation outcomes never replay. */
156
- export function providerApi(id, settings, environment, send, options = {}) {
157
- const token = environment[CREDENTIALS[id]];
158
- if (!token || /[^\x21-\x7e]/.test(token))
159
- throw new Error(`${id}: supply ${CREDENTIALS[id]}.`);
160
- const policy = retryPolicy(options);
161
- const definition = PROVIDER_DEFINITIONS[id];
162
- const origin = definition.regionalOrigins?.[settings.region ?? ''] ?? definition.origin;
163
- return async (route, method = 'GET', body, operation) => {
164
- if (!route.startsWith('/') ||
165
- route.startsWith('//') ||
166
- route.includes('..') ||
167
- /[\r\n#\\]/.test(route))
168
- throw new Error('Invalid provider API path.');
169
- const url = new URL(route, origin);
170
- if (url.origin !== origin)
171
- throw new Error('Provider API origin changed.');
172
- const headers = {
173
- Authorization: `Bearer ${token}`,
174
- Accept: 'application/json',
175
- };
176
- let payload;
177
- if (body) {
178
- if (id === 'stripe') {
179
- const form = new URLSearchParams();
180
- for (const [key, value] of Object.entries(body)) {
181
- if (Array.isArray(value))
182
- for (const entry of value)
183
- form.append(`${key}[]`, String(entry));
184
- else
185
- form.set(key, String(value));
186
- }
187
- payload = form.toString();
188
- headers['Content-Type'] = 'application/x-www-form-urlencoded';
189
- }
190
- else {
191
- payload = JSON.stringify(body);
192
- headers['Content-Type'] = 'application/json';
193
- }
194
- }
195
- if (operation && (id === 'stripe' || id === 'resend'))
196
- headers['Idempotency-Key'] = operation;
197
- const started = performance.now();
198
- const attempts = method === 'GET' ? policy.maxAttempts : 1;
199
- for (let attempt = 0; attempt < attempts; attempt++) {
200
- const remaining = policy.totalTimeoutMs - (performance.now() - started);
201
- if (remaining <= 0)
202
- throw new Error(`${id}: provider read retry deadline exceeded.`);
203
- let retryAfter = 0;
204
- try {
205
- return await deadline(Math.min(remaining, method === 'GET' ? policy.attemptTimeoutMs : policy.totalTimeoutMs), async (signal) => {
206
- let response;
207
- try {
208
- response = await send(url.toString(), {
209
- method,
210
- headers,
211
- body: payload,
212
- redirect: 'error',
213
- signal,
214
- });
215
- }
216
- catch {
217
- throw new TransportFailure();
218
- }
219
- if (!response.ok) {
220
- retryAfter =
221
- requestedDelay(response.headers.get('Retry-After'), policy.maxDelayMs) ?? -1;
222
- cancelBody(response);
223
- throw new ProviderRequestError(`${id}: provider request failed (HTTP ${response.status}). Check account, permissions and quota.`, response.status >= 400 &&
224
- response.status < 500 &&
225
- ![408, 429].includes(response.status), response.status);
226
- }
227
- return responseJson(id, response, signal);
228
- });
229
- }
230
- catch (error) {
231
- const retryable = error instanceof TransportFailure ||
232
- (error instanceof ProviderRequestError &&
233
- [429, 502, 503, 504].includes(error.status ?? 0));
234
- const failure = error instanceof TransportFailure
235
- ? new Error(`${id}: provider request did not complete. Inspect remote status before retrying.`)
236
- : error;
237
- if (method !== 'GET' || !retryable || retryAfter < 0 || attempt + 1 >= attempts)
238
- throw failure;
239
- const delay = Math.max(retryAfter, Math.min(policy.maxDelayMs, policy.baseDelayMs * 2 ** attempt));
240
- const budget = policy.totalTimeoutMs - (performance.now() - started);
241
- if (delay >= budget)
242
- throw failure;
243
- try {
244
- await deadline(budget, async () => policy.delay(delay));
245
- }
246
- catch {
247
- throw new Error(`${id}: provider read retry deadline exceeded.`);
248
- }
249
- }
250
- }
251
- throw new Error(`${id}: provider read retry deadline exceeded.`);
252
- };
253
- }
@@ -1,15 +0,0 @@
1
- import { type IntegrationProvider, type ProviderSettings, type ProviderSettingsById } from './definitions.js';
2
- export { INTEGRATION_PROVIDERS } from './definitions.js';
3
- export type { IntegrationProvider, ProviderSettings, ProviderSettingsById } from './definitions.js';
4
- export interface ProviderConfiguration {
5
- schemaVersion: 1;
6
- providers: Partial<ProviderSettingsById>;
7
- }
8
- /** Validate untrusted JSON before assigning provider-specific types. */
9
- export declare function validateProviderConfiguration(value: unknown, selected?: readonly IntegrationProvider[]): asserts value is ProviderConfiguration;
10
- export declare function providerConfiguration(root: string): ProviderConfiguration;
11
- export declare function setting(settings: ProviderSettings, key: string): string;
12
- /** No identities, domains, prices or organizations are inferred from a user's last session. */
13
- export declare function providerRequirements(id: IntegrationProvider, config: ProviderSettings): string[];
14
- export declare function selectedIntegrations(root: string): IntegrationProvider[];
15
- export declare function providerConfigurationTemplate(products: readonly string[], name: string): ProviderConfiguration;
@@ -1,182 +0,0 @@
1
- import { realpathSync } from 'node:fs';
2
- import { hasProjectSection, readProjectSection } from '../project-config.js';
3
- import { validateSetupPlan } from '../readiness.js';
4
- import { INTEGRATION_PROVIDERS, PROVIDER_DEFINITIONS, PROVIDER_EVENT_PATTERN, PROVIDER_IDENTITY_PATTERN, PROVIDER_TEXT_PATTERN, PROVIDER_WEBHOOK_PATTERN, } from './definitions.js';
5
- export { INTEGRATION_PROVIDERS } from './definitions.js';
6
- /** Validate untrusted JSON before assigning provider-specific types. */
7
- export function validateProviderConfiguration(value, selected = INTEGRATION_PROVIDERS) {
8
- if (!value ||
9
- typeof value !== 'object' ||
10
- Array.isArray(value) ||
11
- !('schemaVersion' in value) ||
12
- value.schemaVersion !== 1 ||
13
- !('providers' in value) ||
14
- !value.providers ||
15
- typeof value.providers !== 'object' ||
16
- Array.isArray(value.providers) ||
17
- Object.keys(value).some((key) => !['schemaVersion', 'providers'].includes(key)))
18
- throw new Error('Invalid provider configuration schema.');
19
- for (const [id, settings] of Object.entries(value.providers)) {
20
- if (!INTEGRATION_PROVIDERS.includes(id) ||
21
- !selected.includes(id))
22
- throw new Error('Provider configuration includes an unsupported or unselected provider.');
23
- if (!settings || typeof settings !== 'object' || Array.isArray(settings))
24
- throw new Error(`Invalid ${id} settings.`);
25
- const definition = PROVIDER_DEFINITIONS[id];
26
- for (const [key, entry] of Object.entries(settings)) {
27
- const field = definition.fields[key];
28
- if (!Object.hasOwn(definition.fields, key) || !field)
29
- throw new Error(`Unsupported ${id} setting. Credentials belong in the environment.`);
30
- if (field.kind === 'events') {
31
- if (!Array.isArray(entry) ||
32
- entry.length < 1 ||
33
- entry.length > 100 ||
34
- new Set(entry).size !== entry.length ||
35
- entry.some((event) => typeof event !== 'string' || !new RegExp(PROVIDER_EVENT_PATTERN).test(event)))
36
- throw new Error('Stripe webhook events must be explicit unique event names.');
37
- continue;
38
- }
39
- if (typeof entry !== 'string' || entry.length > 255 || /[\x00-\x1f\x7f]/.test(entry))
40
- throw new Error(`Invalid ${id} setting.`);
41
- if (field.choices && !field.choices.includes(entry))
42
- throw new Error(`Invalid ${id} ${key} choice.`);
43
- if (field.kind === 'https-url') {
44
- let url;
45
- try {
46
- url = new URL(entry);
47
- }
48
- catch {
49
- throw new Error('Webhook URL must use HTTPS.');
50
- }
51
- if (!new RegExp(PROVIDER_WEBHOOK_PATTERN).test(entry) ||
52
- url.protocol !== 'https:' ||
53
- !url.hostname ||
54
- url.username ||
55
- url.password ||
56
- url.hash ||
57
- url.search)
58
- throw new Error('Webhook URL must use HTTPS without credentials, query or fragment.');
59
- }
60
- else if (!new RegExp(field.kind === 'identity' ? PROVIDER_IDENTITY_PATTERN : PROVIDER_TEXT_PATTERN).test(entry))
61
- throw new Error(`Invalid ${id} ${field.kind === 'identity' ? 'resource identity' : 'setting'}.`);
62
- }
63
- }
64
- }
65
- export function providerConfiguration(root) {
66
- root = realpathSync(root);
67
- const selected = selectedIntegrations(root);
68
- if (!hasProjectSection(root, 'providers'))
69
- return { schemaVersion: 1, providers: {} };
70
- let value;
71
- try {
72
- value = readProjectSection(root, 'providers');
73
- }
74
- catch {
75
- throw new Error('Invalid anhedral.json providers configuration.');
76
- }
77
- validateProviderConfiguration(value, selected);
78
- return value;
79
- }
80
- export function setting(settings, key) {
81
- const value = settings[key];
82
- return typeof value === 'string' ? value : '';
83
- }
84
- /** No identities, domains, prices or organizations are inferred from a user's last session. */
85
- export function providerRequirements(id, config) {
86
- const missing = [];
87
- const need = (key) => {
88
- if (!setting(config, key))
89
- missing.push(key);
90
- };
91
- const existingOrNew = () => {
92
- if (!setting(config, 'projectId'))
93
- need('name');
94
- };
95
- switch (id) {
96
- case 'neon':
97
- existingOrNew();
98
- need('organizationId');
99
- need('database');
100
- need('role');
101
- if (!setting(config, 'projectId'))
102
- need('region');
103
- break;
104
- case 'clerk':
105
- need('workspaceId');
106
- if (!setting(config, 'applicationId'))
107
- need('name');
108
- if (!['development', 'production'].includes(setting(config, 'environment')))
109
- missing.push('environment');
110
- break;
111
- case 'resend':
112
- need('domain');
113
- break;
114
- case 'stripe':
115
- need('accountId');
116
- if (!['test', 'live'].includes(setting(config, 'mode')))
117
- missing.push('mode');
118
- if (setting(config, 'webhookUrl') && !config.webhookEvents)
119
- missing.push('webhookEvents');
120
- if (config.webhookEvents && !setting(config, 'webhookUrl'))
121
- missing.push('webhookUrl');
122
- break;
123
- case 'revenuecat':
124
- existingOrNew();
125
- if (![
126
- 'iosAppId',
127
- 'androidAppId',
128
- 'webAppId',
129
- 'stripeAccountId',
130
- 'bundleId',
131
- 'packageName',
132
- ].some((key) => setting(config, key)))
133
- missing.push('store app identifiers or a connected stripeAccountId');
134
- break;
135
- case 'sentry':
136
- need('organization');
137
- need('team');
138
- need('project');
139
- need('platform');
140
- break;
141
- case 'posthog':
142
- existingOrNew();
143
- need('organizationId');
144
- if (!['us', 'eu'].includes(setting(config, 'region')))
145
- missing.push('region');
146
- break;
147
- case 'openai':
148
- existingOrNew();
149
- need('serviceAccountName');
150
- break;
151
- }
152
- return missing;
153
- }
154
- export function selectedIntegrations(root) {
155
- const setup = readProjectSection(root, 'setup');
156
- validateSetupPlan(setup);
157
- return INTEGRATION_PROVIDERS.filter((id) => setup.products.includes(id) || (id === 'openai' && setup.products.includes('ai-sdk')));
158
- }
159
- export function providerConfigurationTemplate(products, name) {
160
- const templates = {
161
- neon: { name, organizationId: '', region: '', database: 'app', role: 'app_owner' },
162
- clerk: { name, workspaceId: '', environment: 'development' },
163
- resend: { domain: '' },
164
- stripe: { accountId: '', mode: 'test' },
165
- revenuecat: products.includes('expo')
166
- ? { name, bundleId: '', packageName: '' }
167
- : { name, stripeAccountId: '' },
168
- sentry: {
169
- name,
170
- organization: '',
171
- team: '',
172
- project: name,
173
- platform: products.includes('next') || products.includes('vinext') ? 'javascript-nextjs' : 'node',
174
- },
175
- posthog: { name, organizationId: '', region: '' },
176
- openai: { name, serviceAccountName: 'anhedral-runtime' },
177
- };
178
- return {
179
- schemaVersion: 1,
180
- providers: Object.fromEntries(INTEGRATION_PROVIDERS.filter((id) => products.includes(id) || (id === 'openai' && products.includes('ai-sdk'))).map((id) => [id, templates[id]])),
181
- };
182
- }