alchemy 2.0.0-beta.13 → 2.0.0-beta.15

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 (311) hide show
  1. package/bin/alchemy.js +9477 -9290
  2. package/bin/alchemy.js.map +1 -1
  3. package/bin/alchemy.ts +6 -2
  4. package/bin/cli.js +61 -0
  5. package/bin/commands/deploy.ts +6 -4
  6. package/bin/commands/login.ts +1 -1
  7. package/bin/commands/logs.ts +1 -1
  8. package/bin/commands/state.ts +233 -0
  9. package/bin/commands/tail.ts +1 -1
  10. package/lib/AWS/AutoScaling/LaunchTemplate.d.ts +1 -1
  11. package/lib/AWS/EC2/Instance.d.ts +1 -1
  12. package/lib/AWS/EC2/hosted.d.ts +2 -2
  13. package/lib/AWS/ECS/Task.d.ts +4 -4
  14. package/lib/AWS/ECS/Task.d.ts.map +1 -1
  15. package/lib/AWS/ECS/Task.js +2 -2
  16. package/lib/AWS/ECS/Task.js.map +1 -1
  17. package/lib/AWS/Environment.d.ts +2 -2
  18. package/lib/AWS/Lambda/BucketEventSource.d.ts +1 -1
  19. package/lib/AWS/Lambda/BucketEventSource.d.ts.map +1 -1
  20. package/lib/AWS/Lambda/EventBridgeEventSource.d.ts +1 -1
  21. package/lib/AWS/Lambda/EventBridgeEventSource.d.ts.map +1 -1
  22. package/lib/AWS/Lambda/Function.d.ts +2 -2
  23. package/lib/AWS/Lambda/Function.d.ts.map +1 -1
  24. package/lib/AWS/Lambda/Function.js +1 -2
  25. package/lib/AWS/Lambda/Function.js.map +1 -1
  26. package/lib/AWS/Lambda/QueueEventSource.d.ts +1 -1
  27. package/lib/AWS/Lambda/QueueEventSource.d.ts.map +1 -1
  28. package/lib/AWS/Lambda/StreamEventSource.d.ts +1 -1
  29. package/lib/AWS/Lambda/StreamEventSource.d.ts.map +1 -1
  30. package/lib/AWS/Lambda/TableEventSource.d.ts +1 -1
  31. package/lib/AWS/Lambda/TableEventSource.d.ts.map +1 -1
  32. package/lib/AWS/Lambda/TopicEventSource.d.ts +1 -1
  33. package/lib/AWS/Lambda/TopicEventSource.d.ts.map +1 -1
  34. package/lib/AWS/SQS/QueueSink.d.ts.map +1 -1
  35. package/lib/AWS/SQS/QueueSink.js +1 -2
  36. package/lib/AWS/SQS/QueueSink.js.map +1 -1
  37. package/lib/Agent/coding/bash.d.ts +2 -6
  38. package/lib/Agent/coding/bash.d.ts.map +1 -1
  39. package/lib/Agent/coding/bash.js +2 -3
  40. package/lib/Agent/coding/bash.js.map +1 -1
  41. package/lib/Agent/coding/edit.d.ts +1 -1
  42. package/lib/Agent/coding/glob.d.ts +2 -4
  43. package/lib/Agent/coding/glob.d.ts.map +1 -1
  44. package/lib/Agent/coding/glob.js +1 -2
  45. package/lib/Agent/coding/glob.js.map +1 -1
  46. package/lib/Agent/coding/grep.d.ts +2 -4
  47. package/lib/Agent/coding/grep.d.ts.map +1 -1
  48. package/lib/Agent/coding/grep.js +1 -2
  49. package/lib/Agent/coding/grep.js.map +1 -1
  50. package/lib/Agent/coding/read.d.ts +1 -1
  51. package/lib/Agent/coding/write.d.ts +1 -1
  52. package/lib/Agent/lsp/client.d.ts +2 -2
  53. package/lib/Agent/util/ripgrep.d.ts +2 -2
  54. package/lib/AlchemyContext.d.ts +13 -0
  55. package/lib/AlchemyContext.d.ts.map +1 -0
  56. package/lib/AlchemyContext.js +18 -0
  57. package/lib/AlchemyContext.js.map +1 -0
  58. package/lib/Auth/AuthProvider.js +1 -1
  59. package/lib/Auth/AuthProvider.js.map +1 -1
  60. package/lib/Auth/Profile.d.ts +1 -1
  61. package/lib/Auth/index.d.ts +3 -1
  62. package/lib/Auth/index.d.ts.map +1 -1
  63. package/lib/Auth/index.js +3 -0
  64. package/lib/Auth/index.js.map +1 -1
  65. package/lib/Build/Command.d.ts +1 -1
  66. package/lib/Build/Memo.d.ts +1 -1
  67. package/lib/Bundle/Docker.d.ts +3 -3
  68. package/lib/Bundle/TempRoot.d.ts +3 -3
  69. package/lib/Cli/LoggingCli.d.ts +4 -0
  70. package/lib/Cli/LoggingCli.d.ts.map +1 -0
  71. package/lib/{Test/TestCli.js → Cli/LoggingCli.js} +3 -3
  72. package/lib/Cli/LoggingCli.js.map +1 -0
  73. package/lib/Cli/index.d.ts +0 -1
  74. package/lib/Cli/index.d.ts.map +1 -1
  75. package/lib/Cli/index.js +4 -1
  76. package/lib/Cli/index.js.map +1 -1
  77. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts +58 -0
  78. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts.map +1 -0
  79. package/lib/Cloudflare/ApiToken/AccountApiToken.js +137 -0
  80. package/lib/Cloudflare/ApiToken/AccountApiToken.js.map +1 -0
  81. package/lib/Cloudflare/ApiToken/Common.d.ts +91 -0
  82. package/lib/Cloudflare/ApiToken/Common.d.ts.map +1 -0
  83. package/lib/Cloudflare/ApiToken/Common.js +61 -0
  84. package/lib/Cloudflare/ApiToken/Common.js.map +1 -0
  85. package/lib/Cloudflare/ApiToken/PermissionGroups.d.ts +1549 -0
  86. package/lib/Cloudflare/ApiToken/PermissionGroups.d.ts.map +1 -0
  87. package/lib/Cloudflare/ApiToken/PermissionGroups.js +1856 -0
  88. package/lib/Cloudflare/ApiToken/PermissionGroups.js.map +1 -0
  89. package/lib/Cloudflare/ApiToken/UserApiToken.d.ts +49 -0
  90. package/lib/Cloudflare/ApiToken/UserApiToken.d.ts.map +1 -0
  91. package/lib/Cloudflare/ApiToken/UserApiToken.js +113 -0
  92. package/lib/Cloudflare/ApiToken/UserApiToken.js.map +1 -0
  93. package/lib/Cloudflare/ApiToken/index.d.ts +5 -0
  94. package/lib/Cloudflare/ApiToken/index.d.ts.map +1 -0
  95. package/lib/Cloudflare/ApiToken/index.js +5 -0
  96. package/lib/Cloudflare/ApiToken/index.js.map +1 -0
  97. package/lib/Cloudflare/Auth/AuthProvider.js +2 -2
  98. package/lib/Cloudflare/Auth/AuthProvider.js.map +1 -1
  99. package/lib/Cloudflare/CloudflareEnvironment.d.ts +1 -1
  100. package/lib/Cloudflare/Container/ContainerApplication.d.ts +2 -2
  101. package/lib/Cloudflare/Container/ContainerApplication.d.ts.map +1 -1
  102. package/lib/Cloudflare/Container/ContainerApplication.js +7 -2
  103. package/lib/Cloudflare/Container/ContainerApplication.js.map +1 -1
  104. package/lib/Cloudflare/EdgeSession.d.ts +53 -0
  105. package/lib/Cloudflare/EdgeSession.d.ts.map +1 -0
  106. package/lib/Cloudflare/EdgeSession.js +78 -0
  107. package/lib/Cloudflare/EdgeSession.js.map +1 -0
  108. package/lib/Cloudflare/Providers.d.ts +1 -1
  109. package/lib/Cloudflare/Providers.d.ts.map +1 -1
  110. package/lib/Cloudflare/Providers.js +4 -1
  111. package/lib/Cloudflare/Providers.js.map +1 -1
  112. package/lib/Cloudflare/StateStore/Api.d.ts +61 -0
  113. package/lib/Cloudflare/StateStore/Api.d.ts.map +1 -0
  114. package/lib/Cloudflare/StateStore/Api.js +103 -0
  115. package/lib/Cloudflare/StateStore/Api.js.map +1 -0
  116. package/lib/Cloudflare/StateStore/State.d.ts +39 -0
  117. package/lib/Cloudflare/StateStore/State.d.ts.map +1 -0
  118. package/lib/Cloudflare/StateStore/State.js +217 -0
  119. package/lib/Cloudflare/StateStore/State.js.map +1 -0
  120. package/lib/Cloudflare/StateStore/Store.d.ts +82 -0
  121. package/lib/Cloudflare/StateStore/Store.d.ts.map +1 -0
  122. package/lib/Cloudflare/StateStore/Store.js +191 -0
  123. package/lib/Cloudflare/StateStore/Store.js.map +1 -0
  124. package/lib/Cloudflare/StateStore/Token.d.ts +43 -0
  125. package/lib/Cloudflare/StateStore/Token.d.ts.map +1 -0
  126. package/lib/Cloudflare/StateStore/Token.js +61 -0
  127. package/lib/Cloudflare/StateStore/Token.js.map +1 -0
  128. package/lib/Cloudflare/StateStore/index.d.ts +2 -0
  129. package/lib/Cloudflare/StateStore/index.d.ts.map +1 -0
  130. package/lib/Cloudflare/StateStore/index.js +2 -0
  131. package/lib/Cloudflare/StateStore/index.js.map +1 -0
  132. package/lib/Cloudflare/Workers/Assets.d.ts +2 -2
  133. package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts +2 -2
  134. package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts.map +1 -1
  135. package/lib/Cloudflare/Workers/DurableObjectNamespace.js +0 -1
  136. package/lib/Cloudflare/Workers/DurableObjectNamespace.js.map +1 -1
  137. package/lib/Cloudflare/Workers/HttpServer.d.ts +1 -1
  138. package/lib/Cloudflare/Workers/HttpServer.d.ts.map +1 -1
  139. package/lib/Cloudflare/Workers/HttpServer.js.map +1 -1
  140. package/lib/Cloudflare/Workers/Worker.d.ts +5 -5
  141. package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
  142. package/lib/Cloudflare/Workers/Worker.js +0 -1
  143. package/lib/Cloudflare/Workers/Worker.js.map +1 -1
  144. package/lib/Cloudflare/index.d.ts +4 -1
  145. package/lib/Cloudflare/index.d.ts.map +1 -1
  146. package/lib/Cloudflare/index.js +4 -1
  147. package/lib/Cloudflare/index.js.map +1 -1
  148. package/lib/Deploy.d.ts +10 -0
  149. package/lib/Deploy.d.ts.map +1 -0
  150. package/lib/Deploy.js +12 -0
  151. package/lib/Deploy.js.map +1 -0
  152. package/lib/Destroy.d.ts +8 -3
  153. package/lib/Destroy.d.ts.map +1 -1
  154. package/lib/Destroy.js +8 -8
  155. package/lib/Destroy.js.map +1 -1
  156. package/lib/GitHub/Providers.d.ts +3 -0
  157. package/lib/GitHub/Providers.d.ts.map +1 -0
  158. package/lib/GitHub/Providers.js +5 -0
  159. package/lib/GitHub/Providers.js.map +1 -0
  160. package/lib/GitHub/index.d.ts +1 -0
  161. package/lib/GitHub/index.d.ts.map +1 -1
  162. package/lib/GitHub/index.js +1 -0
  163. package/lib/GitHub/index.js.map +1 -1
  164. package/lib/Http.d.ts +1 -1
  165. package/lib/Http.d.ts.map +1 -1
  166. package/lib/Http.js +7 -3
  167. package/lib/Http.js.map +1 -1
  168. package/lib/Kubernetes/client.d.ts +10 -10
  169. package/lib/Output.d.ts.map +1 -1
  170. package/lib/Output.js +4 -0
  171. package/lib/Output.js.map +1 -1
  172. package/lib/Plan.d.ts.map +1 -1
  173. package/lib/Plan.js +4 -0
  174. package/lib/Plan.js.map +1 -1
  175. package/lib/Platform.d.ts +2 -2
  176. package/lib/Platform.d.ts.map +1 -1
  177. package/lib/Platform.js.map +1 -1
  178. package/lib/Provider.d.ts.map +1 -1
  179. package/lib/Provider.js +0 -1
  180. package/lib/Provider.js.map +1 -1
  181. package/lib/Stack.d.ts +24 -12
  182. package/lib/Stack.d.ts.map +1 -1
  183. package/lib/Stack.js +47 -10
  184. package/lib/Stack.js.map +1 -1
  185. package/lib/State/HttpStateApi.d.ts +96 -0
  186. package/lib/State/HttpStateApi.d.ts.map +1 -0
  187. package/lib/State/HttpStateApi.js +96 -0
  188. package/lib/State/HttpStateApi.js.map +1 -0
  189. package/lib/State/HttpStateStore.d.ts +10 -0
  190. package/lib/State/HttpStateStore.d.ts.map +1 -0
  191. package/lib/State/HttpStateStore.js +102 -0
  192. package/lib/State/HttpStateStore.js.map +1 -0
  193. package/lib/State/InMemoryState.d.ts +2 -30
  194. package/lib/State/InMemoryState.d.ts.map +1 -1
  195. package/lib/State/InMemoryState.js +23 -18
  196. package/lib/State/InMemoryState.js.map +1 -1
  197. package/lib/State/LocalState.d.ts +4 -2
  198. package/lib/State/LocalState.d.ts.map +1 -1
  199. package/lib/State/LocalState.js +9 -41
  200. package/lib/State/LocalState.js.map +1 -1
  201. package/lib/State/State.d.ts +11 -4
  202. package/lib/State/State.d.ts.map +1 -1
  203. package/lib/State/State.js +1 -1
  204. package/lib/State/State.js.map +1 -1
  205. package/lib/State/StateEncoding.d.ts +31 -0
  206. package/lib/State/StateEncoding.d.ts.map +1 -0
  207. package/lib/State/StateEncoding.js +82 -0
  208. package/lib/State/StateEncoding.js.map +1 -0
  209. package/lib/State/Sync.d.ts +23 -0
  210. package/lib/State/Sync.d.ts.map +1 -0
  211. package/lib/State/Sync.js +49 -0
  212. package/lib/State/Sync.js.map +1 -0
  213. package/lib/State/index.d.ts +4 -0
  214. package/lib/State/index.d.ts.map +1 -1
  215. package/lib/State/index.js +4 -0
  216. package/lib/State/index.js.map +1 -1
  217. package/lib/Test/Bun.d.ts +13 -17
  218. package/lib/Test/Bun.d.ts.map +1 -1
  219. package/lib/Test/Bun.js +17 -36
  220. package/lib/Test/Bun.js.map +1 -1
  221. package/lib/Test/TestState.d.ts +1 -2
  222. package/lib/Test/TestState.d.ts.map +1 -1
  223. package/lib/Test/TestState.js +5 -9
  224. package/lib/Test/TestState.js.map +1 -1
  225. package/lib/Test/Vitest.d.ts +3 -2
  226. package/lib/Test/Vitest.d.ts.map +1 -1
  227. package/lib/Test/Vitest.js +20 -11
  228. package/lib/Test/Vitest.js.map +1 -1
  229. package/lib/Test/index.d.ts +0 -1
  230. package/lib/Test/index.d.ts.map +1 -1
  231. package/lib/Test/index.js +0 -1
  232. package/lib/Test/index.js.map +1 -1
  233. package/lib/Util/FileLogger.d.ts +2 -2
  234. package/lib/Util/FileLogger.d.ts.map +1 -1
  235. package/lib/Util/FileLogger.js +2 -2
  236. package/lib/Util/FileLogger.js.map +1 -1
  237. package/lib/cli/index.d.ts +10 -5
  238. package/lib/cli/index.d.ts.map +1 -1
  239. package/lib/cli/index.js +2 -43045
  240. package/lib/cli/index.js.map +1 -1
  241. package/lib/index.d.ts +2 -1
  242. package/lib/index.d.ts.map +1 -1
  243. package/lib/index.js +2 -1
  244. package/lib/index.js.map +1 -1
  245. package/package.json +30 -15
  246. package/src/AWS/ECS/Task.ts +4 -4
  247. package/src/AWS/Lambda/Function.ts +2 -3
  248. package/src/AWS/SQS/QueueSink.ts +1 -2
  249. package/src/Agent/coding/bash.ts +2 -3
  250. package/src/Agent/coding/glob.ts +1 -2
  251. package/src/Agent/coding/grep.ts +1 -2
  252. package/src/AlchemyContext.ts +27 -0
  253. package/src/Auth/AuthProvider.ts +1 -1
  254. package/src/Auth/index.ts +3 -1
  255. package/src/{Test/TestCli.ts → Cli/LoggingCli.ts} +2 -2
  256. package/src/Cli/index.ts +4 -1
  257. package/src/Cloudflare/ApiToken/AccountApiToken.ts +197 -0
  258. package/src/Cloudflare/ApiToken/Common.ts +148 -0
  259. package/src/Cloudflare/ApiToken/PermissionGroups.ts +1910 -0
  260. package/src/Cloudflare/ApiToken/UserApiToken.ts +168 -0
  261. package/src/Cloudflare/ApiToken/index.ts +4 -0
  262. package/src/Cloudflare/Auth/AuthProvider.ts +2 -2
  263. package/src/Cloudflare/Container/ContainerApplication.ts +8 -2
  264. package/src/Cloudflare/EdgeSession.ts +144 -0
  265. package/src/Cloudflare/Providers.ts +5 -0
  266. package/src/Cloudflare/StateStore/Api.ts +159 -0
  267. package/src/Cloudflare/StateStore/State.ts +318 -0
  268. package/src/Cloudflare/StateStore/Store.ts +290 -0
  269. package/src/Cloudflare/StateStore/Token.ts +68 -0
  270. package/src/Cloudflare/StateStore/index.ts +1 -0
  271. package/src/Cloudflare/Workers/DurableObjectNamespace.ts +1 -6
  272. package/src/Cloudflare/Workers/HttpServer.ts +1 -1
  273. package/src/Cloudflare/Workers/Worker.ts +7 -7
  274. package/src/Cloudflare/index.ts +4 -1
  275. package/src/Deploy.ts +25 -0
  276. package/src/Destroy.ts +25 -13
  277. package/src/GitHub/Providers.ts +6 -0
  278. package/src/GitHub/index.ts +1 -0
  279. package/src/Http.ts +31 -16
  280. package/src/Output.ts +3 -2
  281. package/src/Plan.ts +3 -0
  282. package/src/Platform.ts +8 -2
  283. package/src/Provider.ts +0 -2
  284. package/src/Stack.ts +146 -45
  285. package/src/State/HttpStateApi.ts +155 -0
  286. package/src/State/HttpStateStore.ts +156 -0
  287. package/src/State/InMemoryState.ts +15 -17
  288. package/src/State/LocalState.ts +13 -45
  289. package/src/State/State.ts +13 -4
  290. package/src/State/StateEncoding.ts +83 -0
  291. package/src/State/Sync.ts +89 -0
  292. package/src/State/index.ts +4 -0
  293. package/src/Test/Bun.ts +31 -89
  294. package/src/Test/TestState.ts +6 -8
  295. package/src/Test/Vitest.ts +32 -19
  296. package/src/Test/index.ts +0 -1
  297. package/src/Util/FileLogger.ts +2 -2
  298. package/src/index.ts +2 -1
  299. package/lib/Config.d.ts +0 -20
  300. package/lib/Config.d.ts.map +0 -1
  301. package/lib/Config.js +0 -22
  302. package/lib/Config.js.map +0 -1
  303. package/lib/Observability.d.ts +0 -2
  304. package/lib/Observability.d.ts.map +0 -1
  305. package/lib/Observability.js +0 -1
  306. package/lib/Observability.js.map +0 -1
  307. package/lib/Test/TestCli.d.ts +0 -4
  308. package/lib/Test/TestCli.d.ts.map +0 -1
  309. package/lib/Test/TestCli.js.map +0 -1
  310. package/src/Config.ts +0 -31
  311. package/src/Observability.ts +0 -0
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * as AdoptPolicy from "./AdoptPolicy.ts";
2
+ export * from "./AlchemyContext.ts";
2
3
  export * from "./Apply.ts";
