@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,214 @@
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 * as lambda from 'aws-cdk-lib/aws-lambda-nodejs';
5
+ import * as apigateway from 'aws-cdk-lib/aws-apigateway';
6
+ import { CfnGroup } from 'aws-cdk-lib/aws-resourcegroups';
7
+ import { Construct } from 'constructs';
8
+ import { DEFAULT_NODE_RUNTIME } from './node-version.js';
9
+ import { addBlocksStackMetadata } from './stack-metadata.js';
10
+ import { finalizeConfigRegistry, registerConfig } from './config-registry.js';
11
+ import { BLOCKS_NAMESPACE, BLOCKS_RPC_PREFIX } from '../constants.js';
12
+ import { registerBuiltinRoutes } from '../builtin-routes.js';
13
+ /**
14
+ * Validate that the Node.js process was started with `--conditions=cdk`.
15
+ *
16
+ * Without this condition, conditional exports in Building Block packages
17
+ * resolve to their mock/default entry points instead of the CDK entry points.
18
+ * This causes a silent deployment failure: CDK synth "succeeds" but produces
19
+ * no real infrastructure (no tables, no IAM, no Lambda configs).
20
+ */
21
+ export function assertCdkConditionActive() {
22
+ const nodeOptions = process.env.NODE_OPTIONS ?? '';
23
+ const execArgv = process.execArgv ?? [];
24
+ const hasCdkCondition = execArgv.some(arg => arg === '--conditions=cdk') ||
25
+ execArgv.some((arg, i) => (arg === '--conditions' || arg === '-C') && execArgv[i + 1] === 'cdk') ||
26
+ nodeOptions.includes('--conditions=cdk') ||
27
+ /(?:--conditions|-C)\s+cdk/.test(nodeOptions);
28
+ if (!hasCdkCondition) {
29
+ throw new Error('Missing --conditions=cdk: Building Blocks will silently load mock implementations instead of CDK constructs.\n\n' +
30
+ 'Fix: Set NODE_OPTIONS="--conditions=cdk" before running CDK synth:\n' +
31
+ ' NODE_OPTIONS="--conditions=cdk" npx cdk synth\n\n' +
32
+ 'Or use the Blocks CLI commands (npm run deploy / npm run sandbox) which set this automatically.');
33
+ }
34
+ }
35
+ /** Shared infra setup — creates Lambda + API Gateway on the given scope. */
36
+ export function setupBlocksInfra(scope, props, id) {
37
+ const handler = new lambda.NodejsFunction(scope, 'Handler', {
38
+ entry: props.backendHandlerPath,
39
+ runtime: DEFAULT_NODE_RUNTIME,
40
+ handler: 'handler',
41
+ memorySize: 2048,
42
+ timeout: cdk.Duration.seconds(60 * 15),
43
+ environment: {
44
+ NODE_ENV: 'production',
45
+ /**
46
+ * BLOCKS_STACK_NAME is used at runtime to derive physical resource names
47
+ * (DynamoDB table names, env var prefixes). It must match the CDK-time
48
+ * fullId of the BlocksStack/BlocksBackend so resource lookups work correctly.
49
+ *
50
+ * For BlocksStack: this equals the stack name (id).
51
+ * For BlocksBackend: the caller overrides this after construction to include
52
+ * the parent stack name for deployment uniqueness.
53
+ */
54
+ BLOCKS_STACK_NAME: id ?? cdk.Stack.of(scope).stackName,
55
+ },
56
+ bundling: {
57
+ minify: true,
58
+ esbuildArgs: { '--conditions': 'aws-runtime' },
59
+ },
60
+ });
61
+ // In sandbox mode, allow localhost origins so the local dev frontend can
62
+ // reach the deployed Lambda API via CORS.
63
+ const isSandbox = scope.node.tryGetContext('sandboxMode') === 'true' ||
64
+ scope.node.tryGetContext('sandboxMode') === true;
65
+ if (isSandbox) {
66
+ handler.addEnvironment('CORS_ALLOWED_ORIGINS', '^https?://(localhost|127\\.0\\.0\\.1)(:\\d+)?$');
67
+ }
68
+ const api = new apigateway.RestApi(scope, 'API', {
69
+ restApiName: 'Blocks API',
70
+ deployOptions: { cachingEnabled: false },
71
+ });
72
+ const integration = new apigateway.LambdaIntegration(handler);
73
+ // Build the nested resource tree for /aws-blocks/api.
74
+ // Intermediate resource gets a proxy so sub-paths (RawRoutes) still reach Lambda.
75
+ const awsBlocksResource = api.root.addResource(BLOCKS_NAMESPACE.slice(1));
76
+ awsBlocksResource.addProxy({ defaultIntegration: integration, anyMethod: true });
77
+ const apiResource = awsBlocksResource.addResource('api');
78
+ apiResource.addMethod('POST', integration);
79
+ apiResource.addMethod('OPTIONS', integration);
80
+ api.root.addProxy({ defaultIntegration: integration, anyMethod: true });
81
+ // ── Resource Groups ────────────────────────────────────────────────────
82
+ let rootStack = cdk.Stack.of(scope);
83
+ while (rootStack.nestedStackParent)
84
+ rootStack = rootStack.nestedStackParent;
85
+ const groupPrefix = (id && id !== rootStack.stackName) ? `${rootStack.stackName}-${id}` : rootStack.stackName;
86
+ new CfnGroup(scope, 'StackResources', {
87
+ name: `${groupPrefix}-resources`,
88
+ resourceQuery: {
89
+ type: 'CLOUDFORMATION_STACK_1_0',
90
+ query: {
91
+ resourceTypeFilters: [
92
+ 'AWS::CloudWatch::Dashboard',
93
+ 'AWS::Cognito::UserPool',
94
+ 'AWS::DynamoDB::Table',
95
+ 'AWS::Logs::LogGroup',
96
+ 'AWS::RDS::DBCluster',
97
+ 'AWS::RDS::DBInstance',
98
+ 'AWS::S3::Bucket',
99
+ 'AWS::SQS::Queue',
100
+ ],
101
+ stackIdentifier: cdk.Stack.of(scope).stackId,
102
+ },
103
+ },
104
+ });
105
+ new CfnGroup(scope, 'StackSettings', {
106
+ name: `${groupPrefix}-settings`,
107
+ resourceQuery: {
108
+ type: 'TAG_FILTERS_1_0',
109
+ query: {
110
+ resourceTypeFilters: ['AWS::SSM::Parameter'],
111
+ tagFilters: [{ key: 'aws-blocks-stack', values: [rootStack.stackName] }],
112
+ },
113
+ },
114
+ });
115
+ // ── Console redirect routes ────────────────────────────────────────────
116
+ const region = cdk.Fn.ref('AWS::Region');
117
+ const resourcesUrl = cdk.Fn.join('', [
118
+ 'https://', region, '.console.aws.amazon.com/resource-groups/group/',
119
+ `${groupPrefix}-resources`, '?region=', region,
120
+ ]);
121
+ const settingsUrl = cdk.Fn.join('', [
122
+ 'https://', region, '.console.aws.amazon.com/resource-groups/group/',
123
+ `${groupPrefix}-settings`, '?region=', region,
124
+ ]);
125
+ registerConfig(scope, 'BB_RESOURCES_GROUP_URL', resourcesUrl);
126
+ registerConfig(scope, 'BB_SETTINGS_GROUP_URL', settingsUrl);
127
+ registerBuiltinRoutes();
128
+ return { handler, gateway: api, apiUrl: `${api.url}${BLOCKS_RPC_PREFIX.slice(1)}` };
129
+ }
130
+ /**
131
+ * Standalone CDK construct that provisions the Blocks backend: a single Lambda
132
+ * function fronted by API Gateway with RPC + catch-all proxy routing.
133
+ *
134
+ * Use this to embed a Blocks backend into any existing CDK stack. Building Blocks
135
+ * instantiated during the `backendCDKPath` import will automatically attach to
136
+ * this construct's Lambda handler.
137
+ *
138
+ * @example Drop into an existing stack
139
+ * ```ts
140
+ * const blocks = await BlocksBackend.create(myStack, 'Blocks', {
141
+ * backendHandlerPath: join(__dirname, 'handler.ts'),
142
+ * backendCDKPath: join(__dirname, 'infra.ts'),
143
+ * });
144
+ * // blocks.apiUrl, blocks.handler, blocks.gateway available
145
+ * ```
146
+ */
147
+ export class BlocksBackend extends Construct {
148
+ apiUrl;
149
+ gateway;
150
+ handler;
151
+ backendHandlerPath;
152
+ /**
153
+ * The fullId used by child Scopes to compute their env var names,
154
+ * construct IDs, and physical resource names (e.g., DynamoDB table names).
155
+ *
156
+ * Includes the CDK stack name to ensure physical resources are unique
157
+ * per deployment. This matches what the runtime sees via BLOCKS_STACK_NAME.
158
+ *
159
+ * IMPORTANT: this value MUST be token-free. Child Scopes embed `fullId` in
160
+ * CDK construct IDs (e.g. `${fullId}DsqlMigrationFn`), and CDK forbids
161
+ * unresolved tokens in construct IDs ("ID components may not include
162
+ * unresolved tokens"). It is also used to build env-var keys that must match
163
+ * byte-for-byte between synth time and runtime.
164
+ *
165
+ * A nested stack (e.g. Amplify Gen2 `backend.createStack('blocks')`) has a
166
+ * tokenized `stackName` that only resolves at deploy time. We therefore walk
167
+ * up to the top-level stack, whose name is concrete at synth time and still
168
+ * unique per deployment. The `Token.isUnresolved` guard is a defensive
169
+ * fallback to the (token-free) construct id should no resolvable name exist.
170
+ */
171
+ get fullId() {
172
+ let stack = cdk.Stack.of(this);
173
+ while (stack.nestedStackParent) {
174
+ stack = stack.nestedStackParent;
175
+ }
176
+ const stackName = stack.stackName;
177
+ if (cdk.Token.isUnresolved(stackName)) {
178
+ return this.node.id;
179
+ }
180
+ return `${stackName}-${this.node.id}`;
181
+ }
182
+ constructor(scope, id, props) {
183
+ super(scope, id);
184
+ this.backendHandlerPath = props.backendHandlerPath;
185
+ // Expose self to Building Blocks at CDK time
186
+ globalThis.CURRENT_BLOCKS_STACK = this;
187
+ const infra = setupBlocksInfra(this, props, id);
188
+ this.handler = infra.handler;
189
+ this.gateway = infra.gateway;
190
+ this.apiUrl = infra.apiUrl;
191
+ // Override BLOCKS_STACK_NAME to include the parent stack name so runtime
192
+ // resource lookups (DynamoDB table names) match the CDK-time fullId
193
+ // and are unique per deployment.
194
+ this.handler.addEnvironment('BLOCKS_STACK_NAME', this.fullId);
195
+ }
196
+ static async create(scope, id, props) {
197
+ assertCdkConditionActive();
198
+ const backend = new BlocksBackend(scope, id, props);
199
+ // ESM caches modules by URL — append a unique query string so each stage re-executes the module body
200
+ const mod = await import(`${props.backendCDKPath}?stack=${id}`);
201
+ if (typeof mod.default === 'function') {
202
+ try {
203
+ await mod.default(backend);
204
+ }
205
+ catch (error) {
206
+ throw new Error(`Error executing default export function for backend "${id}": ${error instanceof Error ? error.message : error}`, { cause: error });
207
+ }
208
+ }
209
+ addBlocksStackMetadata(cdk.Stack.of(backend));
210
+ // Finalize BB config → S3 (after all BBs have registered their config)
211
+ finalizeConfigRegistry(backend, backend.handler);
212
+ return backend;
213
+ }
214
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=blocks-backend.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks-backend.test.d.ts","sourceRoot":"","sources":["../../src/cdk/blocks-backend.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,151 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { test, describe, before } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { dirname, join } from 'node:path';
7
+ import * as cdk from 'aws-cdk-lib';
8
+ import { Template } from 'aws-cdk-lib/assertions';
9
+ import { BlocksBackend } from './blocks-backend.js';
10
+ // Simulate the CDK condition being active (tests import CDK files directly)
11
+ before(() => {
12
+ process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS ?? '') + ' --conditions=cdk';
13
+ });
14
+ const __dirname = dirname(fileURLToPath(import.meta.url));
15
+ const handlerPath = join(__dirname, '__fixtures__', 'handler.js');
16
+ const sideEffectBackendPath = join(__dirname, '__fixtures__', 'side-effect-backend.js');
17
+ const factoryBackendPath = join(__dirname, '__fixtures__', 'factory-backend.js');
18
+ const fullIdConstructBackendPath = join(__dirname, '__fixtures__', 'fullid-construct-backend.js');
19
+ describe('ESM cache-busting (multi-stage)', () => {
20
+ test('BlocksBackend.create() with same backendCDKPath but different IDs produces constructs in each', async () => {
21
+ const app = new cdk.App();
22
+ const stack = new cdk.Stack(app, 'TestStack');
23
+ const backend1 = await BlocksBackend.create(stack, 'Stage1', {
24
+ backendHandlerPath: handlerPath,
25
+ backendCDKPath: sideEffectBackendPath,
26
+ });
27
+ const backend2 = await BlocksBackend.create(stack, 'Stage2', {
28
+ backendHandlerPath: handlerPath,
29
+ backendCDKPath: sideEffectBackendPath,
30
+ });
31
+ const findMarker = (scope) => scope.node.tryFindChild('SideEffectMarker');
32
+ assert.ok(findMarker(backend1), 'Stage1 backend should have SideEffectMarker construct from module side effect');
33
+ assert.ok(findMarker(backend2), 'Stage2 backend should have SideEffectMarker construct from re-executed module');
34
+ });
35
+ });
36
+ describe('synth shape (drop into existing stack)', () => {
37
+ test('BlocksBackend lives inside the parent stack and synthesizes Lambda + API Gateway', async () => {
38
+ const app = new cdk.App();
39
+ const parent = new cdk.Stack(app, 'MyExistingStack');
40
+ const backend = await BlocksBackend.create(parent, 'Blocks', {
41
+ backendHandlerPath: handlerPath,
42
+ backendCDKPath: sideEffectBackendPath,
43
+ });
44
+ // Public surface mirrors BlocksStack.
45
+ assert.ok(backend.handler, 'BlocksBackend should expose .handler');
46
+ assert.ok(backend.gateway, 'BlocksBackend should expose .gateway');
47
+ assert.ok(backend.apiUrl, 'BlocksBackend should expose .apiUrl');
48
+ // Synth produces the expected resources inside the parent stack —
49
+ // no separate stack is created.
50
+ const template = Template.fromStack(parent);
51
+ template.hasResourceProperties('AWS::Lambda::Function', {});
52
+ template.resourceCountIs('AWS::ApiGateway::RestApi', 1);
53
+ });
54
+ test('multiple BlocksBackends in the same parent stack do not collide', async () => {
55
+ const app = new cdk.App();
56
+ const parent = new cdk.Stack(app, 'MultiBackendStack');
57
+ await BlocksBackend.create(parent, 'BackendA', {
58
+ backendHandlerPath: handlerPath,
59
+ backendCDKPath: sideEffectBackendPath,
60
+ });
61
+ await BlocksBackend.create(parent, 'BackendB', {
62
+ backendHandlerPath: handlerPath,
63
+ backendCDKPath: sideEffectBackendPath,
64
+ });
65
+ const template = Template.fromStack(parent);
66
+ template.resourceCountIs('AWS::ApiGateway::RestApi', 2);
67
+ });
68
+ });
69
+ describe('factory function support', () => {
70
+ test('BlocksBackend.create() calls default export function with the backend instance', async () => {
71
+ const app = new cdk.App();
72
+ const stack = new cdk.Stack(app, 'FactoryTestStack');
73
+ const backend = await BlocksBackend.create(stack, 'FactoryStage', {
74
+ backendHandlerPath: handlerPath,
75
+ backendCDKPath: factoryBackendPath,
76
+ });
77
+ const marker = backend.node.tryFindChild('FactoryMarker');
78
+ assert.ok(marker, 'Factory function should have created FactoryMarker on the backend');
79
+ });
80
+ });
81
+ describe('fullId is token-free (construct IDs / env-var keys)', () => {
82
+ test('top-level stack: fullId is {stackName}-{id} and resolvable', async () => {
83
+ const app = new cdk.App();
84
+ const stack = new cdk.Stack(app, 'TopLevelStack');
85
+ const backend = await BlocksBackend.create(stack, 'blocks', {
86
+ backendHandlerPath: handlerPath,
87
+ backendCDKPath: sideEffectBackendPath,
88
+ });
89
+ assert.strictEqual(backend.fullId, 'TopLevelStack-blocks');
90
+ assert.ok(!cdk.Token.isUnresolved(backend.fullId), 'fullId must not contain a token');
91
+ });
92
+ test('nested stack: fullId stays token-free (regression for #714 / Amplify Gen2)', async () => {
93
+ // Amplify Gen2 wires Blocks into a NestedStack via backend.createStack('blocks').
94
+ // A NestedStack has a tokenized stackName that only resolves at deploy time —
95
+ // embedding it in fullId broke construct IDs with
96
+ // "ID components may not include unresolved tokens".
97
+ const app = new cdk.App();
98
+ const parent = new cdk.Stack(app, 'ParentStack');
99
+ const nested = new cdk.NestedStack(parent, 'blocks');
100
+ // Sanity: the nested stack's own name really is a token.
101
+ assert.ok(cdk.Token.isUnresolved(nested.stackName), 'precondition: NestedStack.stackName should be an unresolved token');
102
+ const backend = await BlocksBackend.create(nested, 'blocks', {
103
+ backendHandlerPath: handlerPath,
104
+ backendCDKPath: sideEffectBackendPath,
105
+ });
106
+ assert.ok(!cdk.Token.isUnresolved(backend.fullId), `fullId must be token-free inside a nested stack, got: ${backend.fullId}`);
107
+ // Falls back to the top-level (concrete) stack name, keeping uniqueness.
108
+ assert.strictEqual(backend.fullId, 'ParentStack-blocks');
109
+ });
110
+ test('child Scope can use fullId as a construct ID inside a nested stack', async () => {
111
+ // The fixture mirrors bb-distributed-data: it builds a construct whose ID is
112
+ // `${this.fullId}Marker`. If fullId carried a token, synth would throw.
113
+ const app = new cdk.App();
114
+ const parent = new cdk.Stack(app, 'Gen2ParentStack');
115
+ const nested = new cdk.NestedStack(parent, 'blocks');
116
+ const backend = await BlocksBackend.create(nested, 'blocks', {
117
+ backendHandlerPath: handlerPath,
118
+ backendCDKPath: fullIdConstructBackendPath,
119
+ });
120
+ // The construct ID is `${scope.fullId}Marker` → `ParentStack-blocks-blocks-dbMarker`.
121
+ const expectedId = `${backend.fullId}-dbMarker`;
122
+ assert.ok(nested.node.tryFindChild(expectedId), `expected a child construct with id "${expectedId}"`);
123
+ // Full synth must not throw on unresolved-token-in-construct-id.
124
+ assert.doesNotThrow(() => app.synth());
125
+ });
126
+ test('BLOCKS_STACK_NAME env var equals fullId (CDK-time ↔ runtime invariant)', async () => {
127
+ // Physical resource names (DynamoDB tables, DSQL env-var keys, IAM ARNs) are
128
+ // derived from fullId on BOTH sides: at synth via BlocksBackend.fullId, and at
129
+ // runtime via the root parent `{ id: process.env.BLOCKS_STACK_NAME }`. They MUST
130
+ // be byte-for-byte identical, otherwise the runtime looks up names/grants that
131
+ // were never created. BlocksBackend keeps them in sync by writing fullId into the
132
+ // handler's BLOCKS_STACK_NAME env var — assert that contract holds and is token-free.
133
+ const app = new cdk.App();
134
+ const parent = new cdk.Stack(app, 'InvariantParent');
135
+ const nested = new cdk.NestedStack(parent, 'blocks');
136
+ const backend = await BlocksBackend.create(nested, 'blocks', {
137
+ backendHandlerPath: handlerPath,
138
+ backendCDKPath: sideEffectBackendPath,
139
+ });
140
+ const template = Template.fromStack(nested);
141
+ const fns = template.findResources('AWS::Lambda::Function');
142
+ const envValues = Object.values(fns)
143
+ .map((fn) => fn.Properties?.Environment?.Variables?.BLOCKS_STACK_NAME)
144
+ .filter((v) => typeof v === 'string');
145
+ assert.ok(envValues.length > 0, 'expected a Lambda with a BLOCKS_STACK_NAME env var');
146
+ for (const value of envValues) {
147
+ assert.strictEqual(value, backend.fullId, 'BLOCKS_STACK_NAME must equal BlocksBackend.fullId so runtime names match synth');
148
+ assert.ok(!cdk.Token.isUnresolved(value), `BLOCKS_STACK_NAME must be token-free, got: ${value}`);
149
+ }
150
+ });
151
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=blocks-stack.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocks-stack.test.d.ts","sourceRoot":"","sources":["../../src/cdk/blocks-stack.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,78 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { test, describe, before } from 'node:test';
4
+ import assert from 'node:assert';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { dirname, join } from 'node:path';
7
+ import * as cdk from 'aws-cdk-lib';
8
+ import { BlocksBackend } from './blocks-backend.js';
9
+ import { BlocksStack } from './index.js';
10
+ // Simulate the CDK condition being active (tests import CDK files directly)
11
+ before(() => {
12
+ process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS ?? '') + ' --conditions=cdk';
13
+ });
14
+ const __dirname = dirname(fileURLToPath(import.meta.url));
15
+ const handlerPath = join(__dirname, '__fixtures__', 'handler.js');
16
+ const sideEffectBackendPath = join(__dirname, '__fixtures__', 'side-effect-backend.js');
17
+ const factoryBackendPath = join(__dirname, '__fixtures__', 'factory-backend.js');
18
+ describe('ESM cache-busting (multi-stage)', () => {
19
+ test('BlocksStack.create() with same backendCDKPath but different IDs produces constructs in each', async () => {
20
+ const app = new cdk.App();
21
+ const stack1 = await BlocksStack.create(app, 'PipelineStage1', {
22
+ backendHandlerPath: handlerPath,
23
+ backendCDKPath: sideEffectBackendPath,
24
+ });
25
+ const stack2 = await BlocksStack.create(app, 'PipelineStage2', {
26
+ backendHandlerPath: handlerPath,
27
+ backendCDKPath: sideEffectBackendPath,
28
+ });
29
+ const findMarker = (scope) => scope.node.tryFindChild('SideEffectMarker');
30
+ assert.ok(findMarker(stack1), 'First stack should have SideEffectMarker from module side effect');
31
+ assert.ok(findMarker(stack2), 'Second stack should have SideEffectMarker from re-executed module (cache busted)');
32
+ });
33
+ });
34
+ describe('factory function support', () => {
35
+ test('BlocksStack.create() calls default export function with the stack instance', async () => {
36
+ const app = new cdk.App();
37
+ const stack = await BlocksStack.create(app, 'FactoryBlocksStack', {
38
+ backendHandlerPath: handlerPath,
39
+ backendCDKPath: factoryBackendPath,
40
+ });
41
+ const marker = stack.node.tryFindChild('FactoryMarker');
42
+ assert.ok(marker, 'Factory function should have created FactoryMarker on the stack');
43
+ });
44
+ });
45
+ describe('legacy side-effect mode (no default export)', () => {
46
+ test('module with only side effects still registers constructs via globalThis', async () => {
47
+ const app = new cdk.App();
48
+ const stack = new cdk.Stack(app, 'LegacyTestStack');
49
+ const backend = await BlocksBackend.create(stack, 'LegacyStage', {
50
+ backendHandlerPath: handlerPath,
51
+ backendCDKPath: sideEffectBackendPath,
52
+ });
53
+ const marker = backend.node.tryFindChild('SideEffectMarker');
54
+ assert.ok(marker, 'Side-effect-only module should register construct via globalThis.CURRENT_BLOCKS_STACK');
55
+ });
56
+ });
57
+ describe('assertCdkConditionActive', () => {
58
+ test('BlocksStack.create() throws when --conditions=cdk is missing', async () => {
59
+ const origNodeOptions = process.env.NODE_OPTIONS;
60
+ const origExecArgv = process.execArgv;
61
+ process.env.NODE_OPTIONS = '';
62
+ process.execArgv = [];
63
+ try {
64
+ const app = new cdk.App();
65
+ await assert.rejects(BlocksStack.create(app, 'MissingConditionStack', {
66
+ backendHandlerPath: handlerPath,
67
+ backendCDKPath: sideEffectBackendPath,
68
+ }), (err) => {
69
+ assert.ok(err.message.includes('Missing --conditions=cdk'), `Expected condition error, got: ${err.message}`);
70
+ return true;
71
+ });
72
+ }
73
+ finally {
74
+ process.env.NODE_OPTIONS = origNodeOptions;
75
+ process.execArgv = origExecArgv;
76
+ }
77
+ });
78
+ });
@@ -0,0 +1,26 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import type { Construct } from 'constructs';
3
+ /**
4
+ * Register a config entry for a Building Block. This replaces
5
+ * `handler.addEnvironment(key, value)` for BB resource mappings.
6
+ *
7
+ * The entry will be serialized into a JSON config file in S3, loaded
8
+ * by the Lambda at cold start. This avoids the 4KB env var limit.
9
+ *
10
+ * @param scope - The CDK construct (used to find the parent stack)
11
+ * @param key - The config key (same string the runtime will use to look it up)
12
+ * @param value - The config value (can be a CDK token that resolves at deploy time)
13
+ */
14
+ export declare function registerConfig(scope: Construct, key: string, value: unknown): void;
15
+ /**
16
+ * Finalize the config registry: create an S3 bucket, upload the config JSON,
17
+ * set env vars on the handler, and grant read access.
18
+ *
19
+ * Must be called after all BBs are constructed (i.e., after the backendCDKPath
20
+ * import completes in BlocksStack.create() / BlocksBackend.create()).
21
+ *
22
+ * @param scope - The CDK construct to create resources under
23
+ * @param handler - The Lambda function that needs to read the config
24
+ */
25
+ export declare function finalizeConfigRegistry(scope: Construct, handler: cdk.aws_lambda.IFunction): void;
26
+ //# sourceMappingURL=config-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-registry.d.ts","sourceRoot":"","sources":["../../src/cdk/config-registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAInC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAuB5C;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAIlF;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,SAAS,GAC/B,IAAI,CA6CN"}
@@ -0,0 +1,80 @@
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 * as s3 from 'aws-cdk-lib/aws-s3';
5
+ import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
6
+ import * as iam from 'aws-cdk-lib/aws-iam';
7
+ const REGISTRY_KEY = Symbol.for('BLOCKS_CONFIG_REGISTRY');
8
+ /**
9
+ * Get or create the config registry for a given stack.
10
+ * The registry collects BB config entries (env var key → CDK token value)
11
+ * and serializes them to an S3 JSON file at synth time.
12
+ */
13
+ function getRegistry(stack) {
14
+ let state = stack[REGISTRY_KEY];
15
+ if (!state) {
16
+ state = { entries: new Map(), finalized: false };
17
+ stack[REGISTRY_KEY] = state;
18
+ }
19
+ return state;
20
+ }
21
+ /**
22
+ * Register a config entry for a Building Block. This replaces
23
+ * `handler.addEnvironment(key, value)` for BB resource mappings.
24
+ *
25
+ * The entry will be serialized into a JSON config file in S3, loaded
26
+ * by the Lambda at cold start. This avoids the 4KB env var limit.
27
+ *
28
+ * @param scope - The CDK construct (used to find the parent stack)
29
+ * @param key - The config key (same string the runtime will use to look it up)
30
+ * @param value - The config value (can be a CDK token that resolves at deploy time)
31
+ */
32
+ export function registerConfig(scope, key, value) {
33
+ const stack = cdk.Stack.of(scope);
34
+ const registry = getRegistry(stack);
35
+ registry.entries.set(key, value);
36
+ }
37
+ /**
38
+ * Finalize the config registry: create an S3 bucket, upload the config JSON,
39
+ * set env vars on the handler, and grant read access.
40
+ *
41
+ * Must be called after all BBs are constructed (i.e., after the backendCDKPath
42
+ * import completes in BlocksStack.create() / BlocksBackend.create()).
43
+ *
44
+ * @param scope - The CDK construct to create resources under
45
+ * @param handler - The Lambda function that needs to read the config
46
+ */
47
+ export function finalizeConfigRegistry(scope, handler) {
48
+ const stack = cdk.Stack.of(scope);
49
+ const registry = getRegistry(stack);
50
+ if (registry.finalized)
51
+ return;
52
+ registry.finalized = true;
53
+ if (registry.entries.size === 0)
54
+ return;
55
+ const configBucket = new s3.Bucket(scope, 'BlocksConfigBucket', {
56
+ removalPolicy: cdk.RemovalPolicy.DESTROY,
57
+ autoDeleteObjects: true,
58
+ encryption: s3.BucketEncryption.S3_MANAGED,
59
+ blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
60
+ lifecycleRules: [
61
+ { noncurrentVersionExpiration: cdk.Duration.days(1) },
62
+ ],
63
+ });
64
+ const configKey = 'blocks-config.json';
65
+ const configObject = cdk.Lazy.any({
66
+ produce: () => Object.fromEntries(registry.entries),
67
+ });
68
+ const deployment = new s3deploy.BucketDeployment(scope, 'BlocksConfigDeployment', {
69
+ sources: [s3deploy.Source.jsonData(configKey, configObject)],
70
+ destinationBucket: configBucket,
71
+ prune: false,
72
+ });
73
+ handler.addEnvironment('BLOCKS_CONFIG_BUCKET', configBucket.bucketName);
74
+ handler.addEnvironment('BLOCKS_CONFIG_KEY', configKey);
75
+ // Scope IAM grant to the specific config key
76
+ handler.addToRolePolicy(new iam.PolicyStatement({
77
+ actions: ['s3:GetObject'],
78
+ resources: [`${configBucket.bucketArn}/${configKey}`],
79
+ }));
80
+ }
@@ -0,0 +1,35 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import { Construct } from 'constructs';
3
+ import { type BlocksStackProps, type BlocksStack as BaseBlocksStack, type ScopeParent, type ScopeOptions } from '../common/index.js';
4
+ export { BlocksBackend, type BlocksBackendProps } from './blocks-backend.js';
5
+ export { DEFAULT_NODE_RUNTIME } from './node-version.js';
6
+ export { SandboxDisableDeletionProtection } from './mixins.js';
7
+ export { registerConfig, finalizeConfigRegistry } from './config-registry.js';
8
+ export { synthGuard } from './synth-guard.js';
9
+ export type { ScopeOptions } from '../index.js';
10
+ export { ApiError, isBlocksError } from '../errors.js';
11
+ export declare class BlocksStack extends cdk.Stack implements BaseBlocksStack {
12
+ readonly id: string;
13
+ readonly apiUrl: string;
14
+ readonly gateway: cdk.aws_apigateway.RestApi;
15
+ readonly handler: cdk.aws_lambda_nodejs.NodejsFunction;
16
+ readonly backendHandlerPath: string;
17
+ private constructor();
18
+ static create(scope: Construct, id: string, props: BlocksStackProps): Promise<BlocksStack>;
19
+ }
20
+ export declare class Scope extends Construct {
21
+ readonly id: string;
22
+ readonly parent: ScopeParent;
23
+ readonly bbName?: string;
24
+ readonly bbVersion?: string;
25
+ constructor(id: string, options?: ScopeOptions);
26
+ get handler(): cdk.aws_lambda_nodejs.NodejsFunction;
27
+ get fullId(): string;
28
+ protected buildUserAgentChain(): [string, string][];
29
+ registerClientMiddleware(_packageSpecifier: string): void;
30
+ registerDevAttachment(_packageSpecifier: string): void;
31
+ registerLambdaEventHandler(_eventSource: string, _identifier: string, _handler: (record: any) => Promise<void>): void;
32
+ get clientMiddleware(): readonly string[];
33
+ get devAttachments(): readonly string[];
34
+ }
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cdk/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,WAAW,IAAI,eAAe,EACnC,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEvD,qBAAa,WAAY,SAAQ,GAAG,CAAC,KAAM,YAAW,eAAe;IACnE,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC;IACpD,SAAgB,OAAO,EAAE,GAAG,CAAC,iBAAiB,CAAC,cAAc,CAAC;IAC9D,SAAgB,kBAAkB,EAAE,MAAM,CAAC;IAE3C,OAAO;WAcM,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB;CA0B1E;AAED,qBAAa,KAAM,SAAQ,SAAS;IAClC,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,MAAM,EAAE,WAAW,CAAC;IAEpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEhB,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAO9C,IAAI,OAAO,yCAWV;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,SAAS,CAAC,mBAAmB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;IAKnD,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACzD,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;IACtD,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IACrH,IAAI,gBAAgB,IAAI,SAAS,MAAM,EAAE,CAAe;IACxD,IAAI,cAAc,IAAI,SAAS,MAAM,EAAE,CAAe;CACvD"}