thevoidforge 21.0.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 (328) hide show
  1. package/dist/scripts/vault-read.d.ts +11 -0
  2. package/dist/scripts/vault-read.js +89 -0
  3. package/dist/scripts/voidforge.d.ts +20 -0
  4. package/dist/scripts/voidforge.js +404 -0
  5. package/dist/tsconfig.tsbuildinfo +1 -0
  6. package/dist/wizard/api/auth.d.ts +5 -0
  7. package/dist/wizard/api/auth.js +133 -0
  8. package/dist/wizard/api/blueprint.d.ts +45 -0
  9. package/dist/wizard/api/blueprint.js +184 -0
  10. package/dist/wizard/api/cloud-providers.d.ts +16 -0
  11. package/dist/wizard/api/cloud-providers.js +363 -0
  12. package/dist/wizard/api/credentials.d.ts +1 -0
  13. package/dist/wizard/api/credentials.js +258 -0
  14. package/dist/wizard/api/danger-room.d.ts +18 -0
  15. package/dist/wizard/api/danger-room.js +401 -0
  16. package/dist/wizard/api/deploy.d.ts +4 -0
  17. package/dist/wizard/api/deploy.js +164 -0
  18. package/dist/wizard/api/prd.d.ts +1 -0
  19. package/dist/wizard/api/prd.js +363 -0
  20. package/dist/wizard/api/project.d.ts +1 -0
  21. package/dist/wizard/api/project.js +239 -0
  22. package/dist/wizard/api/projects.d.ts +6 -0
  23. package/dist/wizard/api/projects.js +648 -0
  24. package/dist/wizard/api/provision.d.ts +4 -0
  25. package/dist/wizard/api/provision.js +535 -0
  26. package/dist/wizard/api/terminal.d.ts +25 -0
  27. package/dist/wizard/api/terminal.js +241 -0
  28. package/dist/wizard/api/users.d.ts +6 -0
  29. package/dist/wizard/api/users.js +244 -0
  30. package/dist/wizard/api/war-room.d.ts +14 -0
  31. package/dist/wizard/api/war-room.js +45 -0
  32. package/dist/wizard/lib/ad-platform-core.d.ts +6 -0
  33. package/dist/wizard/lib/ad-platform-core.js +1 -0
  34. package/dist/wizard/lib/adapters/index.d.ts +52 -0
  35. package/dist/wizard/lib/adapters/index.js +38 -0
  36. package/dist/wizard/lib/adapters/sandbox-bank.d.ts +17 -0
  37. package/dist/wizard/lib/adapters/sandbox-bank.js +77 -0
  38. package/dist/wizard/lib/adapters/sandbox.d.ts +39 -0
  39. package/dist/wizard/lib/adapters/sandbox.js +174 -0
  40. package/dist/wizard/lib/adapters/stripe.d.ts +19 -0
  41. package/dist/wizard/lib/adapters/stripe.js +143 -0
  42. package/dist/wizard/lib/adapters/types.d.ts +9 -0
  43. package/dist/wizard/lib/adapters/types.js +10 -0
  44. package/dist/wizard/lib/agent-memory.d.ts +36 -0
  45. package/dist/wizard/lib/agent-memory.js +114 -0
  46. package/dist/wizard/lib/anomaly-detection.d.ts +59 -0
  47. package/dist/wizard/lib/anomaly-detection.js +122 -0
  48. package/dist/wizard/lib/anthropic.d.ts +21 -0
  49. package/dist/wizard/lib/anthropic.js +105 -0
  50. package/dist/wizard/lib/asset-scanner.d.ts +23 -0
  51. package/dist/wizard/lib/asset-scanner.js +107 -0
  52. package/dist/wizard/lib/audit-log.d.ts +23 -0
  53. package/dist/wizard/lib/audit-log.js +70 -0
  54. package/dist/wizard/lib/autonomy-controller.d.ts +76 -0
  55. package/dist/wizard/lib/autonomy-controller.js +183 -0
  56. package/dist/wizard/lib/body-parser.d.ts +2 -0
  57. package/dist/wizard/lib/body-parser.js +36 -0
  58. package/dist/wizard/lib/build-analytics.d.ts +39 -0
  59. package/dist/wizard/lib/build-analytics.js +91 -0
  60. package/dist/wizard/lib/build-step.d.ts +21 -0
  61. package/dist/wizard/lib/build-step.js +104 -0
  62. package/dist/wizard/lib/campaign-proposer.d.ts +39 -0
  63. package/dist/wizard/lib/campaign-proposer.js +180 -0
  64. package/dist/wizard/lib/campaign-state-machine.d.ts +63 -0
  65. package/dist/wizard/lib/campaign-state-machine.js +114 -0
  66. package/dist/wizard/lib/ci-generator.d.ts +14 -0
  67. package/dist/wizard/lib/ci-generator.js +187 -0
  68. package/dist/wizard/lib/claude-merge.d.ts +38 -0
  69. package/dist/wizard/lib/claude-merge.js +115 -0
  70. package/dist/wizard/lib/codegen/erd-gen.d.ts +16 -0
  71. package/dist/wizard/lib/codegen/erd-gen.js +98 -0
  72. package/dist/wizard/lib/codegen/integrations.d.ts +18 -0
  73. package/dist/wizard/lib/codegen/integrations.js +189 -0
  74. package/dist/wizard/lib/codegen/openapi-gen.d.ts +15 -0
  75. package/dist/wizard/lib/codegen/openapi-gen.js +79 -0
  76. package/dist/wizard/lib/codegen/prisma-types.d.ts +15 -0
  77. package/dist/wizard/lib/codegen/prisma-types.js +44 -0
  78. package/dist/wizard/lib/codegen/seed-gen.d.ts +16 -0
  79. package/dist/wizard/lib/codegen/seed-gen.js +128 -0
  80. package/dist/wizard/lib/compliance.d.ts +51 -0
  81. package/dist/wizard/lib/compliance.js +112 -0
  82. package/dist/wizard/lib/correlation-engine.d.ts +59 -0
  83. package/dist/wizard/lib/correlation-engine.js +151 -0
  84. package/dist/wizard/lib/cost-estimator.d.ts +22 -0
  85. package/dist/wizard/lib/cost-estimator.js +72 -0
  86. package/dist/wizard/lib/cost-tracker.d.ts +27 -0
  87. package/dist/wizard/lib/cost-tracker.js +37 -0
  88. package/dist/wizard/lib/daemon-aggregator.d.ts +71 -0
  89. package/dist/wizard/lib/daemon-aggregator.js +204 -0
  90. package/dist/wizard/lib/daemon-core.d.ts +6 -0
  91. package/dist/wizard/lib/daemon-core.js +5 -0
  92. package/dist/wizard/lib/dashboard-data.d.ts +132 -0
  93. package/dist/wizard/lib/dashboard-data.js +336 -0
  94. package/dist/wizard/lib/dashboard-ws.d.ts +25 -0
  95. package/dist/wizard/lib/dashboard-ws.js +91 -0
  96. package/dist/wizard/lib/deep-current.d.ts +77 -0
  97. package/dist/wizard/lib/deep-current.js +234 -0
  98. package/dist/wizard/lib/deploy-coordinator.d.ts +40 -0
  99. package/dist/wizard/lib/deploy-coordinator.js +86 -0
  100. package/dist/wizard/lib/deploy-log.d.ts +28 -0
  101. package/dist/wizard/lib/deploy-log.js +52 -0
  102. package/dist/wizard/lib/desktop-notify.d.ts +27 -0
  103. package/dist/wizard/lib/desktop-notify.js +98 -0
  104. package/dist/wizard/lib/dns/cloudflare-dns.d.ts +35 -0
  105. package/dist/wizard/lib/dns/cloudflare-dns.js +216 -0
  106. package/dist/wizard/lib/dns/cloudflare-registrar.d.ts +31 -0
  107. package/dist/wizard/lib/dns/cloudflare-registrar.js +148 -0
  108. package/dist/wizard/lib/dns/types.d.ts +22 -0
  109. package/dist/wizard/lib/dns/types.js +4 -0
  110. package/dist/wizard/lib/document-discovery.d.ts +33 -0
  111. package/dist/wizard/lib/document-discovery.js +145 -0
  112. package/dist/wizard/lib/env-validator.d.ts +14 -0
  113. package/dist/wizard/lib/env-validator.js +205 -0
  114. package/dist/wizard/lib/env-writer.d.ts +13 -0
  115. package/dist/wizard/lib/env-writer.js +26 -0
  116. package/dist/wizard/lib/exec.d.ts +30 -0
  117. package/dist/wizard/lib/exec.js +52 -0
  118. package/dist/wizard/lib/experiment.d.ts +70 -0
  119. package/dist/wizard/lib/experiment.js +169 -0
  120. package/dist/wizard/lib/extensions.d.ts +20 -0
  121. package/dist/wizard/lib/extensions.js +183 -0
  122. package/dist/wizard/lib/financial/adapter-factory.d.ts +47 -0
  123. package/dist/wizard/lib/financial/adapter-factory.js +225 -0
  124. package/dist/wizard/lib/financial/billing/base.d.ts +6 -0
  125. package/dist/wizard/lib/financial/billing/base.js +1 -0
  126. package/dist/wizard/lib/financial/billing/google-billing.d.ts +56 -0
  127. package/dist/wizard/lib/financial/billing/google-billing.js +298 -0
  128. package/dist/wizard/lib/financial/billing/meta-billing.d.ts +54 -0
  129. package/dist/wizard/lib/financial/billing/meta-billing.js +243 -0
  130. package/dist/wizard/lib/financial/billing/tiktok-billing.d.ts +54 -0
  131. package/dist/wizard/lib/financial/billing/tiktok-billing.js +260 -0
  132. package/dist/wizard/lib/financial/campaign/base.d.ts +13 -0
  133. package/dist/wizard/lib/financial/campaign/base.js +1 -0
  134. package/dist/wizard/lib/financial/campaign/google-campaign.d.ts +42 -0
  135. package/dist/wizard/lib/financial/campaign/google-campaign.js +388 -0
  136. package/dist/wizard/lib/financial/campaign/meta-campaign.d.ts +41 -0
  137. package/dist/wizard/lib/financial/campaign/meta-campaign.js +311 -0
  138. package/dist/wizard/lib/financial/campaign/sandbox-campaign.d.ts +45 -0
  139. package/dist/wizard/lib/financial/campaign/sandbox-campaign.js +261 -0
  140. package/dist/wizard/lib/financial/campaign/tiktok-campaign.d.ts +40 -0
  141. package/dist/wizard/lib/financial/campaign/tiktok-campaign.js +350 -0
  142. package/dist/wizard/lib/financial/funding-auto.d.ts +44 -0
  143. package/dist/wizard/lib/financial/funding-auto.js +52 -0
  144. package/dist/wizard/lib/financial/funding-policy.d.ts +60 -0
  145. package/dist/wizard/lib/financial/funding-policy.js +179 -0
  146. package/dist/wizard/lib/financial/platform-planner.d.ts +47 -0
  147. package/dist/wizard/lib/financial/platform-planner.js +134 -0
  148. package/dist/wizard/lib/financial/reconciliation-engine.d.ts +78 -0
  149. package/dist/wizard/lib/financial/reconciliation-engine.js +193 -0
  150. package/dist/wizard/lib/financial/registry.d.ts +22 -0
  151. package/dist/wizard/lib/financial/registry.js +26 -0
  152. package/dist/wizard/lib/financial/reporting.d.ts +96 -0
  153. package/dist/wizard/lib/financial/reporting.js +198 -0
  154. package/dist/wizard/lib/financial/stablecoin/base.d.ts +6 -0
  155. package/dist/wizard/lib/financial/stablecoin/base.js +1 -0
  156. package/dist/wizard/lib/financial/stablecoin/circle.d.ts +54 -0
  157. package/dist/wizard/lib/financial/stablecoin/circle.js +367 -0
  158. package/dist/wizard/lib/financial/stablecoin/mercury.d.ts +24 -0
  159. package/dist/wizard/lib/financial/stablecoin/mercury.js +171 -0
  160. package/dist/wizard/lib/financial/stablecoin/sandbox-stablecoin.d.ts +47 -0
  161. package/dist/wizard/lib/financial/stablecoin/sandbox-stablecoin.js +202 -0
  162. package/dist/wizard/lib/financial/treasury-planner.d.ts +52 -0
  163. package/dist/wizard/lib/financial/treasury-planner.js +128 -0
  164. package/dist/wizard/lib/financial-core.d.ts +6 -0
  165. package/dist/wizard/lib/financial-core.js +5 -0
  166. package/dist/wizard/lib/financial-vault.d.ts +34 -0
  167. package/dist/wizard/lib/financial-vault.js +199 -0
  168. package/dist/wizard/lib/frontmatter.d.ts +30 -0
  169. package/dist/wizard/lib/frontmatter.js +96 -0
  170. package/dist/wizard/lib/gap-analysis.d.ts +37 -0
  171. package/dist/wizard/lib/gap-analysis.js +218 -0
  172. package/dist/wizard/lib/github.d.ts +22 -0
  173. package/dist/wizard/lib/github.js +261 -0
  174. package/dist/wizard/lib/headless-deploy.d.ts +14 -0
  175. package/dist/wizard/lib/headless-deploy.js +452 -0
  176. package/dist/wizard/lib/health-monitor.d.ts +15 -0
  177. package/dist/wizard/lib/health-monitor.js +91 -0
  178. package/dist/wizard/lib/health-poller.d.ts +9 -0
  179. package/dist/wizard/lib/health-poller.js +123 -0
  180. package/dist/wizard/lib/heartbeat.d.ts +15 -0
  181. package/dist/wizard/lib/heartbeat.js +827 -0
  182. package/dist/wizard/lib/http-helpers.d.ts +9 -0
  183. package/dist/wizard/lib/http-helpers.js +24 -0
  184. package/dist/wizard/lib/image-gen.d.ts +56 -0
  185. package/dist/wizard/lib/image-gen.js +159 -0
  186. package/dist/wizard/lib/instance-sizing.d.ts +26 -0
  187. package/dist/wizard/lib/instance-sizing.js +51 -0
  188. package/dist/wizard/lib/kongo/analytics.d.ts +29 -0
  189. package/dist/wizard/lib/kongo/analytics.js +179 -0
  190. package/dist/wizard/lib/kongo/campaigns.d.ts +52 -0
  191. package/dist/wizard/lib/kongo/campaigns.js +91 -0
  192. package/dist/wizard/lib/kongo/client.d.ts +58 -0
  193. package/dist/wizard/lib/kongo/client.js +221 -0
  194. package/dist/wizard/lib/kongo/jobs.d.ts +57 -0
  195. package/dist/wizard/lib/kongo/jobs.js +122 -0
  196. package/dist/wizard/lib/kongo/pages.d.ts +60 -0
  197. package/dist/wizard/lib/kongo/pages.js +150 -0
  198. package/dist/wizard/lib/kongo/provisioner.d.ts +64 -0
  199. package/dist/wizard/lib/kongo/provisioner.js +116 -0
  200. package/dist/wizard/lib/kongo/seed.d.ts +49 -0
  201. package/dist/wizard/lib/kongo/seed.js +237 -0
  202. package/dist/wizard/lib/kongo/types.d.ts +323 -0
  203. package/dist/wizard/lib/kongo/types.js +11 -0
  204. package/dist/wizard/lib/kongo/variants.d.ts +57 -0
  205. package/dist/wizard/lib/kongo/variants.js +88 -0
  206. package/dist/wizard/lib/kongo/webhooks.d.ts +41 -0
  207. package/dist/wizard/lib/kongo/webhooks.js +112 -0
  208. package/dist/wizard/lib/marker.d.ts +28 -0
  209. package/dist/wizard/lib/marker.js +79 -0
  210. package/dist/wizard/lib/migrator.d.ts +35 -0
  211. package/dist/wizard/lib/migrator.js +190 -0
  212. package/dist/wizard/lib/natural-language-deploy.d.ts +30 -0
  213. package/dist/wizard/lib/natural-language-deploy.js +186 -0
  214. package/dist/wizard/lib/network.d.ts +22 -0
  215. package/dist/wizard/lib/network.js +72 -0
  216. package/dist/wizard/lib/oauth-core.d.ts +6 -0
  217. package/dist/wizard/lib/oauth-core.js +5 -0
  218. package/dist/wizard/lib/open-browser.d.ts +1 -0
  219. package/dist/wizard/lib/open-browser.js +26 -0
  220. package/dist/wizard/lib/patterns/ad-billing-adapter.d.ts +209 -0
  221. package/dist/wizard/lib/patterns/ad-billing-adapter.js +269 -0
  222. package/dist/wizard/lib/patterns/ad-platform-adapter.d.ts +200 -0
  223. package/dist/wizard/lib/patterns/ad-platform-adapter.js +212 -0
  224. package/dist/wizard/lib/patterns/daemon-process.d.ts +88 -0
  225. package/dist/wizard/lib/patterns/daemon-process.js +271 -0
  226. package/dist/wizard/lib/patterns/financial-transaction.d.ts +161 -0
  227. package/dist/wizard/lib/patterns/financial-transaction.js +132 -0
  228. package/dist/wizard/lib/patterns/funding-plan.d.ts +136 -0
  229. package/dist/wizard/lib/patterns/funding-plan.js +200 -0
  230. package/dist/wizard/lib/patterns/oauth-token-lifecycle.d.ts +94 -0
  231. package/dist/wizard/lib/patterns/oauth-token-lifecycle.js +139 -0
  232. package/dist/wizard/lib/patterns/outbound-rate-limiter.d.ts +67 -0
  233. package/dist/wizard/lib/patterns/outbound-rate-limiter.js +216 -0
  234. package/dist/wizard/lib/patterns/revenue-source-adapter.d.ts +96 -0
  235. package/dist/wizard/lib/patterns/revenue-source-adapter.js +182 -0
  236. package/dist/wizard/lib/patterns/stablecoin-adapter.d.ts +218 -0
  237. package/dist/wizard/lib/patterns/stablecoin-adapter.js +264 -0
  238. package/dist/wizard/lib/prd-validator.d.ts +39 -0
  239. package/dist/wizard/lib/prd-validator.js +137 -0
  240. package/dist/wizard/lib/project-init.d.ts +24 -0
  241. package/dist/wizard/lib/project-init.js +193 -0
  242. package/dist/wizard/lib/project-registry.d.ts +86 -0
  243. package/dist/wizard/lib/project-registry.js +359 -0
  244. package/dist/wizard/lib/provision-manifest.d.ts +44 -0
  245. package/dist/wizard/lib/provision-manifest.js +164 -0
  246. package/dist/wizard/lib/provisioner-registry.d.ts +15 -0
  247. package/dist/wizard/lib/provisioner-registry.js +34 -0
  248. package/dist/wizard/lib/provisioners/aws-vps.d.ts +6 -0
  249. package/dist/wizard/lib/provisioners/aws-vps.js +643 -0
  250. package/dist/wizard/lib/provisioners/cloudflare.d.ts +6 -0
  251. package/dist/wizard/lib/provisioners/cloudflare.js +300 -0
  252. package/dist/wizard/lib/provisioners/docker.d.ts +6 -0
  253. package/dist/wizard/lib/provisioners/docker.js +75 -0
  254. package/dist/wizard/lib/provisioners/http-client.d.ts +20 -0
  255. package/dist/wizard/lib/provisioners/http-client.js +79 -0
  256. package/dist/wizard/lib/provisioners/railway.d.ts +6 -0
  257. package/dist/wizard/lib/provisioners/railway.js +413 -0
  258. package/dist/wizard/lib/provisioners/scripts/caddyfile.d.ts +10 -0
  259. package/dist/wizard/lib/provisioners/scripts/caddyfile.js +54 -0
  260. package/dist/wizard/lib/provisioners/scripts/deploy-vps.d.ts +10 -0
  261. package/dist/wizard/lib/provisioners/scripts/deploy-vps.js +112 -0
  262. package/dist/wizard/lib/provisioners/scripts/docker-compose.d.ts +11 -0
  263. package/dist/wizard/lib/provisioners/scripts/docker-compose.js +91 -0
  264. package/dist/wizard/lib/provisioners/scripts/dockerfile.d.ts +5 -0
  265. package/dist/wizard/lib/provisioners/scripts/dockerfile.js +185 -0
  266. package/dist/wizard/lib/provisioners/scripts/ecosystem-config.d.ts +10 -0
  267. package/dist/wizard/lib/provisioners/scripts/ecosystem-config.js +36 -0
  268. package/dist/wizard/lib/provisioners/scripts/provision-vps.d.ts +14 -0
  269. package/dist/wizard/lib/provisioners/scripts/provision-vps.js +202 -0
  270. package/dist/wizard/lib/provisioners/scripts/rollback-vps.d.ts +10 -0
  271. package/dist/wizard/lib/provisioners/scripts/rollback-vps.js +67 -0
  272. package/dist/wizard/lib/provisioners/self-deploy.d.ts +41 -0
  273. package/dist/wizard/lib/provisioners/self-deploy.js +185 -0
  274. package/dist/wizard/lib/provisioners/static-s3.d.ts +6 -0
  275. package/dist/wizard/lib/provisioners/static-s3.js +235 -0
  276. package/dist/wizard/lib/provisioners/types.d.ts +40 -0
  277. package/dist/wizard/lib/provisioners/types.js +4 -0
  278. package/dist/wizard/lib/provisioners/vercel.d.ts +6 -0
  279. package/dist/wizard/lib/provisioners/vercel.js +287 -0
  280. package/dist/wizard/lib/pty-manager.d.ts +42 -0
  281. package/dist/wizard/lib/pty-manager.js +231 -0
  282. package/dist/wizard/lib/rate-limiter-core.d.ts +5 -0
  283. package/dist/wizard/lib/rate-limiter-core.js +5 -0
  284. package/dist/wizard/lib/reconciliation.d.ts +43 -0
  285. package/dist/wizard/lib/reconciliation.js +173 -0
  286. package/dist/wizard/lib/revenue-types.d.ts +5 -0
  287. package/dist/wizard/lib/revenue-types.js +1 -0
  288. package/dist/wizard/lib/route-optimizer.d.ts +28 -0
  289. package/dist/wizard/lib/route-optimizer.js +93 -0
  290. package/dist/wizard/lib/s3-deploy.d.ts +19 -0
  291. package/dist/wizard/lib/s3-deploy.js +156 -0
  292. package/dist/wizard/lib/safety-tiers.d.ts +76 -0
  293. package/dist/wizard/lib/safety-tiers.js +134 -0
  294. package/dist/wizard/lib/sentry-generator.d.ts +15 -0
  295. package/dist/wizard/lib/sentry-generator.js +116 -0
  296. package/dist/wizard/lib/server-config.d.ts +13 -0
  297. package/dist/wizard/lib/server-config.js +23 -0
  298. package/dist/wizard/lib/service-install.d.ts +18 -0
  299. package/dist/wizard/lib/service-install.js +182 -0
  300. package/dist/wizard/lib/site-scanner.d.ts +80 -0
  301. package/dist/wizard/lib/site-scanner.js +262 -0
  302. package/dist/wizard/lib/ssh-deploy.d.ts +25 -0
  303. package/dist/wizard/lib/ssh-deploy.js +225 -0
  304. package/dist/wizard/lib/templates.d.ts +24 -0
  305. package/dist/wizard/lib/templates.js +219 -0
  306. package/dist/wizard/lib/totp.d.ts +35 -0
  307. package/dist/wizard/lib/totp.js +276 -0
  308. package/dist/wizard/lib/tower-auth.d.ts +43 -0
  309. package/dist/wizard/lib/tower-auth.js +352 -0
  310. package/dist/wizard/lib/tower-rate-limit.d.ts +14 -0
  311. package/dist/wizard/lib/tower-rate-limit.js +61 -0
  312. package/dist/wizard/lib/tower-session.d.ts +28 -0
  313. package/dist/wizard/lib/tower-session.js +119 -0
  314. package/dist/wizard/lib/treasury-backup.d.ts +23 -0
  315. package/dist/wizard/lib/treasury-backup.js +126 -0
  316. package/dist/wizard/lib/treasury-heartbeat.d.ts +82 -0
  317. package/dist/wizard/lib/treasury-heartbeat.js +1104 -0
  318. package/dist/wizard/lib/updater.d.ts +29 -0
  319. package/dist/wizard/lib/updater.js +190 -0
  320. package/dist/wizard/lib/user-manager.d.ts +39 -0
  321. package/dist/wizard/lib/user-manager.js +182 -0
  322. package/dist/wizard/lib/vault.d.ts +26 -0
  323. package/dist/wizard/lib/vault.js +161 -0
  324. package/dist/wizard/router.d.ts +5 -0
  325. package/dist/wizard/router.js +15 -0
  326. package/dist/wizard/server.d.ts +18 -0
  327. package/dist/wizard/server.js +436 -0
  328. package/package.json +59 -0
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Pattern: Ad Billing Adapter (Split Interface)
3
+ *
4
+ * Key principles:
5
+ * - Billing is SEPARATE from campaign CRUD. This adapter handles how ad platforms
6
+ * get paid (invoices, direct debits, settlements), not how campaigns are managed.
7
+ * Campaign operations live in ad-platform-adapter.ts.
8
+ * - Three capability states determine what Treasury can automate:
9
+ * FULLY_FUNDABLE — Treasury manages settlement lifecycle end-to-end
10
+ * MONITORED_ONLY — spend and billing are observed, but funding is not automated
11
+ * UNSUPPORTED — billing configuration blocks any automation
12
+ * - Split interface: AdBillingSetup (interactive) + AdBillingAdapter (runtime)
13
+ * - Single-writer: only Heartbeat daemon calls the runtime adapter
14
+ * - All amounts in branded integer cents (Cents type from financial-transaction.ts)
15
+ *
16
+ * Agents: Dockson (treasury), Wax (paid ads), Heartbeat daemon
17
+ *
18
+ * PRD Reference: §10.2, §11.1B, §12.3
19
+ *
20
+ * Google Ads Billing API reference:
21
+ * Billing setup: managed via Google Ads UI — no API for enabling monthly invoicing.
22
+ * Read-only API paths (Ads API v16+):
23
+ * BillingSetup resource → billingSetup.status, paymentsAccount, paymentsProfile
24
+ * Invoice resource → GET /customers/{id}/invoices (monthly invoicing accounts only)
25
+ * Fields: invoice.id, invoice.type, invoice.due_date, invoice.total_amount_micros
26
+ * Note: amounts in micros (1/1,000,000 of currency unit). Divide by 10,000 for cents.
27
+ * payments_account_id identifies the payments profile linked to billing.
28
+ * monthly_invoicing must be enabled by Google — not programmatically toggleable.
29
+ *
30
+ * Meta Ads Billing reference:
31
+ * No first-party invoice API. Billing is managed via:
32
+ * GET /act_{id}?fields=funding_source,funding_source_details → funding method classification
33
+ * funding_source_details.type: 1=credit_card, 2=debit_card, 4=direct_debit,
34
+ * 5=paypal, 8=extended_credit, 11=invoice
35
+ * Direct debit: Meta pulls from linked bank. No settlement instruction needed.
36
+ * Extended credit / invoicing: available to qualifying business accounts.
37
+ * For direct debit accounts, Treasury maintains a buffer; for invoiced accounts,
38
+ * Treasury tracks due dates and settlement instructions.
39
+ */
40
+ type Cents = number & {
41
+ readonly __brand: 'Cents';
42
+ };
43
+ declare function toCents(dollars: number): Cents;
44
+ type CapabilityState = 'FULLY_FUNDABLE' | 'MONITORED_ONLY' | 'UNSUPPORTED';
45
+ type BillingMode = 'monthly_invoicing' | 'direct_debit' | 'extended_credit' | 'manual_bank_transfer' | 'card_only' | 'unknown';
46
+ type AdPlatform = 'google' | 'meta' | 'tiktok' | 'linkedin' | 'twitter' | 'reddit' | 'snap';
47
+ interface Invoice {
48
+ id: string;
49
+ platform: AdPlatform;
50
+ externalAccountId: string;
51
+ amountCents: Cents;
52
+ currency: 'USD';
53
+ issueDate: string;
54
+ dueDate: string;
55
+ status: 'pending' | 'paid' | 'overdue' | 'cancelled';
56
+ lineItems?: InvoiceLineItem[];
57
+ paymentReference?: string;
58
+ }
59
+ interface InvoiceLineItem {
60
+ description: string;
61
+ amountCents: Cents;
62
+ campaignId?: string;
63
+ }
64
+ interface ExpectedDebit {
65
+ id: string;
66
+ platform: AdPlatform;
67
+ externalAccountId: string;
68
+ estimatedAmountCents: Cents;
69
+ currency: 'USD';
70
+ expectedDate: string;
71
+ status: 'expected' | 'detected' | 'confirmed' | 'failed';
72
+ bankTransactionId?: string;
73
+ }
74
+ interface SettlementInstruction {
75
+ invoiceId: string;
76
+ platform: AdPlatform;
77
+ payeeName: string;
78
+ paymentMethod: 'wire' | 'ach' | 'direct_debit';
79
+ amountCents: Cents;
80
+ currency: 'USD';
81
+ dueDate: string;
82
+ bankReference?: string;
83
+ routingNumber?: string;
84
+ accountNumber?: string;
85
+ notes: string;
86
+ }
87
+ interface PlatformBillingProfile {
88
+ platform: AdPlatform;
89
+ capabilityState: CapabilityState;
90
+ billingMode: BillingMode;
91
+ externalAccountId: string;
92
+ billingSetupId?: string;
93
+ invoiceGroupId?: string;
94
+ paymentProfileId?: string;
95
+ fundingSourceId?: string;
96
+ currency: 'USD';
97
+ nextDueDate?: string;
98
+ status: 'active' | 'degraded' | 'suspended' | 'unconfigured';
99
+ lastVerifiedAt: string;
100
+ }
101
+ interface BillingConfiguration {
102
+ billingMode: BillingMode;
103
+ accountIds: {
104
+ externalAccountId: string;
105
+ billingSetupId?: string;
106
+ invoiceGroupId?: string;
107
+ paymentProfileId?: string;
108
+ fundingSourceId?: string;
109
+ };
110
+ nextDueDate?: string;
111
+ estimatedMonthlySpendCents?: Cents;
112
+ }
113
+ interface NormalizedFundingState {
114
+ platform: AdPlatform;
115
+ capabilityState: CapabilityState;
116
+ billingMode: BillingMode;
117
+ outstandingCents: Cents;
118
+ nextPaymentDueDate?: string;
119
+ daysUntilNextPayment?: number;
120
+ fundingHealthy: boolean;
121
+ warnings: string[];
122
+ }
123
+ interface DateRange {
124
+ start: string;
125
+ end: string;
126
+ }
127
+ interface AdBillingSetup {
128
+ /** Determine what level of funding automation this platform supports */
129
+ verifyBillingCapability(platform: AdPlatform, externalAccountId: string, tokens: {
130
+ accessToken: string;
131
+ }): Promise<CapabilityState>;
132
+ /** Read the billing configuration details for storage in vault */
133
+ readBillingConfiguration(platform: AdPlatform, externalAccountId: string, tokens: {
134
+ accessToken: string;
135
+ }): Promise<BillingConfiguration>;
136
+ /** Auto-detect the billing mode from platform API responses */
137
+ detectBillingMode(platform: AdPlatform, externalAccountId: string, tokens: {
138
+ accessToken: string;
139
+ }): Promise<BillingMode>;
140
+ }
141
+ interface AdBillingAdapter {
142
+ /** Current capability state — may degrade at runtime if billing config changes */
143
+ getCapabilityState(platform: AdPlatform): Promise<CapabilityState>;
144
+ /** List pending and paid invoices in date range (Google monthly invoicing) */
145
+ readInvoices(platform: AdPlatform, dateRange: DateRange): Promise<Invoice[]>;
146
+ /** List expected bank debits in date range (Meta direct debit) */
147
+ readExpectedDebits(platform: AdPlatform, dateRange: DateRange): Promise<ExpectedDebit[]>;
148
+ /** Generate a settlement instruction for a specific invoice */
149
+ generateSettlementInstructions(invoice: Invoice): Promise<SettlementInstruction>;
150
+ /** Confirm that an invoice was settled by linking to a bank transaction */
151
+ confirmSettlement(invoiceId: string, bankTransactionId: string): Promise<{
152
+ confirmed: boolean;
153
+ reconciledAmountCents: Cents;
154
+ varianceCents: Cents;
155
+ }>;
156
+ /** Unified funding view across all connected platforms */
157
+ normalizeFundingState(): Promise<NormalizedFundingState[]>;
158
+ }
159
+ declare class GoogleBillingAdapter implements AdBillingSetup, AdBillingAdapter {
160
+ private readonly adsApiUrl;
161
+ private profiles;
162
+ verifyBillingCapability(_platform: AdPlatform, externalAccountId: string, tokens: {
163
+ accessToken: string;
164
+ }): Promise<CapabilityState>;
165
+ readBillingConfiguration(_platform: AdPlatform, externalAccountId: string, tokens: {
166
+ accessToken: string;
167
+ }): Promise<BillingConfiguration>;
168
+ detectBillingMode(_platform: AdPlatform, externalAccountId: string, tokens: {
169
+ accessToken: string;
170
+ }): Promise<BillingMode>;
171
+ getCapabilityState(_platform: AdPlatform): Promise<CapabilityState>;
172
+ readInvoices(_platform: AdPlatform, dateRange: DateRange): Promise<Invoice[]>;
173
+ readExpectedDebits(_platform: AdPlatform, _dateRange: DateRange): Promise<ExpectedDebit[]>;
174
+ generateSettlementInstructions(invoice: Invoice): Promise<SettlementInstruction>;
175
+ confirmSettlement(invoiceId: string, bankTransactionId: string): Promise<{
176
+ confirmed: boolean;
177
+ reconciledAmountCents: Cents;
178
+ varianceCents: Cents;
179
+ }>;
180
+ normalizeFundingState(): Promise<NormalizedFundingState[]>;
181
+ private queryBillingSetup;
182
+ private classifyGoogleBillingMode;
183
+ }
184
+ declare class MetaBillingAdapter implements AdBillingSetup, AdBillingAdapter {
185
+ private readonly baseUrl;
186
+ private profiles;
187
+ verifyBillingCapability(_platform: AdPlatform, externalAccountId: string, tokens: {
188
+ accessToken: string;
189
+ }): Promise<CapabilityState>;
190
+ readBillingConfiguration(_platform: AdPlatform, externalAccountId: string, tokens: {
191
+ accessToken: string;
192
+ }): Promise<BillingConfiguration>;
193
+ detectBillingMode(_platform: AdPlatform, externalAccountId: string, tokens: {
194
+ accessToken: string;
195
+ }): Promise<BillingMode>;
196
+ getCapabilityState(_platform: AdPlatform): Promise<CapabilityState>;
197
+ readInvoices(_platform: AdPlatform, _dateRange: DateRange): Promise<Invoice[]>;
198
+ readExpectedDebits(_platform: AdPlatform, dateRange: DateRange): Promise<ExpectedDebit[]>;
199
+ generateSettlementInstructions(invoice: Invoice): Promise<SettlementInstruction>;
200
+ confirmSettlement(invoiceId: string, bankTransactionId: string): Promise<{
201
+ confirmed: boolean;
202
+ reconciledAmountCents: Cents;
203
+ varianceCents: Cents;
204
+ }>;
205
+ normalizeFundingState(): Promise<NormalizedFundingState[]>;
206
+ private apiCall;
207
+ }
208
+ export type { AdBillingSetup, AdBillingAdapter, CapabilityState, BillingMode, AdPlatform, Invoice, InvoiceLineItem, ExpectedDebit, SettlementInstruction, PlatformBillingProfile, BillingConfiguration, NormalizedFundingState, DateRange, Cents, };
209
+ export { toCents, GoogleBillingAdapter, MetaBillingAdapter };
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Pattern: Ad Billing Adapter (Split Interface)
3
+ *
4
+ * Key principles:
5
+ * - Billing is SEPARATE from campaign CRUD. This adapter handles how ad platforms
6
+ * get paid (invoices, direct debits, settlements), not how campaigns are managed.
7
+ * Campaign operations live in ad-platform-adapter.ts.
8
+ * - Three capability states determine what Treasury can automate:
9
+ * FULLY_FUNDABLE — Treasury manages settlement lifecycle end-to-end
10
+ * MONITORED_ONLY — spend and billing are observed, but funding is not automated
11
+ * UNSUPPORTED — billing configuration blocks any automation
12
+ * - Split interface: AdBillingSetup (interactive) + AdBillingAdapter (runtime)
13
+ * - Single-writer: only Heartbeat daemon calls the runtime adapter
14
+ * - All amounts in branded integer cents (Cents type from financial-transaction.ts)
15
+ *
16
+ * Agents: Dockson (treasury), Wax (paid ads), Heartbeat daemon
17
+ *
18
+ * PRD Reference: §10.2, §11.1B, §12.3
19
+ *
20
+ * Google Ads Billing API reference:
21
+ * Billing setup: managed via Google Ads UI — no API for enabling monthly invoicing.
22
+ * Read-only API paths (Ads API v16+):
23
+ * BillingSetup resource → billingSetup.status, paymentsAccount, paymentsProfile
24
+ * Invoice resource → GET /customers/{id}/invoices (monthly invoicing accounts only)
25
+ * Fields: invoice.id, invoice.type, invoice.due_date, invoice.total_amount_micros
26
+ * Note: amounts in micros (1/1,000,000 of currency unit). Divide by 10,000 for cents.
27
+ * payments_account_id identifies the payments profile linked to billing.
28
+ * monthly_invoicing must be enabled by Google — not programmatically toggleable.
29
+ *
30
+ * Meta Ads Billing reference:
31
+ * No first-party invoice API. Billing is managed via:
32
+ * GET /act_{id}?fields=funding_source,funding_source_details → funding method classification
33
+ * funding_source_details.type: 1=credit_card, 2=debit_card, 4=direct_debit,
34
+ * 5=paypal, 8=extended_credit, 11=invoice
35
+ * Direct debit: Meta pulls from linked bank. No settlement instruction needed.
36
+ * Extended credit / invoicing: available to qualifying business accounts.
37
+ * For direct debit accounts, Treasury maintains a buffer; for invoiced accounts,
38
+ * Treasury tracks due dates and settlement instructions.
39
+ */
40
+ function toCents(dollars) {
41
+ return Math.round(dollars * 100);
42
+ }
43
+ // ── Reference Implementation: Google Billing ─────────
44
+ // Production implementation would live in wizard/lib/financial/billing/google-billing.ts
45
+ class GoogleBillingAdapter {
46
+ adsApiUrl = 'https://googleads.googleapis.com/v16';
47
+ profiles = new Map();
48
+ // ── Setup (interactive) ──────────
49
+ async verifyBillingCapability(_platform, externalAccountId, tokens) {
50
+ const mode = await this.detectBillingMode('google', externalAccountId, tokens);
51
+ if (mode === 'monthly_invoicing')
52
+ return 'FULLY_FUNDABLE';
53
+ if (mode === 'manual_bank_transfer')
54
+ return 'MONITORED_ONLY';
55
+ if (mode === 'unknown' || mode === 'card_only')
56
+ return 'UNSUPPORTED';
57
+ return 'MONITORED_ONLY';
58
+ }
59
+ async readBillingConfiguration(_platform, externalAccountId, tokens) {
60
+ // Google Ads API: query billing_setup resource
61
+ // SELECT billing_setup.id, billing_setup.status, billing_setup.payments_account,
62
+ // billing_setup.payments_profile
63
+ // FROM billing_setup
64
+ const billingSetup = await this.queryBillingSetup(externalAccountId, tokens);
65
+ const mode = this.classifyGoogleBillingMode(billingSetup);
66
+ return {
67
+ billingMode: mode,
68
+ accountIds: {
69
+ externalAccountId,
70
+ billingSetupId: billingSetup.id,
71
+ paymentProfileId: billingSetup.paymentsProfile,
72
+ },
73
+ };
74
+ }
75
+ async detectBillingMode(_platform, externalAccountId, tokens) {
76
+ const billingSetup = await this.queryBillingSetup(externalAccountId, tokens);
77
+ return this.classifyGoogleBillingMode(billingSetup);
78
+ }
79
+ // ── Runtime (daemon) ──────────
80
+ async getCapabilityState(_platform) {
81
+ // Re-verify from cached profile — full re-check happens on scheduled interval
82
+ const profile = this.profiles.get('google');
83
+ return profile?.capabilityState ?? 'UNSUPPORTED';
84
+ }
85
+ async readInvoices(_platform, dateRange) {
86
+ // Google Ads API: query invoice resource
87
+ // SELECT invoice.id, invoice.type, invoice.due_date,
88
+ // invoice.service_date_range, invoice.total_amount_micros,
89
+ // invoice.payments_account_id
90
+ // FROM invoice
91
+ // WHERE invoice.issue_date >= '{dateRange.start}'
92
+ // AND invoice.issue_date <= '{dateRange.end}'
93
+ //
94
+ // Amounts are in micros: divide by 10,000 to get cents
95
+ // e.g., 1,500,000,000 micros = $1,500.00 = 150,000 cents
96
+ throw new Error('HTTP implementation — use node:https with Google Ads REST API');
97
+ }
98
+ async readExpectedDebits(_platform, _dateRange) {
99
+ // Google does not use direct debit in the monthly invoicing flow.
100
+ // This method returns empty for Google — debits are a Meta concept.
101
+ return [];
102
+ }
103
+ async generateSettlementInstructions(invoice) {
104
+ // Google monthly invoicing: payment via wire/ACH to Google's bank account
105
+ // Payment instructions are on the invoice itself.
106
+ // Reference number must be included for matching.
107
+ return {
108
+ invoiceId: invoice.id,
109
+ platform: 'google',
110
+ payeeName: 'Google Ads',
111
+ paymentMethod: 'wire',
112
+ amountCents: invoice.amountCents,
113
+ currency: 'USD',
114
+ dueDate: invoice.dueDate,
115
+ bankReference: invoice.paymentReference,
116
+ notes: `Google monthly invoice ${invoice.id} — wire payment with reference ${invoice.paymentReference ?? 'see invoice'}`,
117
+ };
118
+ }
119
+ async confirmSettlement(invoiceId, bankTransactionId) {
120
+ // Match bank transaction amount against invoice amount.
121
+ // In production: read from bank adapter + invoice store.
122
+ // Variance threshold: configurable, default 0 cents for exact match.
123
+ throw new Error('Implementation requires invoice store + bank adapter integration');
124
+ }
125
+ async normalizeFundingState() {
126
+ const profile = this.profiles.get('google');
127
+ if (!profile)
128
+ return [];
129
+ const invoices = await this.readInvoices('google', {
130
+ start: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000).toISOString(),
131
+ end: new Date().toISOString(),
132
+ });
133
+ const pending = invoices.filter(i => i.status === 'pending' || i.status === 'overdue');
134
+ const outstandingCents = pending.reduce((sum, i) => (sum + i.amountCents), 0);
135
+ const overdue = pending.some(i => i.status === 'overdue');
136
+ return [{
137
+ platform: 'google',
138
+ capabilityState: profile.capabilityState,
139
+ billingMode: profile.billingMode,
140
+ outstandingCents,
141
+ nextPaymentDueDate: profile.nextDueDate,
142
+ daysUntilNextPayment: profile.nextDueDate
143
+ ? Math.ceil((new Date(profile.nextDueDate).getTime() - Date.now()) / (24 * 60 * 60 * 1000))
144
+ : undefined,
145
+ fundingHealthy: !overdue && profile.status === 'active',
146
+ warnings: overdue ? ['Overdue Google Ads invoice — settlement required'] : [],
147
+ }];
148
+ }
149
+ // ── Private helpers ──────────
150
+ async queryBillingSetup(_externalAccountId, _tokens) {
151
+ // POST {adsApiUrl}/customers/{id}/googleAds:searchStream
152
+ // Body: { query: "SELECT billing_setup.id, ..." }
153
+ // Headers: Authorization: Bearer {accessToken}, developer-token: {devToken}
154
+ throw new Error('HTTP implementation — use node:https with Google Ads REST API');
155
+ }
156
+ classifyGoogleBillingMode(billingSetup) {
157
+ const status = billingSetup.status;
158
+ if (status === 'APPROVED')
159
+ return 'monthly_invoicing';
160
+ if (status === 'PENDING')
161
+ return 'unknown';
162
+ if (status === 'CANCELLED')
163
+ return 'unknown';
164
+ return 'unknown';
165
+ }
166
+ }
167
+ // ── Reference Implementation: Meta Billing ───────────
168
+ // Production implementation would live in wizard/lib/financial/billing/meta-billing.ts
169
+ class MetaBillingAdapter {
170
+ baseUrl = 'https://graph.facebook.com/v19.0';
171
+ profiles = new Map();
172
+ // ── Setup (interactive) ──────────
173
+ async verifyBillingCapability(_platform, externalAccountId, tokens) {
174
+ const mode = await this.detectBillingMode('meta', externalAccountId, tokens);
175
+ if (mode === 'direct_debit' || mode === 'extended_credit')
176
+ return 'FULLY_FUNDABLE';
177
+ if (mode === 'card_only')
178
+ return 'UNSUPPORTED';
179
+ return 'MONITORED_ONLY';
180
+ }
181
+ async readBillingConfiguration(_platform, externalAccountId, tokens) {
182
+ const mode = await this.detectBillingMode('meta', externalAccountId, tokens);
183
+ return {
184
+ billingMode: mode,
185
+ accountIds: {
186
+ externalAccountId,
187
+ },
188
+ };
189
+ }
190
+ async detectBillingMode(_platform, externalAccountId, tokens) {
191
+ // GET /act_{id}?fields=funding_source_details&access_token={token}
192
+ // Response: { funding_source_details: { id, type, display_string } }
193
+ // type values: 1=credit_card, 2=debit_card, 4=direct_debit,
194
+ // 5=paypal, 8=extended_credit, 11=invoice
195
+ const res = await this.apiCall('GET', `/act_${externalAccountId}`, tokens.accessToken, { fields: 'funding_source_details' });
196
+ const details = res.funding_source_details;
197
+ const fundingType = details?.type;
198
+ switch (fundingType) {
199
+ case 4: return 'direct_debit';
200
+ case 8: return 'extended_credit';
201
+ case 11: return 'monthly_invoicing';
202
+ case 1:
203
+ case 2: return 'card_only';
204
+ default: return 'unknown';
205
+ }
206
+ }
207
+ // ── Runtime (daemon) ──────────
208
+ async getCapabilityState(_platform) {
209
+ const profile = this.profiles.get('meta');
210
+ return profile?.capabilityState ?? 'UNSUPPORTED';
211
+ }
212
+ async readInvoices(_platform, _dateRange) {
213
+ // Meta does not expose a first-party invoice API for most account types.
214
+ // For extended_credit accounts: invoices may be available via Business Manager.
215
+ // In V1: return empty — Meta billing is tracked via expected debits.
216
+ return [];
217
+ }
218
+ async readExpectedDebits(_platform, dateRange) {
219
+ // For direct debit accounts: estimate upcoming debits from recent spend.
220
+ // Meta typically debits when spend threshold is reached or on billing date.
221
+ // This is a forecast based on spend velocity, not a platform API call.
222
+ // The actual debit is detected when it appears in the bank account.
223
+ throw new Error('Implementation requires spend history + bank transaction detection');
224
+ }
225
+ async generateSettlementInstructions(invoice) {
226
+ // Meta direct debit: no manual settlement needed — Meta pulls from bank.
227
+ // Meta extended credit / invoicing: payment instructions on invoice.
228
+ return {
229
+ invoiceId: invoice.id,
230
+ platform: 'meta',
231
+ payeeName: 'Meta Platforms Inc',
232
+ paymentMethod: 'direct_debit',
233
+ amountCents: invoice.amountCents,
234
+ currency: 'USD',
235
+ dueDate: invoice.dueDate,
236
+ notes: 'Meta direct debit — ensure sufficient bank balance before debit date',
237
+ };
238
+ }
239
+ async confirmSettlement(invoiceId, bankTransactionId) {
240
+ throw new Error('Implementation requires invoice store + bank adapter integration');
241
+ }
242
+ async normalizeFundingState() {
243
+ const profile = this.profiles.get('meta');
244
+ if (!profile)
245
+ return [];
246
+ return [{
247
+ platform: 'meta',
248
+ capabilityState: profile.capabilityState,
249
+ billingMode: profile.billingMode,
250
+ outstandingCents: 0, // Meta direct debit is pulled, not pushed
251
+ nextPaymentDueDate: profile.nextDueDate,
252
+ daysUntilNextPayment: profile.nextDueDate
253
+ ? Math.ceil((new Date(profile.nextDueDate).getTime() - Date.now()) / (24 * 60 * 60 * 1000))
254
+ : undefined,
255
+ fundingHealthy: profile.status === 'active',
256
+ warnings: profile.status === 'degraded'
257
+ ? ['Meta billing degraded — check funding source status']
258
+ : [],
259
+ }];
260
+ }
261
+ // ── Private helpers ──────────
262
+ async apiCall(method, path, accessToken, params) {
263
+ // Implementation: raw HTTPS (no SDK — zero dependency principle)
264
+ // Headers: Authorization: Bearer {accessToken}
265
+ // Sanitize response strings per §9.19.16 before returning
266
+ throw new Error('HTTP implementation — use node:https, no SDK dependencies');
267
+ }
268
+ }
269
+ export { toCents, GoogleBillingAdapter, MetaBillingAdapter };
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Pattern: Ad Platform Adapter (Split Interface)
3
+ *
4
+ * Key principles:
5
+ * - Separate interactive setup (browser OAuth) from runtime operations (daemon)
6
+ * - AdPlatformSetup runs in CLI/Danger Room (interactive, user-present)
7
+ * - AdPlatformAdapter runs in heartbeat daemon (non-interactive, autonomous)
8
+ * - All amounts in integer cents (Cents branded type) — never float
9
+ * - Rate limiting per-platform with token bucket
10
+ * - Errors normalized to common PlatformError format
11
+ * - Idempotency keys on all write operations (WAL pattern per ADR-3)
12
+ *
13
+ * Agents: Breeze (platform relations), Wax (paid ads), Dockson (treasury)
14
+ *
15
+ * PRD Reference: §9.5, §9.19.10, §9.20.4
16
+ *
17
+ * Authorization Guard (§9.20.4):
18
+ * Daemon Tier 1 jobs receive ReadOnlyAdapter (pause, read operations only).
19
+ * Authenticated external commands receive full AdPlatformAdapter.
20
+ * See financial-transaction.ts for the Cents branded type.
21
+ */
22
+ type Cents = number & {
23
+ readonly __brand: 'Cents';
24
+ };
25
+ type Percentage = number & {
26
+ readonly __brand: 'Percentage';
27
+ };
28
+ type Ratio = number & {
29
+ readonly __brand: 'Ratio';
30
+ };
31
+ declare function toCents(dollars: number): Cents;
32
+ declare function toDollars(cents: Cents): number;
33
+ type AdPlatform = 'meta' | 'google' | 'tiktok' | 'linkedin' | 'twitter' | 'reddit' | 'snap';
34
+ interface OAuthTokens {
35
+ accessToken: string;
36
+ refreshToken: string;
37
+ expiresAt: string;
38
+ platform: AdPlatform;
39
+ scopes: string[];
40
+ }
41
+ interface ConnectionStatus {
42
+ connected: boolean;
43
+ accountId?: string;
44
+ accountName?: string;
45
+ currency?: string;
46
+ error?: string;
47
+ }
48
+ interface PlatformError {
49
+ platform: AdPlatform;
50
+ code: 'RATE_LIMITED' | 'AUTH_EXPIRED' | 'BUDGET_EXCEEDED' | 'CREATIVE_REJECTED' | 'UNKNOWN';
51
+ originalCode: number;
52
+ message: string;
53
+ retryable: boolean;
54
+ retryAfter?: number;
55
+ }
56
+ interface CampaignConfig {
57
+ name: string;
58
+ platform: AdPlatform;
59
+ objective: 'awareness' | 'traffic' | 'conversions';
60
+ dailyBudget: Cents;
61
+ targeting: {
62
+ audiences: string[];
63
+ locations: string[];
64
+ ageRange?: [number, number];
65
+ interests?: string[];
66
+ };
67
+ creative: {
68
+ headlines: string[];
69
+ descriptions: string[];
70
+ callToAction: string;
71
+ landingUrl: string;
72
+ imageUrls?: string[];
73
+ };
74
+ testGroupId?: string;
75
+ testVariant?: string;
76
+ schedule?: {
77
+ startDate?: string;
78
+ endDate?: string;
79
+ };
80
+ idempotencyKey: string;
81
+ complianceStatus: 'passed' | 'pending';
82
+ }
83
+ interface CampaignResult {
84
+ externalId: string;
85
+ platform: AdPlatform;
86
+ status: 'created' | 'pending_review';
87
+ dashboardUrl: string;
88
+ }
89
+ interface CampaignUpdate {
90
+ name?: string;
91
+ dailyBudget?: Cents;
92
+ targeting?: Partial<CampaignConfig['targeting']>;
93
+ schedule?: CampaignConfig['schedule'];
94
+ }
95
+ interface CreativeConfig {
96
+ headlines?: string[];
97
+ descriptions?: string[];
98
+ callToAction?: string;
99
+ landingUrl?: string;
100
+ imageUrls?: string[];
101
+ }
102
+ interface SpendReport {
103
+ platform: AdPlatform;
104
+ dateRange: {
105
+ start: string;
106
+ end: string;
107
+ };
108
+ totalSpend: Cents;
109
+ campaigns: Array<{
110
+ externalId: string;
111
+ spend: Cents;
112
+ impressions: number;
113
+ clicks: number;
114
+ conversions: number;
115
+ }>;
116
+ }
117
+ interface PerformanceMetrics {
118
+ campaignId: string;
119
+ impressions: number;
120
+ clicks: number;
121
+ conversions: number;
122
+ spend: Cents;
123
+ ctr: Percentage;
124
+ cpc: Cents;
125
+ roas: Ratio;
126
+ }
127
+ interface InsightData {
128
+ campaignId: string;
129
+ metrics: Record<string, number>;
130
+ recommendations?: string[];
131
+ }
132
+ interface AdPlatformSetup {
133
+ /** Interactive OAuth flow — opens browser for authorization */
134
+ authenticate(): Promise<OAuthTokens>;
135
+ /** Verify the connection works and return account info */
136
+ verifyConnection(tokens: OAuthTokens): Promise<ConnectionStatus>;
137
+ /** Detect account currency for ADR-6 enforcement */
138
+ detectCurrency(tokens: OAuthTokens): Promise<string>;
139
+ }
140
+ interface AdPlatformAdapter {
141
+ refreshToken(token: OAuthTokens): Promise<OAuthTokens>;
142
+ createCampaign(config: CampaignConfig): Promise<CampaignResult>;
143
+ updateCampaign(id: string, changes: CampaignUpdate): Promise<void>;
144
+ pauseCampaign(id: string): Promise<void>;
145
+ resumeCampaign(id: string): Promise<void>;
146
+ deleteCampaign(id: string): Promise<void>;
147
+ updateBudget(id: string, dailyBudget: Cents): Promise<void>;
148
+ updateCreative(id: string, creative: CreativeConfig): Promise<void>;
149
+ getSpend(dateRange: {
150
+ start: string;
151
+ end: string;
152
+ }): Promise<SpendReport>;
153
+ getPerformance(campaignId: string): Promise<PerformanceMetrics>;
154
+ getInsights(campaignId: string, metrics: string[]): Promise<InsightData>;
155
+ handleWebhook?(payload: unknown): Promise<{
156
+ processed: boolean;
157
+ }>;
158
+ verifyWebhookSignature?(payload: Buffer, signature: string): boolean;
159
+ }
160
+ type ReadOnlyAdapter = Pick<AdPlatformAdapter, 'pauseCampaign' | // Protective — stopping spend is always safe
161
+ 'getSpend' | 'getPerformance' | 'getInsights' | 'refreshToken'>;
162
+ declare class MetaAdapter implements AdPlatformSetup, AdPlatformAdapter {
163
+ private adAccountId;
164
+ private readonly baseUrl;
165
+ private rateLimiter;
166
+ constructor(adAccountId: string);
167
+ authenticate(): Promise<OAuthTokens>;
168
+ verifyConnection(tokens: OAuthTokens): Promise<ConnectionStatus>;
169
+ detectCurrency(tokens: OAuthTokens): Promise<string>;
170
+ refreshToken(token: OAuthTokens): Promise<OAuthTokens>;
171
+ createCampaign(config: CampaignConfig): Promise<CampaignResult>;
172
+ pauseCampaign(id: string): Promise<void>;
173
+ resumeCampaign(id: string): Promise<void>;
174
+ deleteCampaign(id: string): Promise<void>;
175
+ updateCampaign(id: string, changes: CampaignUpdate): Promise<void>;
176
+ updateBudget(id: string, dailyBudget: Cents): Promise<void>;
177
+ updateCreative(id: string, creative: CreativeConfig): Promise<void>;
178
+ getSpend(dateRange: {
179
+ start: string;
180
+ end: string;
181
+ }): Promise<SpendReport>;
182
+ getPerformance(campaignId: string): Promise<PerformanceMetrics>;
183
+ getInsights(campaignId: string, metrics: string[]): Promise<InsightData>;
184
+ private mapObjective;
185
+ private apiCall;
186
+ }
187
+ declare class TokenBucketLimiter {
188
+ private tokens;
189
+ private lastRefill;
190
+ private readonly capacity;
191
+ private readonly refillRate;
192
+ constructor(opts: {
193
+ capacity: number;
194
+ refillRate: number;
195
+ });
196
+ acquire(): Promise<void>;
197
+ private refill;
198
+ }
199
+ export type { AdPlatformSetup, AdPlatformAdapter, ReadOnlyAdapter, CampaignConfig, CampaignResult, CampaignUpdate, CreativeConfig, SpendReport, PerformanceMetrics, InsightData, OAuthTokens, ConnectionStatus, PlatformError, Cents, Percentage, Ratio, AdPlatform, };
200
+ export { toCents, toDollars, MetaAdapter, TokenBucketLimiter };