3
4
  export { Service as BindingService, Policy, type ServiceLike as BindingServiceLike, type ServiceShape as BindingServiceShape, type PolicyLike, type PolicyShape, } from "./Binding.ts";
4
- export * from "./Config.ts";
5
5
  export * from "./Destroy.ts";
6
6
  export * from "./Diff.ts";
7
7
  export * from "./Input.ts";
@@ -20,6 +20,7 @@ export * as Server from "./Server/index.ts";
20
20
  export * as Serverless from "./Serverless/index.ts";
21
21
  export { Stack } from "./Stack.ts";
22
22
  export * from "./Stage.ts";
23
+ export { inMemoryState, localState } from "./State/index.ts";
23
24
  export * from "./Trait.ts";
24
25
  export * as Construct from "./Construct.ts";
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,MAAM,EACN,KAAK,WAAW,IAAI,kBAAkB,EACtC,KAAK,YAAY,IAAI,mBAAmB,EACxC,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7D,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,cAAc,eAAe,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAE3B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,MAAM,EACN,KAAK,WAAW,IAAI,kBAAkB,EACtC,KAAK,YAAY,IAAI,mBAAmB,EACxC,KAAK,UAAU,EACf,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7D,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,cAAc,eAAe,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC7D,cAAc,YAAY,CAAC;AAE3B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export * as AdoptPolicy from "./AdoptPolicy.js";
2
+ export * from "./AlchemyContext.js";
2
3
  export * from "./Apply.js";
