@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,169 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Runtime config loader for Building Blocks.
6
+ *
7
+ * At deploy time, BB resource mappings (ARNs, URLs, paths) are stored in an
8
+ * S3 JSON file instead of Lambda environment variables (which have a 4KB limit).
9
+ * This module loads that config file once at cold start and caches it.
10
+ *
11
+ * Lookup order for each key:
12
+ * 1. `process.env[key]` — local dev where env vars are set directly
13
+ * 2. Cached S3 config — loaded once per cold start
14
+ *
15
+ * @module
16
+ */
17
+
18
+ let configCache: Record<string, string> | null = null;
19
+ let configLoadPromise: Promise<Record<string, string>> | null = null;
20
+
21
+ type S3Fetcher = (bucket: string, key: string) => Promise<string>;
22
+ let s3FetcherOverride: S3Fetcher | null = null;
23
+
24
+ async function defaultS3Fetcher(bucket: string, key: string): Promise<string> {
25
+ const { S3Client, GetObjectCommand } = await import('@aws-sdk/client-s3');
26
+ const client = new S3Client({
27
+ region: process.env.AWS_REGION,
28
+ requestHandler: { requestTimeout: 5000 },
29
+ maxAttempts: 3,
30
+ });
31
+ const response = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key }));
32
+ const body = await response.Body?.transformToString('utf-8');
33
+ if (!body) throw new Error('Empty config file');
34
+ return body;
35
+ }
36
+
37
+ /**
38
+ * Load the config JSON from S3. Fetches once and caches forever (Lambda lifetime).
39
+ * Skips S3 entirely if BLOCKS_CONFIG_BUCKET/BLOCKS_CONFIG_KEY are not set (local dev).
40
+ * Throws if the env vars ARE set but the S3 fetch fails.
41
+ */
42
+ async function loadConfigFromS3(): Promise<Record<string, string>> {
43
+ if (configCache) return configCache;
44
+
45
+ const bucket = process.env.BLOCKS_CONFIG_BUCKET;
46
+ const key = process.env.BLOCKS_CONFIG_KEY;
47
+
48
+ if (!bucket || !key) {
49
+ configCache = {};
50
+ return configCache;
51
+ }
52
+
53
+ const fetcher = s3FetcherOverride ?? defaultS3Fetcher;
54
+
55
+ try {
56
+ const body = await fetcher(bucket, key);
57
+ configCache = JSON.parse(body);
58
+ } catch (error: any) {
59
+ const isNotFound = error?.name === 'NoSuchKey'
60
+ || error?.Code === 'NoSuchKey'
61
+ || error?.$metadata?.httpStatusCode === 404;
62
+ if (isNotFound) {
63
+ console.warn(`[Blocks] Config file not found in S3 (${bucket}/${key}), proceeding with empty config`);
64
+ configCache = {};
65
+ return configCache;
66
+ }
67
+ const msg = error instanceof Error ? error.message : String(error);
68
+ throw new Error(`[Blocks] Failed to load config from S3 (${bucket}/${key}): ${msg}`);
69
+ }
70
+
71
+ if (typeof configCache !== 'object' || configCache === null || Array.isArray(configCache)) {
72
+ throw new Error('[Blocks] Config file must be a JSON object');
73
+ }
74
+
75
+ console.log(`[Blocks] Config loaded: ${Object.keys(configCache).length} keys`);
76
+ return configCache!;
77
+ }
78
+
79
+ /**
80
+ * Ensure only one S3 fetch is in flight at a time.
81
+ * Multiple BB constructors calling getConfig() concurrently will share the same promise.
82
+ */
83
+ function ensureConfigLoaded(): Promise<Record<string, string>> {
84
+ if (configCache) return Promise.resolve(configCache);
85
+ if (!configLoadPromise) {
86
+ configLoadPromise = loadConfigFromS3().finally(() => {
87
+ configLoadPromise = null;
88
+ });
89
+ }
90
+ return configLoadPromise;
91
+ }
92
+
93
+ /**
94
+ * Get a config value by key.
95
+ *
96
+ * Checks `process.env[key]` first (local dev where env vars are set directly).
97
+ * If not found, reads from the cached S3 config file.
98
+ *
99
+ * @param key - The config key (e.g., `BLOCKS_AUTH_COGNITO_MYAPP_AUTHC_USER_POOL_ID`)
100
+ * @returns The config value, or empty string if not found anywhere
101
+ */
102
+ export async function getConfig(key: string): Promise<string> {
103
+ const envValue = process.env[key];
104
+ if (envValue !== undefined) return envValue;
105
+
106
+ const config = await ensureConfigLoaded();
107
+ return config[key] ?? '';
108
+ }
109
+
110
+ /**
111
+ * Synchronous config access — returns the value if already cached, otherwise
112
+ * returns the process.env fallback. Use this only when you're certain the
113
+ * config has already been loaded (e.g., after an initial await getConfig() call).
114
+ *
115
+ * @param key - The config key
116
+ * @returns The config value, or empty string if not found
117
+ */
118
+ export function getConfigSync(key: string): string {
119
+ const envValue = process.env[key];
120
+ if (envValue !== undefined) return envValue;
121
+
122
+ if (configCache) return configCache[key] ?? '';
123
+
124
+ return '';
125
+ }
126
+
127
+ /**
128
+ * Preload the S3 config. Call this early in Lambda cold start to ensure
129
+ * the config is cached before any BB constructors need it.
130
+ *
131
+ * This is a no-op if the config is already loaded or if S3 env vars aren't set.
132
+ */
133
+ export async function preloadConfig(): Promise<void> {
134
+ await ensureConfigLoaded();
135
+ }
136
+
137
+ /**
138
+ * Load S3 config and inject all values into `process.env`.
139
+ *
140
+ * This enables the lazy-init handler pattern: the handler loads config into
141
+ * process.env BEFORE importing the backend module, so BB constructors can
142
+ * read their config via `process.env[key]` as before — no BB code changes needed.
143
+ *
144
+ * Only sets env vars that aren't already set (won't override explicit env vars).
145
+ */
146
+ export async function loadConfigToProcessEnv(): Promise<void> {
147
+ const config = await ensureConfigLoaded();
148
+ for (const [key, value] of Object.entries(config)) {
149
+ if (process.env[key] === undefined) {
150
+ process.env[key] = value;
151
+ }
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Reset the config cache. **For testing only.**
157
+ */
158
+ export function _resetConfigCache(): void {
159
+ configCache = null;
160
+ configLoadPromise = null;
161
+ s3FetcherOverride = null;
162
+ }
163
+
164
+ /**
165
+ * Override the S3 fetcher function. **For testing only.**
166
+ */
167
+ export function _setS3Fetcher(fetcher: ((bucket: string, key: string) => Promise<string>) | null): void {
168
+ s3FetcherOverride = fetcher;
169
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Shared constants used across the Blocks framework.
6
+ *
7
+ * Centralizes magic strings so directory names and conventions
8
+ * can be updated in one place.
9
+ */
10
+
11
+ /** Directory where sandbox/deploy config is written (relative to project root). */
12
+ export const BLOCKS_SANDBOX_DIR = '.blocks-sandbox';
13
+
14
+ /** Default backend entry point directory name. */
15
+ export const BLOCKS_BACKEND_DIR = 'aws-blocks';
@@ -0,0 +1,15 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { timingSafeEqual } from 'node:crypto';
5
+
6
+ /**
7
+ * Compares two strings in constant time to prevent timing side-channel attacks.
8
+ * Use this for HMAC signature validation — never use === or !== for crypto comparisons.
9
+ */
10
+ export function constantTimeEquals(a: string, b: string): boolean {
11
+ const ab = Buffer.from(a, 'utf8');
12
+ const bb = Buffer.from(b, 'utf8');
13
+ if (ab.length !== bb.length) return false;
14
+ return timingSafeEqual(ab, bb);
15
+ }
@@ -0,0 +1,242 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { test, describe } from 'node:test';
5
+ import assert from 'node:assert';
6
+ import { Scope } from './index.js';
7
+ import type { ScopeParent } from './index.js';
8
+ import { CORE_VERSION } from '../version.js';
9
+
10
+ /**
11
+ * Test subclass that exposes the protected buildUserAgentChain method.
12
+ */
13
+ class TestBB extends Scope {
14
+ override readonly bbName?: string;
15
+ override readonly bbVersion?: string;
16
+
17
+ constructor(
18
+ id: string,
19
+ opts?: { parent?: ScopeParent; bbName?: string; bbVersion?: string },
20
+ ) {
21
+ super(id, { parent: opts?.parent });
22
+ this.bbName = opts?.bbName;
23
+ this.bbVersion = opts?.bbVersion;
24
+ }
25
+
26
+ /** Expose protected method for testing */
27
+ public testBuildUserAgentChain(): [string, string][] {
28
+ return this.buildUserAgentChain();
29
+ }
30
+ }
31
+
32
+ // ── buildUserAgentChain: standalone BB (no BB parent) ───────────────────────
33
+
34
+ describe('buildUserAgentChain', () => {
35
+ test('standalone BB returns [aws-blocks, bb] pair', () => {
36
+ const root = { id: 'my-app' };
37
+ const bb = new TestBB('store', {
38
+ parent: root,
39
+ bbName: 'KVStore',
40
+ bbVersion: '0.4.0',
41
+ });
42
+
43
+ const chain = bb.testBuildUserAgentChain();
44
+
45
+ assert.deepStrictEqual(chain, [
46
+ ['aws-blocks', CORE_VERSION],
47
+ ['bb', 'KVStore/0.4.0'],
48
+ ]);
49
+ });
50
+
51
+ // ── Nested BB (one level) ─────────────────────────────────────────────
52
+
53
+ test('BB nested inside another BB includes parent BB in chain', () => {
54
+ const root = { id: 'my-app' };
55
+ const parentBB = new TestBB('auth', {
56
+ parent: root,
57
+ bbName: 'AuthBasic',
58
+ bbVersion: '1.0.1',
59
+ });
60
+ const childBB = new TestBB('store', {
61
+ parent: parentBB,
62
+ bbName: 'KVStore',
63
+ bbVersion: '0.4.0',
64
+ });
65
+
66
+ const chain = childBB.testBuildUserAgentChain();
67
+
68
+ assert.deepStrictEqual(chain, [
69
+ ['aws-blocks', CORE_VERSION],
70
+ ['bb', 'AuthBasic/1.0.1'],
71
+ ['bb', 'KVStore/0.4.0'],
72
+ ]);
73
+ });
74
+
75
+ // ── Deeply nested BB (2+ levels) ──────────────────────────────────────
76
+
77
+ test('BB nested 2+ levels deep builds the full chain in root-to-leaf order', () => {
78
+ const root = { id: 'my-app' };
79
+ const grandparentBB = new TestBB('dashboard', {
80
+ parent: root,
81
+ bbName: 'Dashboard',
82
+ bbVersion: '2.0.0',
83
+ });
84
+ const parentBB = new TestBB('auth', {
85
+ parent: grandparentBB,
86
+ bbName: 'AuthBasic',
87
+ bbVersion: '1.0.1',
88
+ });
89
+ const childBB = new TestBB('store', {
90
+ parent: parentBB,
91
+ bbName: 'KVStore',
92
+ bbVersion: '0.4.0',
93
+ });
94
+
95
+ const chain = childBB.testBuildUserAgentChain();
96
+
97
+ assert.deepStrictEqual(chain, [
98
+ ['aws-blocks', CORE_VERSION],
99
+ ['bb', 'Dashboard/2.0.0'],
100
+ ['bb', 'AuthBasic/1.0.1'],
101
+ ['bb', 'KVStore/0.4.0'],
102
+ ]);
103
+ });
104
+
105
+ // ── Parent without BB metadata (non-BB scope in the chain) ────────────
106
+
107
+ test('parent scope without bbName/bbVersion is skipped in chain', () => {
108
+ const root = { id: 'my-app' };
109
+ // A plain Scope (not a BB) in between
110
+ const middleScope = new TestBB('middleware', {
111
+ parent: root,
112
+ // no bbName/bbVersion
113
+ });
114
+ const childBB = new TestBB('store', {
115
+ parent: middleScope,
116
+ bbName: 'KVStore',
117
+ bbVersion: '0.4.0',
118
+ });
119
+
120
+ const chain = childBB.testBuildUserAgentChain();
121
+
122
+ assert.deepStrictEqual(chain, [
123
+ ['aws-blocks', CORE_VERSION],
124
+ ['bb', 'KVStore/0.4.0'],
125
+ ]);
126
+ });
127
+
128
+ test('non-BB parent between two BBs is skipped', () => {
129
+ const root = { id: 'my-app' };
130
+ const parentBB = new TestBB('auth', {
131
+ parent: root,
132
+ bbName: 'AuthBasic',
133
+ bbVersion: '1.0.1',
134
+ });
135
+ // Plain scope between parent BB and child BB
136
+ const middleScope = new TestBB('internal', {
137
+ parent: parentBB,
138
+ // no bbName/bbVersion
139
+ });
140
+ const childBB = new TestBB('store', {
141
+ parent: middleScope,
142
+ bbName: 'KVStore',
143
+ bbVersion: '0.4.0',
144
+ });
145
+
146
+ const chain = childBB.testBuildUserAgentChain();
147
+
148
+ assert.deepStrictEqual(chain, [
149
+ ['aws-blocks', CORE_VERSION],
150
+ ['bb', 'AuthBasic/1.0.1'],
151
+ ['bb', 'KVStore/0.4.0'],
152
+ ]);
153
+ });
154
+
155
+ // ── Edge case: bbName set but bbVersion missing ───────────────────────
156
+
157
+ test('self not added to chain when bbVersion is missing', () => {
158
+ const root = { id: 'my-app' };
159
+ const bb = new TestBB('store', {
160
+ parent: root,
161
+ bbName: 'KVStore',
162
+ // bbVersion missing
163
+ });
164
+
165
+ const chain = bb.testBuildUserAgentChain();
166
+
167
+ assert.deepStrictEqual(chain, [
168
+ ['aws-blocks', CORE_VERSION],
169
+ ]);
170
+ });
171
+
172
+ // ── Edge case: bbVersion set but bbName missing ───────────────────────
173
+
174
+ test('self not added to chain when bbName is missing', () => {
175
+ const root = { id: 'my-app' };
176
+ const bb = new TestBB('store', {
177
+ parent: root,
178
+ // bbName missing
179
+ bbVersion: '0.4.0',
180
+ });
181
+
182
+ const chain = bb.testBuildUserAgentChain();
183
+
184
+ assert.deepStrictEqual(chain, [
185
+ ['aws-blocks', CORE_VERSION],
186
+ ]);
187
+ });
188
+
189
+ // ── Edge case: neither bbName nor bbVersion set ───────────────────────
190
+
191
+ test('self not added to chain when neither bbName nor bbVersion is set', () => {
192
+ const root = { id: 'my-app' };
193
+ const bb = new TestBB('store', {
194
+ parent: root,
195
+ });
196
+
197
+ const chain = bb.testBuildUserAgentChain();
198
+
199
+ assert.deepStrictEqual(chain, [
200
+ ['aws-blocks', CORE_VERSION],
201
+ ]);
202
+ });
203
+
204
+ // ── Edge case: parent with only bbName (no bbVersion) is skipped ──────
205
+
206
+ test('parent with bbName but no bbVersion is skipped', () => {
207
+ const root = { id: 'my-app' };
208
+ const parentPartial = new TestBB('partial', {
209
+ parent: root,
210
+ bbName: 'PartialBB',
211
+ // bbVersion missing
212
+ });
213
+ const childBB = new TestBB('store', {
214
+ parent: parentPartial,
215
+ bbName: 'KVStore',
216
+ bbVersion: '0.4.0',
217
+ });
218
+
219
+ const chain = childBB.testBuildUserAgentChain();
220
+
221
+ assert.deepStrictEqual(chain, [
222
+ ['aws-blocks', CORE_VERSION],
223
+ ['bb', 'KVStore/0.4.0'],
224
+ ]);
225
+ });
226
+
227
+ // ── Verifies CORE_VERSION is used as the aws-blocks version ───────────
228
+
229
+ test('CORE_VERSION is used as the aws-blocks version', () => {
230
+ const root = { id: 'my-app' };
231
+ const bb = new TestBB('store', {
232
+ parent: root,
233
+ bbName: 'KVStore',
234
+ bbVersion: '1.0.0',
235
+ });
236
+
237
+ const chain = bb.testBuildUserAgentChain();
238
+
239
+ assert.strictEqual(chain[0][0], 'aws-blocks');
240
+ assert.strictEqual(chain[0][1], CORE_VERSION);
241
+ });
242
+ });