@aws-blocks/core 0.1.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 (394) hide show
  1. package/LICENSE +174 -0
  2. package/dist/api.d.ts +147 -0
  3. package/dist/api.d.ts.map +1 -0
  4. package/dist/api.js +10 -0
  5. package/dist/api.test.d.ts +2 -0
  6. package/dist/api.test.d.ts.map +1 -0
  7. package/dist/api.test.js +19 -0
  8. package/dist/bb-utils.d.ts +11 -0
  9. package/dist/bb-utils.d.ts.map +1 -0
  10. package/dist/bb-utils.js +12 -0
  11. package/dist/builtin-routes.d.ts +6 -0
  12. package/dist/builtin-routes.d.ts.map +1 -0
  13. package/dist/builtin-routes.js +57 -0
  14. package/dist/cdk/__fixtures__/factory-backend.d.ts +3 -0
  15. package/dist/cdk/__fixtures__/factory-backend.d.ts.map +1 -0
  16. package/dist/cdk/__fixtures__/factory-backend.js +6 -0
  17. package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts +2 -0
  18. package/dist/cdk/__fixtures__/fullid-construct-backend.d.ts.map +1 -0
  19. package/dist/cdk/__fixtures__/fullid-construct-backend.js +37 -0
  20. package/dist/cdk/__fixtures__/handler.d.ts +5 -0
  21. package/dist/cdk/__fixtures__/handler.d.ts.map +1 -0
  22. package/dist/cdk/__fixtures__/handler.js +3 -0
  23. package/dist/cdk/__fixtures__/side-effect-backend.d.ts +2 -0
  24. package/dist/cdk/__fixtures__/side-effect-backend.d.ts.map +1 -0
  25. package/dist/cdk/__fixtures__/side-effect-backend.js +5 -0
  26. package/dist/cdk/blocks-backend.d.ts +68 -0
  27. package/dist/cdk/blocks-backend.d.ts.map +1 -0
  28. package/dist/cdk/blocks-backend.js +214 -0
  29. package/dist/cdk/blocks-backend.test.d.ts +2 -0
  30. package/dist/cdk/blocks-backend.test.d.ts.map +1 -0
  31. package/dist/cdk/blocks-backend.test.js +151 -0
  32. package/dist/cdk/blocks-stack.test.d.ts +2 -0
  33. package/dist/cdk/blocks-stack.test.d.ts.map +1 -0
  34. package/dist/cdk/blocks-stack.test.js +78 -0
  35. package/dist/cdk/config-registry.d.ts +26 -0
  36. package/dist/cdk/config-registry.d.ts.map +1 -0
  37. package/dist/cdk/config-registry.js +80 -0
  38. package/dist/cdk/index.d.ts +35 -0
  39. package/dist/cdk/index.d.ts.map +1 -0
  40. package/dist/cdk/index.js +90 -0
  41. package/dist/cdk/mixins.d.ts +28 -0
  42. package/dist/cdk/mixins.d.ts.map +1 -0
  43. package/dist/cdk/mixins.js +37 -0
  44. package/dist/cdk/mixins.test.d.ts +2 -0
  45. package/dist/cdk/mixins.test.d.ts.map +1 -0
  46. package/dist/cdk/mixins.test.js +108 -0
  47. package/dist/cdk/node-version.d.ts +14 -0
  48. package/dist/cdk/node-version.d.ts.map +1 -0
  49. package/dist/cdk/node-version.js +15 -0
  50. package/dist/cdk/stack-metadata.d.ts +12 -0
  51. package/dist/cdk/stack-metadata.d.ts.map +1 -0
  52. package/dist/cdk/stack-metadata.js +22 -0
  53. package/dist/cdk/stack-metadata.test.d.ts +2 -0
  54. package/dist/cdk/stack-metadata.test.d.ts.map +1 -0
  55. package/dist/cdk/stack-metadata.test.js +56 -0
  56. package/dist/cdk/synth-guard.d.ts +14 -0
  57. package/dist/cdk/synth-guard.d.ts.map +1 -0
  58. package/dist/cdk/synth-guard.js +20 -0
  59. package/dist/cdk/synth-guard.test.d.ts +2 -0
  60. package/dist/cdk/synth-guard.test.d.ts.map +1 -0
  61. package/dist/cdk/synth-guard.test.js +15 -0
  62. package/dist/client/index.d.ts +97 -0
  63. package/dist/client/index.d.ts.map +1 -0
  64. package/dist/client/index.js +238 -0
  65. package/dist/client/index.test.d.ts +2 -0
  66. package/dist/client/index.test.d.ts.map +1 -0
  67. package/dist/client/index.test.js +113 -0
  68. package/dist/common/config.d.ts +45 -0
  69. package/dist/common/config.d.ts.map +1 -0
  70. package/dist/common/config.js +154 -0
  71. package/dist/common/config.test.d.ts +2 -0
  72. package/dist/common/config.test.d.ts.map +1 -0
  73. package/dist/common/config.test.js +173 -0
  74. package/dist/common/constants.d.ts +11 -0
  75. package/dist/common/constants.d.ts.map +1 -0
  76. package/dist/common/constants.js +12 -0
  77. package/dist/common/crypto.d.ts +6 -0
  78. package/dist/common/crypto.d.ts.map +1 -0
  79. package/dist/common/crypto.js +14 -0
  80. package/dist/common/index.d.ts +220 -0
  81. package/dist/common/index.d.ts.map +1 -0
  82. package/dist/common/index.js +180 -0
  83. package/dist/common/index.test.d.ts +2 -0
  84. package/dist/common/index.test.d.ts.map +1 -0
  85. package/dist/common/index.test.js +195 -0
  86. package/dist/common/mock-data.d.ts +40 -0
  87. package/dist/common/mock-data.d.ts.map +1 -0
  88. package/dist/common/mock-data.js +39 -0
  89. package/dist/common/official-bb-names.generated.d.ts +7 -0
  90. package/dist/common/official-bb-names.generated.d.ts.map +1 -0
  91. package/dist/common/official-bb-names.generated.js +28 -0
  92. package/dist/common/sdk-registry.d.ts +136 -0
  93. package/dist/common/sdk-registry.d.ts.map +1 -0
  94. package/dist/common/sdk-registry.js +125 -0
  95. package/dist/constants.d.ts +27 -0
  96. package/dist/constants.d.ts.map +1 -0
  97. package/dist/constants.js +28 -0
  98. package/dist/cors.d.ts +39 -0
  99. package/dist/cors.d.ts.map +1 -0
  100. package/dist/cors.js +85 -0
  101. package/dist/cors.test.d.ts +2 -0
  102. package/dist/cors.test.d.ts.map +1 -0
  103. package/dist/cors.test.js +241 -0
  104. package/dist/db-naming.d.ts +21 -0
  105. package/dist/db-naming.d.ts.map +1 -0
  106. package/dist/db-naming.js +38 -0
  107. package/dist/db-naming.test.d.ts +2 -0
  108. package/dist/db-naming.test.d.ts.map +1 -0
  109. package/dist/db-naming.test.js +29 -0
  110. package/dist/errors.d.ts +67 -0
  111. package/dist/errors.d.ts.map +1 -0
  112. package/dist/errors.js +69 -0
  113. package/dist/hosting.d.ts +258 -0
  114. package/dist/hosting.d.ts.map +1 -0
  115. package/dist/hosting.js +340 -0
  116. package/dist/hosting.test.d.ts +2 -0
  117. package/dist/hosting.test.d.ts.map +1 -0
  118. package/dist/hosting.test.js +1077 -0
  119. package/dist/index.cdk.d.ts +13 -0
  120. package/dist/index.cdk.d.ts.map +1 -0
  121. package/dist/index.cdk.js +13 -0
  122. package/dist/index.d.ts +9 -0
  123. package/dist/index.d.ts.map +1 -0
  124. package/dist/index.js +10 -0
  125. package/dist/lambda-handler.d.ts +131 -0
  126. package/dist/lambda-handler.d.ts.map +1 -0
  127. package/dist/lambda-handler.js +610 -0
  128. package/dist/lambda-handler.test.d.ts +2 -0
  129. package/dist/lambda-handler.test.d.ts.map +1 -0
  130. package/dist/lambda-handler.test.js +835 -0
  131. package/dist/pipeline/index.d.ts +4 -0
  132. package/dist/pipeline/index.d.ts.map +1 -0
  133. package/dist/pipeline/index.js +3 -0
  134. package/dist/pipeline/pipeline-construct.d.ts +130 -0
  135. package/dist/pipeline/pipeline-construct.d.ts.map +1 -0
  136. package/dist/pipeline/pipeline-construct.js +484 -0
  137. package/dist/pipeline/pipeline.test.d.ts +2 -0
  138. package/dist/pipeline/pipeline.test.d.ts.map +1 -0
  139. package/dist/pipeline/pipeline.test.js +1231 -0
  140. package/dist/pipeline/types.d.ts +351 -0
  141. package/dist/pipeline/types.d.ts.map +1 -0
  142. package/dist/pipeline/types.js +3 -0
  143. package/dist/raw-route.cdk.d.ts +47 -0
  144. package/dist/raw-route.cdk.d.ts.map +1 -0
  145. package/dist/raw-route.cdk.js +51 -0
  146. package/dist/raw-route.d.ts +119 -0
  147. package/dist/raw-route.d.ts.map +1 -0
  148. package/dist/raw-route.js +239 -0
  149. package/dist/raw-route.mock.d.ts +47 -0
  150. package/dist/raw-route.mock.d.ts.map +1 -0
  151. package/dist/raw-route.mock.js +51 -0
  152. package/dist/raw-route.test.d.ts +2 -0
  153. package/dist/raw-route.test.d.ts.map +1 -0
  154. package/dist/raw-route.test.js +597 -0
  155. package/dist/redact.d.ts +51 -0
  156. package/dist/redact.d.ts.map +1 -0
  157. package/dist/redact.js +134 -0
  158. package/dist/redact.test.d.ts +2 -0
  159. package/dist/redact.test.d.ts.map +1 -0
  160. package/dist/redact.test.js +199 -0
  161. package/dist/rpc.d.ts +54 -0
  162. package/dist/rpc.d.ts.map +1 -0
  163. package/dist/rpc.js +127 -0
  164. package/dist/rpc.test.d.ts +2 -0
  165. package/dist/rpc.test.d.ts.map +1 -0
  166. package/dist/rpc.test.js +60 -0
  167. package/dist/scripts/cdk-telemetry-env.d.ts +13 -0
  168. package/dist/scripts/cdk-telemetry-env.d.ts.map +1 -0
  169. package/dist/scripts/cdk-telemetry-env.js +21 -0
  170. package/dist/scripts/cdk-telemetry-env.test.d.ts +2 -0
  171. package/dist/scripts/cdk-telemetry-env.test.d.ts.map +1 -0
  172. package/dist/scripts/cdk-telemetry-env.test.js +56 -0
  173. package/dist/scripts/cleanup.d.ts +3 -0
  174. package/dist/scripts/cleanup.d.ts.map +1 -0
  175. package/dist/scripts/cleanup.js +35 -0
  176. package/dist/scripts/console.d.ts +6 -0
  177. package/dist/scripts/console.d.ts.map +1 -0
  178. package/dist/scripts/console.js +25 -0
  179. package/dist/scripts/deploy.d.ts +6 -0
  180. package/dist/scripts/deploy.d.ts.map +1 -0
  181. package/dist/scripts/deploy.js +82 -0
  182. package/dist/scripts/destroy.d.ts +6 -0
  183. package/dist/scripts/destroy.d.ts.map +1 -0
  184. package/dist/scripts/destroy.js +30 -0
  185. package/dist/scripts/dev-server-cors.test.d.ts +2 -0
  186. package/dist/scripts/dev-server-cors.test.d.ts.map +1 -0
  187. package/dist/scripts/dev-server-cors.test.js +23 -0
  188. package/dist/scripts/dev-server-telemetry.test.d.ts +2 -0
  189. package/dist/scripts/dev-server-telemetry.test.d.ts.map +1 -0
  190. package/dist/scripts/dev-server-telemetry.test.js +113 -0
  191. package/dist/scripts/dev-server.d.ts +21 -0
  192. package/dist/scripts/dev-server.d.ts.map +1 -0
  193. package/dist/scripts/dev-server.js +456 -0
  194. package/dist/scripts/ensure-secrets.d.ts +31 -0
  195. package/dist/scripts/ensure-secrets.d.ts.map +1 -0
  196. package/dist/scripts/ensure-secrets.js +100 -0
  197. package/dist/scripts/ensure-secrets.test.d.ts +2 -0
  198. package/dist/scripts/ensure-secrets.test.d.ts.map +1 -0
  199. package/dist/scripts/ensure-secrets.test.js +44 -0
  200. package/dist/scripts/external-migrations-step.d.ts +62 -0
  201. package/dist/scripts/external-migrations-step.d.ts.map +1 -0
  202. package/dist/scripts/external-migrations-step.js +243 -0
  203. package/dist/scripts/external-migrations-step.test.d.ts +2 -0
  204. package/dist/scripts/external-migrations-step.test.d.ts.map +1 -0
  205. package/dist/scripts/external-migrations-step.test.js +47 -0
  206. package/dist/scripts/extract-ts-types.d.ts +65 -0
  207. package/dist/scripts/extract-ts-types.d.ts.map +1 -0
  208. package/dist/scripts/extract-ts-types.js +664 -0
  209. package/dist/scripts/extract-ts-types.test.d.ts +2 -0
  210. package/dist/scripts/extract-ts-types.test.d.ts.map +1 -0
  211. package/dist/scripts/extract-ts-types.test.js +497 -0
  212. package/dist/scripts/generate-client-worker.d.ts +2 -0
  213. package/dist/scripts/generate-client-worker.d.ts.map +1 -0
  214. package/dist/scripts/generate-client-worker.js +13 -0
  215. package/dist/scripts/generate-client.d.ts +14 -0
  216. package/dist/scripts/generate-client.d.ts.map +1 -0
  217. package/dist/scripts/generate-client.js +73 -0
  218. package/dist/scripts/generate-client.test.d.ts +2 -0
  219. package/dist/scripts/generate-client.test.d.ts.map +1 -0
  220. package/dist/scripts/generate-client.test.js +48 -0
  221. package/dist/scripts/generate-spec-cli.d.ts +3 -0
  222. package/dist/scripts/generate-spec-cli.d.ts.map +1 -0
  223. package/dist/scripts/generate-spec-cli.js +77 -0
  224. package/dist/scripts/generate-spec-cli.test.d.ts +14 -0
  225. package/dist/scripts/generate-spec-cli.test.d.ts.map +1 -0
  226. package/dist/scripts/generate-spec-cli.test.js +90 -0
  227. package/dist/scripts/generate-spec.d.ts +61 -0
  228. package/dist/scripts/generate-spec.d.ts.map +1 -0
  229. package/dist/scripts/generate-spec.js +746 -0
  230. package/dist/scripts/generate-spec.test.d.ts +12 -0
  231. package/dist/scripts/generate-spec.test.d.ts.map +1 -0
  232. package/dist/scripts/generate-spec.test.js +88 -0
  233. package/dist/scripts/index.d.ts +12 -0
  234. package/dist/scripts/index.d.ts.map +1 -0
  235. package/dist/scripts/index.js +13 -0
  236. package/dist/scripts/sandbox.d.ts +11 -0
  237. package/dist/scripts/sandbox.d.ts.map +1 -0
  238. package/dist/scripts/sandbox.js +200 -0
  239. package/dist/scripts/telemetry-cli.d.ts +3 -0
  240. package/dist/scripts/telemetry-cli.d.ts.map +1 -0
  241. package/dist/scripts/telemetry-cli.js +8 -0
  242. package/dist/scripts/telemetry.d.ts +17 -0
  243. package/dist/scripts/telemetry.d.ts.map +1 -0
  244. package/dist/scripts/telemetry.js +150 -0
  245. package/dist/scripts/telemetry.test.d.ts +2 -0
  246. package/dist/scripts/telemetry.test.d.ts.map +1 -0
  247. package/dist/scripts/telemetry.test.js +203 -0
  248. package/dist/scripts/validate-spec.d.ts +22 -0
  249. package/dist/scripts/validate-spec.d.ts.map +1 -0
  250. package/dist/scripts/validate-spec.js +159 -0
  251. package/dist/server/index.d.ts +3 -0
  252. package/dist/server/index.d.ts.map +1 -0
  253. package/dist/server/index.js +3 -0
  254. package/dist/server/withAuth.d.ts +142 -0
  255. package/dist/server/withAuth.d.ts.map +1 -0
  256. package/dist/server/withAuth.js +261 -0
  257. package/dist/server/withAuth.test.d.ts +2 -0
  258. package/dist/server/withAuth.test.d.ts.map +1 -0
  259. package/dist/server/withAuth.test.js +278 -0
  260. package/dist/telemetry/client.d.ts +59 -0
  261. package/dist/telemetry/client.d.ts.map +1 -0
  262. package/dist/telemetry/client.js +215 -0
  263. package/dist/telemetry/config-writer.d.ts +16 -0
  264. package/dist/telemetry/config-writer.d.ts.map +1 -0
  265. package/dist/telemetry/config-writer.js +36 -0
  266. package/dist/telemetry/consent-commands.test.d.ts +2 -0
  267. package/dist/telemetry/consent-commands.test.d.ts.map +1 -0
  268. package/dist/telemetry/consent-commands.test.js +161 -0
  269. package/dist/telemetry/consent.d.ts +60 -0
  270. package/dist/telemetry/consent.d.ts.map +1 -0
  271. package/dist/telemetry/consent.js +122 -0
  272. package/dist/telemetry/environment.d.ts +33 -0
  273. package/dist/telemetry/environment.d.ts.map +1 -0
  274. package/dist/telemetry/environment.js +87 -0
  275. package/dist/telemetry/identifiers.d.ts +20 -0
  276. package/dist/telemetry/identifiers.d.ts.map +1 -0
  277. package/dist/telemetry/identifiers.js +86 -0
  278. package/dist/telemetry/index.d.ts +6 -0
  279. package/dist/telemetry/index.d.ts.map +1 -0
  280. package/dist/telemetry/index.js +4 -0
  281. package/dist/telemetry/telemetry.test.d.ts +2 -0
  282. package/dist/telemetry/telemetry.test.d.ts.map +1 -0
  283. package/dist/telemetry/telemetry.test.js +1131 -0
  284. package/dist/telemetry/trackCommand.d.ts +32 -0
  285. package/dist/telemetry/trackCommand.d.ts.map +1 -0
  286. package/dist/telemetry/trackCommand.js +102 -0
  287. package/dist/telemetry/types.d.ts +92 -0
  288. package/dist/telemetry/types.d.ts.map +1 -0
  289. package/dist/telemetry/types.js +1 -0
  290. package/dist/types.d.ts +24 -0
  291. package/dist/types.d.ts.map +1 -0
  292. package/dist/types.js +3 -0
  293. package/dist/version.d.ts +2 -0
  294. package/dist/version.d.ts.map +1 -0
  295. package/dist/version.js +2 -0
  296. package/package.json +83 -0
  297. package/src/api.test.ts +25 -0
  298. package/src/api.ts +163 -0
  299. package/src/bb-utils.ts +13 -0
  300. package/src/builtin-routes.ts +62 -0
  301. package/src/cdk/__fixtures__/factory-backend.ts +8 -0
  302. package/src/cdk/__fixtures__/fullid-construct-backend.ts +42 -0
  303. package/src/cdk/__fixtures__/handler.ts +4 -0
  304. package/src/cdk/__fixtures__/side-effect-backend.ts +7 -0
  305. package/src/cdk/blocks-backend.test.ts +207 -0
  306. package/src/cdk/blocks-backend.ts +249 -0
  307. package/src/cdk/blocks-stack.test.ts +106 -0
  308. package/src/cdk/config-registry.ts +106 -0
  309. package/src/cdk/index.ts +115 -0
  310. package/src/cdk/mixins.test.ts +129 -0
  311. package/src/cdk/mixins.ts +41 -0
  312. package/src/cdk/node-version.ts +17 -0
  313. package/src/cdk/stack-metadata.test.ts +71 -0
  314. package/src/cdk/stack-metadata.ts +29 -0
  315. package/src/cdk/synth-guard.test.ts +21 -0
  316. package/src/cdk/synth-guard.ts +23 -0
  317. package/src/client/index.test.ts +118 -0
  318. package/src/client/index.ts +320 -0
  319. package/src/common/config.test.ts +236 -0
  320. package/src/common/config.ts +169 -0
  321. package/src/common/constants.ts +15 -0
  322. package/src/common/crypto.ts +15 -0
  323. package/src/common/index.test.ts +242 -0
  324. package/src/common/index.ts +335 -0
  325. package/src/common/mock-data.ts +52 -0
  326. package/src/common/official-bb-names.generated.ts +29 -0
  327. package/src/common/sdk-registry.ts +150 -0
  328. package/src/constants.ts +31 -0
  329. package/src/cors.test.ts +279 -0
  330. package/src/cors.ts +91 -0
  331. package/src/db-naming.test.ts +48 -0
  332. package/src/db-naming.ts +41 -0
  333. package/src/errors.ts +72 -0
  334. package/src/hosting.test.ts +1431 -0
  335. package/src/hosting.ts +626 -0
  336. package/src/index.cdk.ts +45 -0
  337. package/src/index.ts +22 -0
  338. package/src/lambda-handler.test.ts +1005 -0
  339. package/src/lambda-handler.ts +706 -0
  340. package/src/pipeline/index.ts +12 -0
  341. package/src/pipeline/pipeline-construct.ts +662 -0
  342. package/src/pipeline/pipeline.test.ts +1565 -0
  343. package/src/pipeline/types.ts +384 -0
  344. package/src/raw-route.cdk.ts +56 -0
  345. package/src/raw-route.mock.ts +56 -0
  346. package/src/raw-route.test.ts +819 -0
  347. package/src/raw-route.ts +316 -0
  348. package/src/redact.test.ts +222 -0
  349. package/src/redact.ts +143 -0
  350. package/src/rpc.test.ts +73 -0
  351. package/src/rpc.ts +174 -0
  352. package/src/scripts/cdk-telemetry-env.test.ts +75 -0
  353. package/src/scripts/cdk-telemetry-env.ts +23 -0
  354. package/src/scripts/cleanup.ts +39 -0
  355. package/src/scripts/console.ts +34 -0
  356. package/src/scripts/deploy.ts +106 -0
  357. package/src/scripts/destroy.ts +42 -0
  358. package/src/scripts/dev-server-cors.test.ts +28 -0
  359. package/src/scripts/dev-server-telemetry.test.ts +127 -0
  360. package/src/scripts/dev-server.ts +515 -0
  361. package/src/scripts/ensure-secrets.test.ts +50 -0
  362. package/src/scripts/ensure-secrets.ts +113 -0
  363. package/src/scripts/external-migrations-step.test.ts +64 -0
  364. package/src/scripts/external-migrations-step.ts +269 -0
  365. package/src/scripts/extract-ts-types.test.ts +516 -0
  366. package/src/scripts/extract-ts-types.ts +773 -0
  367. package/src/scripts/generate-client-worker.ts +15 -0
  368. package/src/scripts/generate-client.test.ts +69 -0
  369. package/src/scripts/generate-client.ts +86 -0
  370. package/src/scripts/generate-spec-cli.test.ts +106 -0
  371. package/src/scripts/generate-spec-cli.ts +92 -0
  372. package/src/scripts/generate-spec.test.ts +99 -0
  373. package/src/scripts/generate-spec.ts +833 -0
  374. package/src/scripts/index.ts +21 -0
  375. package/src/scripts/sandbox.ts +230 -0
  376. package/src/scripts/telemetry-cli.ts +10 -0
  377. package/src/scripts/telemetry.test.ts +239 -0
  378. package/src/scripts/telemetry.ts +173 -0
  379. package/src/scripts/validate-spec.ts +199 -0
  380. package/src/server/index.ts +5 -0
  381. package/src/server/withAuth.test.ts +348 -0
  382. package/src/server/withAuth.ts +323 -0
  383. package/src/telemetry/client.ts +226 -0
  384. package/src/telemetry/config-writer.ts +52 -0
  385. package/src/telemetry/consent-commands.test.ts +196 -0
  386. package/src/telemetry/consent.ts +154 -0
  387. package/src/telemetry/environment.ts +100 -0
  388. package/src/telemetry/identifiers.ts +94 -0
  389. package/src/telemetry/index.ts +11 -0
  390. package/src/telemetry/telemetry.test.ts +1343 -0
  391. package/src/telemetry/trackCommand.ts +110 -0
  392. package/src/telemetry/types.ts +92 -0
  393. package/src/types.ts +33 -0
  394. package/src/version.ts +2 -0