3
4
  export { Service as BindingService, Policy, } from "./Binding.js";
4
- export * from "./Config.js";
5
5
  export * from "./Destroy.js";
6
6
  export * from "./Diff.js";
7
7
  export * from "./Input.js";
@@ -19,6 +19,7 @@ export * as Server from "./Server/index.js";
19
19
  export * as Serverless from "./Serverless/index.js";
20
20
  export { Stack } from "./Stack.js";
21
21
  export * from "./Stage.js";
22
+ export { inMemoryState, localState } from "./State/index.js";
22
23
  export * from "./Trait.js";
23
24
  export * as Construct from "./Construct.js";
24
25
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,MAAM,GAKP,MAAM,cAAc,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7D,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,cAAc,eAAe,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAE3B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,OAAO,IAAI,cAAc,EACzB,MAAM,GAKP,MAAM,cAAc,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,mBAAmB,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7D,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,cAAc,eAAe,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC7D,cAAc,YAAY,CAAC;AAE3B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alchemy",
3
- "version": "2.0.0-beta.13",
3
+ "version": "2.0.0-beta.15",
4
4
  "homepage": "https://alchemy.run",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Sam Goodwin <sam@alchemy.run>",
@@ -9,6 +9,9 @@
9
9
  "url": "git+https://github.com/alchemy-run/alchemy-effect.git",
10
10
  "directory": "package/alchemy"
11
11
  },
12
+ "bin": {
13
+ "alchemy": "./bin/cli.js"
14
+ },
12
15
  "files": [
13
16
  "bin",
14
17
  "lib",
@@ -43,6 +46,12 @@
43
46
  "worker": "./src/Agent/index.ts",
44
47
  "import": "./lib/Agent/index.js"
45
48
  },
49
+ "./Auth": {
50
+ "types": "./src/Auth/index.ts",
51
+ "bun": "./src/Auth/index.ts",
52
+ "worker": "./src/Auth/index.ts",
53
+ "import": "./lib/Auth/index.js"
54
+ },
46
55
  "./AWS": {
47
56
  "types": "./src/AWS/index.ts",
48
57
  "bun": "./src/AWS/index.ts",
@@ -187,6 +196,12 @@
187
196
  "worker": "./src/State/index.ts",
188
197
  "import": "./lib/State/index.js"
189
198
  },
199
+ "./State/*": {
200
+ "types": "./src/State/*.ts",
201
+ "bun": "./src/State/*.ts",
202
+ "worker": "./src/State/*.ts",
203
+ "import": "./lib/State/*.js"
204
+ },
190
205
  "./Test/Bun": {
191
206
  "types": "./src/Test/Bun.ts",
192
207
  "bun": "./src/Test/Bun.ts",
@@ -199,26 +214,28 @@
199
214
  "worker": "./src/Util/index.ts",
200
215
  "import": "./lib/Util/index.js"
201
216
  },