@@ -0,0 +1,90 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import * as cdk from 'aws-cdk-lib';
4
+ import { Construct } from 'constructs';
5
+ import { computeScopeFullId, } from '../common/index.js';
6
+ import { setupBlocksInfra, BlocksBackend, assertCdkConditionActive } from './blocks-backend.js';
7
+ import { addBlocksStackMetadata } from './stack-metadata.js';
8
+ import { finalizeConfigRegistry } from './config-registry.js';
9
+ export { BlocksBackend } from './blocks-backend.js';
10
+ export { DEFAULT_NODE_RUNTIME } from './node-version.js';
11
+ export { SandboxDisableDeletionProtection } from './mixins.js';
12
+ export { registerConfig, finalizeConfigRegistry } from './config-registry.js';
13
+ export { synthGuard } from './synth-guard.js';
14
+ export { ApiError, isBlocksError } from '../errors.js';
15
+ export class BlocksStack extends cdk.Stack {
16
+ id;
17
+ apiUrl;
18
+ gateway;
19
+ handler;
20
+ backendHandlerPath;
21
+ constructor(scope, id, props) {
22
+ super(scope, id, props);
23
+ this.id = id;
24
+ this.backendHandlerPath = props.backendHandlerPath;
25
+ // Set globalThis so Building Blocks attach directly to this stack
26
+ globalThis.CURRENT_BLOCKS_STACK = this;
27
+ const infra = setupBlocksInfra(this, props, id);
28
+ this.handler = infra.handler;
29
+ this.gateway = infra.gateway;
30
+ this.apiUrl = infra.apiUrl;
31
+ }
32
+ static async create(scope, id, props) {
33
+ assertCdkConditionActive();
34
+ // Detect ambient pipeline stage scope set by Pipeline appFile imports
35
+ const pipelineScope = globalThis.__PIPELINE_STAGE_SCOPE__;
36
+ const actualScope = pipelineScope || scope;
37
+ const stack = new BlocksStack(actualScope, id, props);
38
+ // ESM caches modules by URL — append a unique query string so each stage re-executes the module body
39
+ const mod = await import(`${props.backendCDKPath}?stack=${id}`);
40
+ if (typeof mod.default === 'function') {
41
+ try {
42
+ await mod.default(stack);
43
+ }
44
+ catch (error) {
45
+ throw new Error(`Error executing default export function for stack "${id}": ${error instanceof Error ? error.message : error}`, { cause: error });
46
+ }
47
+ }
48
+ // Finalize BB config → S3 (after all BBs have registered their config)
49
+ finalizeConfigRegistry(stack, stack.handler);
50
+ new cdk.CfnOutput(stack, 'ApiUrl', { value: stack.apiUrl });
51
+ addBlocksStackMetadata(stack);
52
+ return stack;
53
+ }
54
+ }
55
+ export class Scope extends Construct {
56
+ id;
57
+ parent;
58
+ bbName;
59
+ bbVersion;
60
+ constructor(id, options) {
61
+ const parent = options?.parent || globalThis.CURRENT_BLOCKS_STACK;
62
+ super(parent, id);
63
+ this.id = id;
64
+ this.parent = parent;
65
+ }
66
+ get handler() {
67
+ // Walk up the construct tree to find the owning BlocksStack/BlocksBackend
68
+ let current = this;
69
+ while (current.node.scope) {
70
+ current = current.node.scope;
71
+ if (current instanceof BlocksStack || current instanceof BlocksBackend) {
72
+ return current.handler;
73
+ }
74
+ }
75
+ // Fallback to globalThis for backward compatibility
76
+ return globalThis.CURRENT_BLOCKS_STACK.handler;
77
+ }
78
+ get fullId() {
79
+ return computeScopeFullId(this);
80
+ }
81
+ buildUserAgentChain() {
82
+ return [];
83
+ }
84
+ // Plugin registration — no-ops in CDK context (plugins are only used at dev/build time)
85
+ registerClientMiddleware(_packageSpecifier) { }
86
+ registerDevAttachment(_packageSpecifier) { }
87
+ registerLambdaEventHandler(_eventSource, _identifier, _handler) { }
88
+ get clientMiddleware() { return []; }
89
+ get devAttachments() { return []; }
90
+ }
@@ -0,0 +1,28 @@
1
+ import { Mixin } from 'aws-cdk-lib';
2
+ import type { IConstruct } from 'constructs';
3
+ import type { IMixin } from 'constructs';
4
+ /**
5
+ * Disables deletion protection on any construct that has a `deletionProtection`
6
+ * property (e.g. RDS clusters, RDS instances). Uses duck-typing so it
7
+ * automatically covers current and future resource types.
8
+ *
9
+ * Intended for sandbox teardown — use in the CDK layer alongside
10
+ * `RemovalPolicies.of(stack).destroy()` to ensure `sandbox:destroy` can
11
+ * delete the entire stack without manual cleanup.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { RemovalPolicies, Mixins } from 'aws-cdk-lib';
16
+ * import { SandboxDisableDeletionProtection } from '@aws-blocks/blocks/cdk';
17
+ *
18
+ * if (sandboxMode) {
19
+ * RemovalPolicies.of(stack).destroy();
20
+ * Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
21
+ * }
22
+ * ```
23
+ */
24
+ export declare class SandboxDisableDeletionProtection extends Mixin implements IMixin {
25
+ supports(construct: any): boolean;
26
+ applyTo(node: IConstruct): void;
27
+ }
28
+ //# sourceMappingURL=mixins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixins.d.ts","sourceRoot":"","sources":["../../src/cdk/mixins.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,gCAAiC,SAAQ,KAAM,YAAW,MAAM;IAC3E,QAAQ,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO;IAGjC,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;CAShC"}
@@ -0,0 +1,37 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Mixin } from 'aws-cdk-lib';
4
+ /**
5
+ * Disables deletion protection on any construct that has a `deletionProtection`
6
+ * property (e.g. RDS clusters, RDS instances). Uses duck-typing so it
7
+ * automatically covers current and future resource types.
8
+ *
9
+ * Intended for sandbox teardown — use in the CDK layer alongside
10
+ * `RemovalPolicies.of(stack).destroy()` to ensure `sandbox:destroy` can
11
+ * delete the entire stack without manual cleanup.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { RemovalPolicies, Mixins } from 'aws-cdk-lib';
16
+ * import { SandboxDisableDeletionProtection } from '@aws-blocks/blocks/cdk';
17
+ *
18
+ * if (sandboxMode) {
19
+ * RemovalPolicies.of(stack).destroy();
20
+ * Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
21
+ * }
22
+ * ```
23
+ */
24
+ export class SandboxDisableDeletionProtection extends Mixin {
25
+ supports(construct) {
26
+ return 'deletionProtection' in construct;
27
+ }
28
+ applyTo(node) {
29
+ // Only flip explicitly-enabled protection. When undefined (the default),
30
+ // deletion protection is already off — setting it to false would emit the
31
+ // property in the CloudFormation template, which breaks Aurora DB instances
32
+ // (RDS rejects DeletionProtection on cluster members).
33
+ if (node.deletionProtection === true) {
34
+ node.deletionProtection = false;
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mixins.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mixins.test.d.ts","sourceRoot":"","sources":["../../src/cdk/mixins.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,108 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { test, describe } from 'node:test';
4
+ import * as cdk from 'aws-cdk-lib';
5
+ import { Template, Match } from 'aws-cdk-lib/assertions';
6
+ import { Table, AttributeType, BillingMode } from 'aws-cdk-lib/aws-dynamodb';
7
+ import * as rds from 'aws-cdk-lib/aws-rds';
8
+ import * as ec2 from 'aws-cdk-lib/aws-ec2';
9
+ import { RemovalPolicies, Mixins } from 'aws-cdk-lib';
10
+ import { SandboxDisableDeletionProtection } from './mixins.js';
11
+ describe('sandbox removal policy', () => {
12
+ test('sandbox mode: DeletionPolicy is Delete on all resources', () => {
13
+ const app = new cdk.App({ context: { sandboxMode: 'true' } });
14
+ const stack = new cdk.Stack(app, 'TestStack');
15
+ new Table(stack, 'MyTable', {
16
+ partitionKey: { name: 'pk', type: AttributeType.STRING },
17
+ billingMode: BillingMode.PAY_PER_REQUEST,
18
+ });
19
+ RemovalPolicies.of(stack).destroy();
20
+ const template = Template.fromStack(stack);
21
+ template.hasResource('AWS::DynamoDB::Table', {
22
+ DeletionPolicy: 'Delete',
23
+ });
24
+ });
25
+ test('sandbox mode: deletionProtection disabled on RDS cluster', () => {
26
+ const app = new cdk.App({ context: { sandboxMode: 'true' } });
27
+ const stack = new cdk.Stack(app, 'TestStack');
28
+ const vpc = new ec2.Vpc(stack, 'Vpc', {
29
+ maxAzs: 2,
30
+ natGateways: 0,
31
+ subnetConfiguration: [
32
+ { name: 'isolated', subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
33
+ ],
34
+ });
35
+ new rds.DatabaseCluster(stack, 'Cluster', {
36
+ engine: rds.DatabaseClusterEngine.auroraPostgres({
37
+ version: rds.AuroraPostgresEngineVersion.VER_16_4,
38
+ }),
39
+ writer: rds.ClusterInstance.serverlessV2('Writer'),
40
+ vpc,
41
+ vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
42
+ deletionProtection: true,
43
+ });
44
+ RemovalPolicies.of(stack).destroy();
45
+ Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
46
+ const template = Template.fromStack(stack);
47
+ template.hasResourceProperties('AWS::RDS::DBCluster', {
48
+ DeletionProtection: false,
49
+ });
50
+ template.hasResource('AWS::RDS::DBCluster', {
51
+ DeletionPolicy: 'Delete',
52
+ });
53
+ });
54
+ test('production mode: default DeletionPolicy is Retain (CDK default, no explicit call needed)', () => {
55
+ const app = new cdk.App();
56
+ const stack = new cdk.Stack(app, 'TestStack');
57
+ new Table(stack, 'MyTable', {
58
+ partitionKey: { name: 'pk', type: AttributeType.STRING },
59
+ billingMode: BillingMode.PAY_PER_REQUEST,
60
+ });
61
+ // No removal policy call — CDK defaults to RETAIN
62
+ const template = Template.fromStack(stack);
63
+ template.hasResource('AWS::DynamoDB::Table', {
64
+ DeletionPolicy: 'Retain',
65
+ });
66
+ });
67
+ test('SandboxDisableDeletionProtection mixin: does not set deletionProtection on Aurora instances', () => {
68
+ const app = new cdk.App();
69
+ const stack = new cdk.Stack(app, 'TestStack');
70
+ const vpc = new ec2.Vpc(stack, 'Vpc', {
71
+ maxAzs: 2,
72
+ natGateways: 0,
73
+ subnetConfiguration: [
74
+ { name: 'isolated', subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
75
+ ],
76
+ });
77
+ new rds.DatabaseCluster(stack, 'Cluster', {
78
+ engine: rds.DatabaseClusterEngine.auroraPostgres({
79
+ version: rds.AuroraPostgresEngineVersion.VER_16_4,
80
+ }),
81
+ writer: rds.ClusterInstance.serverlessV2('Writer'),
82
+ vpc,
83
+ vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED },
84
+ removalPolicy: cdk.RemovalPolicy.DESTROY,
85
+ });
86
+ RemovalPolicies.of(stack).destroy();
87
+ Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
88
+ const template = Template.fromStack(stack);
89
+ // Aurora DB instance should NOT have DeletionProtection set at all
90
+ // (RDS rejects it for cluster members)
91
+ template.hasResourceProperties('AWS::RDS::DBInstance', {
92
+ DeletionProtection: Match.absent(),
93
+ });
94
+ });
95
+ test('SandboxDisableDeletionProtection mixin: skips constructs without deletionProtection', () => {
96
+ const app = new cdk.App();
97
+ const stack = new cdk.Stack(app, 'TestStack');
98
+ new Table(stack, 'MyTable', {
99
+ partitionKey: { name: 'pk', type: AttributeType.STRING },
100
+ billingMode: BillingMode.PAY_PER_REQUEST,
101
+ });
102
+ // Should not throw — DynamoDB Table has no deletionProtection property
103
+ Mixins.of(stack).apply(new SandboxDisableDeletionProtection());
104
+ const template = Template.fromStack(stack);
105
+ // Table should still synthesize normally
106
+ template.resourceCountIs('AWS::DynamoDB::Table', 1);
107
+ });
108
+ });
@@ -0,0 +1,14 @@
1
+ import { Runtime } from 'aws-cdk-lib/aws-lambda';
2
+ /**
3
+ * The single source of truth for the Node.js Lambda runtime used by Blocks's
4
+ * own Lambda functions and every Building Block. Set every
5
+ * `aws_lambda.Function` / `NodejsFunction` runtime to this constant rather
6
+ * than hardcoding `Runtime.NODEJS_*_X`, so the whole framework moves in
7
+ * lockstep when the runtime is bumped.
8
+ *
9
+ * Currently the latest Active LTS. This controls only the AWS-managed
10
+ * runtime that executes deployed handlers; it is independent of the Node
11
+ * version a consumer runs the CLI / CDK synth on.
12
+ */
13
+ export declare const DEFAULT_NODE_RUNTIME: Runtime;
14
+ //# sourceMappingURL=node-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-version.d.ts","sourceRoot":"","sources":["../../src/cdk/node-version.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,SAAsB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Runtime } from 'aws-cdk-lib/aws-lambda';
4
+ /**
5
+ * The single source of truth for the Node.js Lambda runtime used by Blocks's
6
+ * own Lambda functions and every Building Block. Set every
7
+ * `aws_lambda.Function` / `NodejsFunction` runtime to this constant rather
8
+ * than hardcoding `Runtime.NODEJS_*_X`, so the whole framework moves in
9
+ * lockstep when the runtime is bumped.
10
+ *
11
+ * Currently the latest Active LTS. This controls only the AWS-managed
12
+ * runtime that executes deployed handlers; it is independent of the Node
13
+ * version a consumer runs the CLI / CDK synth on.
14
+ */
15
+ export const DEFAULT_NODE_RUNTIME = Runtime.NODEJS_24_X;
@@ -0,0 +1,12 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ /**
3
+ * Adds AWS Blocks identification metadata and a deployment-type tag to a CloudFormation stack.
4
+ *
5
+ * Sets `AWS::Blocks::Platform` template metadata with the current core version
6
+ * and applies a `blocks:deployment-type` tag (`sandbox` or `production`) based on
7
+ * the CDK context key `sandboxMode`.
8
+ *
9
+ * @param stack - The CDK stack to annotate.
10
+ */
11
+ export declare function addBlocksStackMetadata(stack: cdk.Stack): void;
12
+ //# sourceMappingURL=stack-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-metadata.d.ts","sourceRoot":"","sources":["../../src/cdk/stack-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAgB7D"}
@@ -0,0 +1,22 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import { CORE_VERSION } from '../version.js';
3
+ /**
4
+ * Adds AWS Blocks identification metadata and a deployment-type tag to a CloudFormation stack.
5
+ *
6
+ * Sets `AWS::Blocks::Platform` template metadata with the current core version
7
+ * and applies a `blocks:deployment-type` tag (`sandbox` or `production`) based on
8
+ * the CDK context key `sandboxMode`.
9
+ *
10
+ * @param stack - The CDK stack to annotate.
11
+ */
12
+ export function addBlocksStackMetadata(stack) {
13
+ stack.templateOptions.metadata = {
14
+ ...stack.templateOptions.metadata,
15
+ 'AWS::Blocks::Platform': {
16
+ version: CORE_VERSION,
17
+ },
18
+ };
19
+ const isSandbox = stack.node.tryGetContext('sandboxMode') === 'true' ||
20
+ stack.node.tryGetContext('sandboxMode') === true;
21
+ cdk.Tags.of(stack).add('blocks:deployment-type', isSandbox ? 'sandbox' : 'production');
22
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=stack-metadata.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack-metadata.test.d.ts","sourceRoot":"","sources":["../../src/cdk/stack-metadata.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,56 @@
1
+ import { test, describe } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import * as cdk from 'aws-cdk-lib';
4
+ import { Template } from 'aws-cdk-lib/assertions';
5
+ import { addBlocksStackMetadata } from './stack-metadata.js';
6
+ import { CORE_VERSION } from '../version.js';
7
+ describe('addBlocksStackMetadata', () => {
8
+ test('adds AWS::Blocks::Platform metadata with correct version', () => {
9
+ const app = new cdk.App();
10
+ const stack = new cdk.Stack(app, 'TestStack');
11
+ addBlocksStackMetadata(stack);
12
+ const template = Template.fromStack(stack);
13
+ const metadata = template.toJSON().Metadata;
14
+ assert.deepStrictEqual(metadata['AWS::Blocks::Platform'], {
15
+ version: CORE_VERSION,
16
+ });
17
+ });
18
+ test('preserves existing template metadata', () => {
19
+ const app = new cdk.App();
20
+ const stack = new cdk.Stack(app, 'ExistingMetaStack');
21
+ stack.templateOptions.metadata = {
22
+ 'Custom::Existing': { key: 'value' },
23
+ };
24
+ addBlocksStackMetadata(stack);
25
+ const template = Template.fromStack(stack);
26
+ const metadata = template.toJSON().Metadata;
27
+ assert.deepStrictEqual(metadata['Custom::Existing'], { key: 'value' });
28
+ assert.deepStrictEqual(metadata['AWS::Blocks::Platform'], {
29
+ version: CORE_VERSION,
30
+ });
31
+ });
32
+ test('tags deployment-type as production when sandboxMode context is absent', () => {
33
+ const app = new cdk.App();
34
+ const stack = new cdk.Stack(app, 'ProdStack');
35
+ addBlocksStackMetadata(stack);
36
+ const assembly = app.synth();
37
+ const stackArtifact = assembly.getStackByName(stack.stackName);
38
+ assert.strictEqual(stackArtifact.tags['blocks:deployment-type'], 'production');
39
+ });
40
+ test('tags deployment-type as sandbox when sandboxMode context is boolean true', () => {
41
+ const app = new cdk.App({ context: { sandboxMode: true } });
42
+ const stack = new cdk.Stack(app, 'SandboxBoolStack');
43
+ addBlocksStackMetadata(stack);
44
+ const assembly = app.synth();
45
+ const stackArtifact = assembly.getStackByName(stack.stackName);
46
+ assert.strictEqual(stackArtifact.tags['blocks:deployment-type'], 'sandbox');
47
+ });
48
+ test('tags deployment-type as sandbox when sandboxMode context is string "true"', () => {
49
+ const app = new cdk.App({ context: { sandboxMode: 'true' } });
50
+ const stack = new cdk.Stack(app, 'SandboxStringStack');
51
+ addBlocksStackMetadata(stack);
52
+ const assembly = app.synth();
53
+ const stackArtifact = assembly.getStackByName(stack.stackName);
54
+ assert.strictEqual(stackArtifact.tags['blocks:deployment-type'], 'sandbox');
55
+ });
56
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Throws an actionable error when a runtime-only method is called during CDK synth.
3
+ *
4
+ * Under `--conditions=cdk` Building Block modules resolve to their CDK construct,
5
+ * which only provisions infrastructure. Data/runtime methods live in the runtime
6
+ * build. Calling them at module top-level (which runs during synth) would otherwise
7
+ * fail with a cryptic `X is not a function` TypeError; this utility turns that into
8
+ * an actionable message directing the user to the correct execution context.
9
+ *
10
+ * @param className - The Building Block class name (e.g. "KVStore", "DistributedTable")
11
+ * @param method - The method that was called (e.g. "get", "put")
12
+ */
13
+ export declare function synthGuard(className: string, method: string): never;
14
+ //# sourceMappingURL=synth-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synth-guard.d.ts","sourceRoot":"","sources":["../../src/cdk/synth-guard.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAOnE"}
@@ -0,0 +1,20 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Throws an actionable error when a runtime-only method is called during CDK synth.
5
+ *
6
+ * Under `--conditions=cdk` Building Block modules resolve to their CDK construct,
7
+ * which only provisions infrastructure. Data/runtime methods live in the runtime
8
+ * build. Calling them at module top-level (which runs during synth) would otherwise
9
+ * fail with a cryptic `X is not a function` TypeError; this utility turns that into
10
+ * an actionable message directing the user to the correct execution context.
11
+ *
12
+ * @param className - The Building Block class name (e.g. "KVStore", "DistributedTable")
13
+ * @param method - The method that was called (e.g. "get", "put")
14
+ */
15
+ export function synthGuard(className, method) {
16
+ throw new Error(`${className}.${method}() cannot be called during CDK synth. ` +
17
+ `Data methods run at request time — call them inside an ApiNamespace method, ` +
18
+ `RawRoute handler, job handler, or a runtime script (run with --conditions=aws-runtime), ` +
19
+ `not at the top level of your backend module.`);
20
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=synth-guard.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synth-guard.test.d.ts","sourceRoot":"","sources":["../../src/cdk/synth-guard.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { synthGuard } from './synth-guard.js';
6
+ test('synthGuard throws an error mentioning the class and method name', () => {
7
+ assert.throws(() => synthGuard('MyBlock', 'doThing'), (err) => {
8
+ assert.match(err.message, /MyBlock\.doThing\(\) cannot be called during CDK synth/);
9
+ assert.match(err.message, /--conditions=aws-runtime/);
10
+ return true;
11
+ });
12
+ });
13
+ test('synthGuard always throws (return type is never)', () => {
14
+ assert.throws(() => synthGuard('X', 'y'));
15
+ });
@@ -0,0 +1,97 @@
1
+ export type BlocksContext = any;
2
+ export type ApiHandler<T extends Record<string, (...args: any[]) => any>> = any;
3
+ type AsyncAPI<T extends Record<string, (...args: any[]) => any>> = {
4
+ [K in keyof T]: T[K] extends (...args: infer Args) => infer R ? (...args: Args) => Promise<Awaited<R>> : never;
5
+ };
6
+ /**
7
+ * A Blocks request object passed through middleware before being sent.
8
+ * Middleware can inspect or modify any of these properties before the
9
+ * request is dispatched to the server.
10
+ */
11
+ export interface KitRequest {
12
+ /** The namespace name this call targets (e.g., 'api', 'auth'). Corresponds to the second argument of `new ApiNamespace(scope, name, handler)` in the backend. */
13
+ apiNamespace: string;
14
+ /** The method being called on the namespace (e.g., 'getUser', 'kvSet'). */
15
+ method: string;
16
+ /** The arguments passed to the method call. */
17
+ args: any[];
18
+ /** HTTP headers that will be sent with the request. Middleware can add or modify headers (e.g., inject auth tokens). */
19
+ headers: Record<string, string>;
20
+ }
21
+ /**
22
+ * Client middleware that can process requests before they are sent
23
+ * and/or responses after they are received. Both hooks are optional.
24
+ *
25
+ * ```typescript
26
+ * // Request middleware — inject auth token
27
+ * registerMiddleware({
28
+ * onRequest(req) {
29
+ * req.headers['authorization'] = `Bearer ${getToken()}`;
30
+ * }
31
+ * });
32
+ *
33
+ * // Response middleware — hydrate transferable descriptors
34
+ * registerMiddleware({
35
+ * onResponse(data) {
36
+ * if (isMyDescriptor(data)) return hydrate(data);
37
+ * return data;
38
+ * }
39
+ * });
40
+ * ```
41
+ */
42
+ export interface KitMiddleware {
43
+ /** Transform the request before it's sent. Modify the request in place or return a new one. Can be async. */
44
+ onRequest?: (request: KitRequest) => KitRequest | void | Promise<KitRequest | void>;
45
+ /** Transform the response data after it's received. Used to hydrate __blocks descriptors. */
46
+ onResponse?: (data: unknown) => unknown;
47
+ }
48
+ /**
49
+ * Register client middleware for request/response processing.
50
+ *
51
+ * Building Block middleware packages call this on import to register
52
+ * hooks that run on every API call. Request hooks can inject headers
53
+ * (e.g., auth tokens). Response hooks hydrate `{ __blocks: '...' }`
54
+ * descriptors into live client-side objects (e.g., WebSocket channels).
55
+ *
56
+ * Client middleware uses a **self-registering** pattern: the middleware
57
+ * module imports this function and calls it as a side effect of being
58
+ * imported. The generated `client.js` simply includes
59
+ * `import 'bb-realtime/mock-middleware'` — no explicit registration
60
+ * code is needed. This is idiomatic for browser/bundler contexts where
61
+ * side-effect imports are standard (similar to CSS imports or polyfills).
62
+ *
63
+ * This differs intentionally from **dev server attachments**, which use
64
+ * an explicit `attach(server)` pattern because they need the HTTP server
65
+ * instance passed to them — something unavailable at import time.
66
+ */
67
+ export declare function registerMiddleware(middleware: KitMiddleware): void;
68
+ /**
69
+ * Options for `ApiNamespaceClient`.
70
+ */
71
+ export interface ApiNamespaceClientOptions {
72
+ /** Explicit API URL. When provided, skips automatic config.json discovery. */
73
+ url?: string;
74
+ }
75
+ /**
76
+ * Client-side API proxy. Creates a typed proxy that sends method calls
77
+ * to the backend API over HTTP and hydrates Transferable descriptors
78
+ * in responses via registered middleware.
79
+ *
80
+ * This is the browser counterpart of the server-side `ApiNamespace` in
81
+ * `core/api.ts`. The generated `client.js` emits one of these per
82
+ * API namespace exported from the backend.
83
+ *
84
+ * ```typescript
85
+ * // Generated client.js
86
+ * import { ApiNamespaceClient } from '@aws-blocks/core/client';
87
+ * export const api = ApiNamespaceClient('api');
88
+ *
89
+ * // Frontend usage — fully typed via the 'aws-blocks' types export
90
+ * import { api } from 'aws-blocks';
91
+ * const user = await api.getUser('123');
92
+ * ```
93
+ */
94
+ export declare function ApiNamespaceClient<T extends Record<string, (...args: any[]) => any>>(name: string, options?: ApiNamespaceClientOptions): AsyncAPI<T>;
95
+ export { ApiError, isBlocksError } from '../errors.js';
96
+ export { Scope, type ScopeOptions } from '../common/index.js';
97
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC;AAChC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AAiBhF,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,IAAI;KAChE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,IAAI,KAAK,MAAM,CAAC,GACzD,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACtC,KAAK;CACV,CAAC;AAoHF;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,iKAAiK;IACjK,YAAY,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,wHAAwH;IACxH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,aAAa;IAC5B,6GAA6G;IAC7G,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IACpF,6FAA6F;IAC7F,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;CACzC;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI,CAElE;AAqBD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,EAClF,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,yBAAyB,GAClC,QAAQ,CAAC,CAAC,CAAC,CAyDb;AAED,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC"}