217
+ "./Util/Clank": {
218
+ "types": "./src/Util/Clank.ts",
219
+ "bun": "./src/Util/Clank.ts",
220
+ "worker": "./src/Util/Clank.ts",
221
+ "import": "./lib/Util/Clank.js"
222
+ },
202
223
  "./bin/alchemy.js": "./bin/alchemy.js"
203
224
  },
204
225
  "publishConfig": {
205
226
  "access": "public"
206
227
  },
207
- "optionalDependencies": {
208
- "@alchemy.run/cli-posix": "2.0.0-beta.13",
209
- "@alchemy.run/cli-win32": "2.0.0-beta.13"
210
- },
211
228
  "dependencies": {
212
229
  "@ai-sdk/anthropic": "^3.0.31",
213
230
  "@ai-sdk/openai": "^3.0.23",
214
231
  "@ai-sdk/provider": "^3.0.8",
215
232
  "@aws-sdk/credential-providers": "^3.0.0",
216
233
  "@clack/prompts": "^0.11.0",
217
- "@distilled.cloud/aws": "^0.10.2",
218
- "@distilled.cloud/cloudflare": "^0.10.2",
234
+ "@distilled.cloud/aws": "^0.12.4",
235
+ "@distilled.cloud/cloudflare": "^0.12.4",
219
236
  "@distilled.cloud/cloudflare-rolldown-plugin": "0.3.0",
220
237
  "@distilled.cloud/cloudflare-vite-plugin": "0.2.0",
221
- "@distilled.cloud/core": "^0.10.2",
238
+ "@distilled.cloud/core": "^0.12.4",
222
239
  "@effect/vitest": "4.0.0-beta.48",
223
240
  "@libsql/client": "^0.17.0",
224
241
  "@octokit/rest": "^22.0.1",
@@ -233,11 +250,11 @@
233
250
  "cloudflare": "^5.2.0",
234
251
  "fast-glob": "^3.3.2",
235
252
  "fast-xml-parser": "^5.3.4",
253
+ "foreground-child": "^4.0.3",
236
254
  "ignore": "^7.0.5",
237
255
  "jszip": "^3.10.1",
238
256
  "libsodium-wrappers": "^0.8.3",
239
257
  "rolldown": "1.0.0-rc.13",
240
- "solid-js": "latest",
241
258
  "sonda": "^0.11.1",
242
259
  "web-tree-sitter": "0.25.10",
243
260
  "workerd": "1.20260417.1",
@@ -259,15 +276,16 @@
259
276
  "pathe": "^2.0.3",
260
277
  "react": "^19.2.0",
261
278
  "react-devtools-core": "^7.0.1",
279
+ "solid-js": "latest",
262
280
  "tsconfig-paths": "^4.2.0",
263
281
  "tsdown": "^0.15.4",
264
282
  "tsx": "^4.20.6",
265
283
  "typescript": "^5.9.3"
266
284
  },
267
285
  "peerDependencies": {
268
- "@effect/platform-bun": "*",
269
- "@effect/platform-node": "*",
270
- "effect": "*",
286
+ "@effect/platform-bun": "4.0.0-beta.48",
287
+ "@effect/platform-node": "4.0.0-beta.48",
288
+ "effect": "4.0.0-beta.48",
271
289
  "vite": "^8.0.7"
272
290
  },
273
291
  "peerDependenciesMeta": {
@@ -277,9 +295,6 @@
277
295
  "@effect/platform-bun": {
278
296
  "optional": true
279
297
  },
280
- "effect": {
281
- "optional": true
282
- },
283
298
  "vite": {
284
299
  "optional": true
285
300
  }
@@ -8,6 +8,7 @@ import * as Context from "effect/Context";
8
8
  import * as Effect from "effect/Effect";
9
9
  import * as FileSystem from "effect/FileSystem";
10
10
  import type * as rolldown from "rolldown";
11
+ import { AlchemyContext } from "../../AlchemyContext.ts";
11
12
  import * as Bundle from "../../Bundle/Bundle.ts";
12
13
  import {
13
14
  dockerBuild,
@@ -19,20 +20,19 @@ import {
19
20
  findCwdForBundle,
20
21
  getStableContextDir,
21
22
  } from "../../Bundle/TempRoot.ts";
22
- import { DotAlchemy } from "../../Config.ts";
23
23
  import { isResolved } from "../../Diff.ts";
24
24
  import * as Output from "../../Output.ts";
25
25
  import { createPhysicalName } from "../../PhysicalName.ts";
26
26
  import { Platform, type Main, type PlatformProps } from "../../Platform.ts";
27
27
  import * as Provider from "../../Provider.ts";
28
28
  import { Resource, type ResourceBinding } from "../../Resource.ts";
29
- import type { Providers } from "../Providers.ts";
30
29
  import type { ProcessContext, ServerHost } from "../../Server/Process.ts";
31
30
  import { Stack } from "../../Stack.ts";
32
31
  import { createInternalTags, createTagsList, hasTags } from "../../Tags.ts";
33
- import { AWSEnvironment } from "../Environment.ts";
34
32
  import type { Credentials } from "../Credentials.ts";
33
+ import { AWSEnvironment } from "../Environment.ts";
35
34
  import type { PolicyStatement } from "../IAM/Policy.ts";
35
+ import type { Providers } from "../Providers.ts";
36
36
 
37
37
  export const isTask = (value: any): value is Task => {
38
38
  return (
@@ -225,7 +225,7 @@ export const TaskProvider = () =>
225
225
  const stack = yield* Stack;
226
226
  const { accountId } = yield* AWSEnvironment;
227
227
  const region = yield* Region;
228
- const dotAlchemy = yield* DotAlchemy;
228
+ const { dotAlchemy } = yield* AlchemyContext;
229
229
  const fs = yield* FileSystem.FileSystem;
230
230
  const virtualEntryPlugin = yield* Bundle.virtualEntryPlugin;
231
231
 
@@ -23,16 +23,16 @@ import { Platform, type Main, type PlatformProps } from "../../Platform.ts";
23
23
  import type { LogLine, LogsInput } from "../../Provider.ts";
24
24
  import * as Provider from "../../Provider.ts";
25
25
  import { Resource, type ResourceBinding } from "../../Resource.ts";
26
- import type { Providers } from "../Providers.ts";
27
26
  import * as Serverless from "../../Serverless/index.ts";
28
27
  import { Stack } from "../../Stack.ts";
29
28
  import { createInternalTags, createTagsList, hasTags } from "../../Tags.ts";
30
29
  import { sha256 } from "../../Util/sha256.ts";
31
30
  import { zipCode } from "../../Util/zip.ts";
32
- import { AWSEnvironment } from "../Environment.ts";
33
31
  import { Assets } from "../Assets.ts";
32
+ import { AWSEnvironment } from "../Environment.ts";
34
33
  import * as IAM from "../IAM/index.ts";
35
34
  import type { PolicyStatement } from "../IAM/Policy.ts";
35
+ import type { Providers } from "../Providers.ts";
36
36
  import { makeFunctionHttpHandler } from "./HttpServer.ts";
37
37
 
38
38
  export const FunctionTypeId = "AWS.Lambda.Function" as const;
@@ -403,7 +403,6 @@ export const Function: Platform<
403
403
  }),
404
404
  (handlers) =>
405
405
  async (event: any, context: lambda.Context): Promise<any> => {
406
- console.log({ event, handlers });
407
406
  for (const handler of handlers) {
408
407
  const eff = handler(event);
409
408
  if (Effect.isEffect(eff)) {
@@ -1,4 +1,3 @@
1
- import * as Console from "effect/Console";
2
1
  import * as Effect from "effect/Effect";
3
2
  import * as Layer from "effect/Layer";
4
3
  import * as Sink from "effect/Sink";
@@ -30,7 +29,7 @@ export const QueueSinkLive = Layer.effect(
30
29
  Id: `${i}`,
31
30
  MessageBody: message,
32
31
  })),
33
- }).pipe(Effect.tapError(Console.log), Effect.orDie, Effect.asVoid),
32
+ }).pipe(Effect.orDie, Effect.asVoid),
34
33
  );
35
34
  });
36
35
  }),
@@ -2,7 +2,6 @@ import * as Effect from "effect/Effect";
2
2
  import * as Option from "effect/Option";
3
3
  import * as S from "effect/Schema";
4
4
  import { ChildProcess } from "effect/unstable/process";
5
- import { cwd } from "../../Config.ts";
6
5
  import { AspectConfig } from "../Aspect.ts";
7
6
  import { Tool } from "../tool/tool.ts";
8
7
  import { CommandValidator } from "../util/command-validator.ts";
@@ -18,7 +17,7 @@ export class timeout extends Tool.input(
18
17
  export class workdir extends Tool.input(
19
18
  "workdir",
20
19
  S.optional(S.String),
21
- )`The working directory to run the command in. Defaults to ${cwd}. Use this instead of 'cd' commands.` {}
20
+ )`The working directory to run the command in. Defaults to cwd. Use this instead of 'cd' commands.` {}
22
21
 
23
22
  export class description extends Tool.input(
24
23
  "description",
@@ -51,7 +50,7 @@ export class bash extends Tool("bash", {
51
50
  Returns the ${exitCode} and ${stdout} containing both stdout and stderr.
52
51
  If the command is invalid, an error message will be returned as a ${S.String}.
53
52
 
54
- All commands run in ${cwd} by default. Use the ${workdir} parameter if you need to run a command in a different directory. AVOID using \`cd <directory> && <command>\` patterns - use \`workdir\` instead.
53
+ All commands run in cwd by default. Use the ${workdir} parameter if you need to run a command in a different directory. AVOID using \`cd <directory> && <command>\` patterns - use \`workdir\` instead.
55
54
 
56
55
  IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. DO NOT use it for file operations (reading, writing, editing, searching, finding files) - use the specialized tools for this instead.
57
56
 
@@ -3,7 +3,6 @@ import * as FileSystem from "effect/FileSystem";
3
3
  import * as Option from "effect/Option";
4
4
  import * as Path from "effect/Path";
5
5
  import * as S from "effect/Schema";
6
- import { cwd } from "../../Config.ts";
7
6
  import { AspectConfig } from "../Aspect.ts";
8
7
  import { Tool } from "../tool/tool.ts";
9
8
  import * as Ripgrep from "../util/ripgrep.ts";
@@ -21,7 +20,7 @@ Examples:
21
20
  export class path extends Tool.input(
22
21
  "path",
23
22
  S.optional(S.String),
24
- )`The directory to search in. Defaults to ${cwd} if not specified.` {}
23
+ )`The directory to search in. Defaults to cwd if not specified.` {}
25
24
 
26
25
  export class files extends Tool.output(
27
26
  "files",
@@ -3,7 +3,6 @@ import * as FileSystem from "effect/FileSystem";
3
3
  import * as Option from "effect/Option";
4
4
  import * as S from "effect/Schema";
5
5
  import { ChildProcess } from "effect/unstable/process";
6
- import { cwd } from "../../Config.ts";
7
6
  import { AspectConfig } from "../Aspect.ts";
8
7
  import { Tool } from "../tool/tool.ts";
9
8
  import { exec } from "../util/exec.ts";
@@ -18,7 +17,7 @@ Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+", etc.)` {}
18
17
  class path extends Tool.input(
19
18
  "path",
20
19
  S.optional(S.String),
21
- )`The directory to search in. Defaults to ${cwd} if not specified.` {}
20
+ )`The directory to search in. Defaults to cwd if not specified.` {}
22
21
 
23
22
  class include extends Tool.input(
24
23
  "include",
@@ -0,0 +1,27 @@
1
+ import * as EffectContext from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as FileSystem from "effect/FileSystem";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Path from "effect/Path";
6
+
7
+ export class AlchemyContext extends EffectContext.Service<
8
+ AlchemyContext,
9
+ {
10
+ dotAlchemy: string;
11
+ updateStateStore: boolean;
12
+ }
13
+ >()("alchemy/Context") {}
14
+
15
+ export const AlchemyContextLive = Layer.effect(
16
+ AlchemyContext,
17
+ Effect.gen(function* () {
18
+ const fs = yield* FileSystem.FileSystem;
19
+ const path = yield* Path.Path;
20
+ const dir = path.join(process.cwd(), ".alchemy");
21
+ yield* fs.makeDirectory(dir, { recursive: true });
22
+ return {
23
+ dotAlchemy: dir,
24
+ updateStateStore: false,
25
+ };
26
+ }),
27
+ );
@@ -206,7 +206,7 @@ export const getAuthProvider = <
206
206
  registry[name] == null
207
207
  ? Effect.fail(
208
208
  new AuthError({
209
- message: `AuthProvider '${name}' is not registered. Make sure its layer has been built.`,
209
+ message: `AuthProvider '${name}' is not registered. Make sure its layer has been provided.`,
210
210
  }),
211
211
  )
212
212
  : Effect.succeed(registry[name] as AuthProvider<Config, Credentials>),
package/src/Auth/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from "./AuthProvider.ts";
2
- export type * from "./Profile.ts";
2
+ export * from "./Credentials.ts";
3
+ export * from "./Env.ts";
4
+ export * from "./Profile.ts";
@@ -1,8 +1,8 @@
1
1
  import * as Effect from "effect/Effect";
2
2
  import * as Layer from "effect/Layer";
3
- import { Cli } from "../Cli/Cli.ts";
3
+ import { Cli } from "./Cli.ts";
4
4
 
5
- export const TestCli = Layer.succeed(
5
+ export const LoggingCli = Layer.succeed(
6
6
  Cli,
7
7
  Cli.of({
8
8
  approvePlan: () => Effect.succeed(true),
package/src/Cli/index.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from "./Cli.ts";
2
- export * from "./InkCLI.tsx";
2
+ // Note: do NOT re-export InkCLI here. The Ink-based renderer pulls in
3
+ // `react`/`ink`, which we do not want consumers of `alchemy/Cli` to
4
+ // transitively depend on. Import `alchemy/Cli/InkCLI` directly when needed
5
+ // (currently only from `bin/alchemy.ts`, which is bundled).
@@ -0,0 +1,197 @@
1
+ import * as accounts from "@distilled.cloud/cloudflare/accounts";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Redacted from "effect/Redacted";
4
+ import { isResolved } from "../../Diff.ts";
5
+ import { createPhysicalName } from "../../PhysicalName.ts";
6
+ import * as Provider from "../../Provider.ts";
7
+ import { Resource } from "../../Resource.ts";
8
+ import { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
9
+ import type { Providers } from "../Providers.ts";
10
+ import {
11
+ buildConditionPayload,
12
+ conditionFingerprint,
13
+ policyFingerprint,
14
+ resolvePolicies,
15
+ type BaseApiTokenProps,
16
+ } from "./Common.ts";
17
+
18
+ export type AccountApiTokenProps = BaseApiTokenProps;
19
+
20
+ export type AccountApiToken = Resource<
21
+ "Cloudflare.AccountApiToken",
22
+ AccountApiTokenProps,
23
+ {
24
+ tokenId: string;
25
+ name: string;
26
+ status: "active" | "disabled" | "expired";
27
+ /**
28
+ * The plaintext token value. Cloudflare returns this only once, on
29
+ * creation, so we persist it here for downstream consumers (e.g. a
30
+ * GitHub Actions secret).
31
+ */
32
+ value: Redacted.Redacted<string>;
33
+ accountId: string;
34
+ },
35
+ never,
36
+ Providers
37
+ >;
38
+
39
+ /**
40
+ * A Cloudflare account-owned API token (`POST /accounts/{account_id}/tokens`).
41
+ *
42
+ * Account-owned tokens are managed at the account level and persist
43
+ * independently of any single user. Use these for CI tokens, third-party
44
+ * integrations, or anywhere the token should outlive an individual user's
45
+ * session.
46
+ *
47
+ * Creating account-owned tokens requires the caller to have the
48
+ * `API Tokens > Write` account permission.
49
+ *
50
+ * @section Creating a Token
51
+ * @example A token for managing Workers and KV from CI
52
+ * ```typescript
53
+ * const token = yield* Cloudflare.AccountApiToken("ci-token", {
54
+ * name: "my-ci-token",
55
+ * policies: [
56
+ * {
57
+ * effect: "allow",
58
+ * permissionGroups: [
59
+ * "Workers Scripts Write",
60
+ * "Workers KV Storage Write",
61
+ * ],
62
+ * resources: { "com.cloudflare.api.account": "*" },
63
+ * },
64
+ * ],
65
+ * });
66
+ *
67
+ * yield* GitHub.Secret("cf-api-token", {
68
+ * owner: "me",
69
+ * repository: "my-repo",
70
+ * name: "CLOUDFLARE_API_TOKEN",
71
+ * value: token.value,
72
+ * });
73
+ * ```
74
+ */
75
+ export const AccountApiToken = Resource<AccountApiToken>(
76
+ "Cloudflare.AccountApiToken",
77
+ );
78
+
79
+ type AccountApiTokenAttributes = AccountApiToken["Attributes"];
80
+
81
+ const resolveName = (id: string, name: string | undefined) =>
82
+ Effect.gen(function* () {
83
+ return name ?? (yield* createPhysicalName({ id }));
84
+ });
85
+
86
+ export const AccountApiTokenProvider = () =>
87
+ Provider.effect(
88
+ AccountApiToken,
89
+ Effect.gen(function* () {
90
+ const { accountId } = yield* CloudflareEnvironment;
91
+ const createToken = yield* accounts.createToken;
92
+ const updateToken = yield* accounts.updateToken;
93
+ const deleteToken = yield* accounts.deleteToken;
94
+ const getToken = yield* accounts.getToken;
95
+
96
+ const buildAttributes = (
97
+ tokenData: {
98
+ id?: string | null;
99
+ name?: string | null;
100
+ status?: "active" | "disabled" | "expired" | null;
101
+ },
102
+ value: Redacted.Redacted<string>,
103
+ ): AccountApiTokenAttributes => ({
104
+ tokenId: tokenData.id ?? "",
105
+ name: tokenData.name ?? "",
106
+ status: tokenData.status ?? "active",
107
+ value,
108
+ accountId,
109
+ });
110
+
111
+ return {
112
+ stables: ["tokenId", "accountId"],
113
+ diff: Effect.fn(function* ({ id, olds, news, output }) {
114
+ if (!isResolved(news)) return undefined;
115
+ if ((output?.accountId ?? accountId) !== accountId) {
116
+ return { action: "replace" } as const;
117
+ }
118
+ const oldName = output?.name ?? (yield* resolveName(id, olds?.name));
119
+ const newName = yield* resolveName(id, news.name);
120
+ const oldPolicyFp = policyFingerprint(
121
+ resolvePolicies(olds?.policies ?? [], accountId),
122
+ );
123
+ const newPolicyFp = policyFingerprint(
124
+ resolvePolicies(news.policies, accountId),
125
+ );
126
+ const oldCondFp = conditionFingerprint(olds?.condition);
127
+ const newCondFp = conditionFingerprint(news.condition);
128
+ if (
129
+ oldName !== newName ||
130
+ oldPolicyFp !== newPolicyFp ||
131
+ oldCondFp !== newCondFp ||
132
+ (olds?.expiresOn ?? undefined) !== (news.expiresOn ?? undefined) ||
133
+ (olds?.notBefore ?? undefined) !== (news.notBefore ?? undefined)
134
+ ) {
135
+ return { action: "update" } as const;
136
+ }
137
+ }),
138
+ create: Effect.fn(function* ({ id, news }) {
139
+ const name = yield* resolveName(id, news.name);
140
+ const policies = resolvePolicies(news.policies, accountId);
141
+ const result = yield* createToken({
142
+ accountId,
143
+ name,
144
+ policies,
145
+ condition: buildConditionPayload(news.condition),
146
+ expiresOn: news.expiresOn,
147
+ notBefore: news.notBefore,
148
+ });
149
+ if (!result.value) {
150
+ return yield* Effect.die(
151
+ `Cloudflare did not return a value for token "${name}".`,
152
+ );
153
+ }
154
+ return buildAttributes(result, Redacted.make(result.value));
155
+ }),
156
+ update: Effect.fn(function* ({ id, news, output }) {
157
+ const name = yield* resolveName(id, news.name);
158
+ const policies = resolvePolicies(news.policies, accountId);
159
+ const result = yield* updateToken({
160
+ accountId,
161
+ tokenId: output.tokenId,
162
+ name,
163
+ policies,
164
+ condition: buildConditionPayload(news.condition),
165
+ expiresOn: news.expiresOn,
166
+ notBefore: news.notBefore,
167
+ });
168
+ // Cloudflare doesn't return the value on update; preserve the
169
+ // value captured at creation.
170
+ return buildAttributes(result, output.value);
171
+ }),
172
+ delete: Effect.fn(function* ({ output }) {
173
+ yield* deleteToken({
174
+ accountId: output.accountId,
175
+ tokenId: output.tokenId,
176
+ }).pipe(
177
+ // Already gone — Cloudflare may report this as either an
178
+ // `InvalidRoute` (token-id no longer routable) or a generic
179
+ // `TokenNotFound`. Either is fine; we just want the resource gone.
180
+ Effect.catchTag("InvalidRoute", () => Effect.void),
181
+ Effect.catchTag("TokenNotFound", () => Effect.void),
182
+ );
183
+ }),
184
+ read: Effect.fn(function* ({ output }) {
185
+ if (!output?.tokenId) return undefined;
186
+ return yield* getToken({
187
+ accountId: output.accountId,
188
+ tokenId: output.tokenId,
189
+ }).pipe(
190
+ Effect.map((token) => buildAttributes(token, output.value)),
191
+ Effect.catchTag("InvalidRoute", () => Effect.succeed(undefined)),
192
+ Effect.catchTag("TokenNotFound", () => Effect.succeed(undefined)),
193
+ );
194
+ }),
195
+ };
196
+ }),
197
+ );