@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,113 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Pre-deploy secret provisioning.
6
+ *
7
+ * Writes the connection string to an SSM SecureString parameter.
8
+ * Parameter name includes the stage to prevent sandbox/prod collision:
9
+ * /blocks/{stage}/db-connection-string
10
+ *
11
+ * On first deploy: creates the parameter.
12
+ * On subsequent deploys: updates if value changed, no-op otherwise.
13
+ */
14
+ import { existsSync, readFileSync } from 'node:fs';
15
+ import { dbConnectionParameterName } from '../db-naming.js';
16
+
17
+ const CONNECTION_STRING_PATTERN = /_(DB_URL|CONNECTION_STRING)$/;
18
+
19
+ export interface EnsureSecretsResult {
20
+ created: string[];
21
+ updated: string[];
22
+ unchanged: string[];
23
+ }
24
+
25
+ export function findConnectionString(): { name: string; value: string } | null {
26
+ for (const [name, value] of Object.entries(process.env)) {
27
+ if (CONNECTION_STRING_PATTERN.test(name) && value) {
28
+ return { name, value };
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+
34
+ /**
35
+ * Ensure the connection string is stored in SSM for the current stage.
36
+ */
37
+ export async function ensureSecrets(stage?: 'sandbox' | 'production'): Promise<EnsureSecretsResult> {
38
+ const result: EnsureSecretsResult = { created: [], updated: [], unchanged: [] };
39
+
40
+ const conn = findConnectionString();
41
+ if (!conn) return result;
42
+
43
+ const resolvedStage = stage ?? process.env.BLOCKS_STAGE ?? 'sandbox';
44
+
45
+ const { SSMClient, GetParameterCommand, PutParameterCommand } =
46
+ await import('@aws-sdk/client-ssm');
47
+
48
+ const client = new SSMClient();
49
+ const parameterName = dbConnectionParameterName(resolvedStage);
50
+
51
+ let isNew = false;
52
+ try {
53
+ const current = await client.send(new GetParameterCommand({
54
+ Name: parameterName,
55
+ WithDecryption: true,
56
+ }));
57
+ if (current.Parameter?.Value === conn.value) {
58
+ result.unchanged.push(parameterName);
59
+ return result;
60
+ }
61
+ } catch (e: any) {
62
+ if (e.name !== 'ParameterNotFound') throw e;
63
+ isNew = true;
64
+ }
65
+
66
+ await client.send(new PutParameterCommand({
67
+ Name: parameterName,
68
+ Value: conn.value,
69
+ Type: 'SecureString',
70
+ Overwrite: true,
71
+ }));
72
+ (isNew ? result.created : result.updated).push(parameterName);
73
+
74
+ return result;
75
+ }
76
+
77
+ /**
78
+ * Load environment for production deployment.
79
+ *
80
+ * Loads `.env.production` into `process.env` when present, then returns.
81
+ * If the file is absent this is a no-op — a missing `.env.production` is
82
+ * valid for templates that need no production-only configuration (e.g. the
83
+ * default DynamoDB template, Next.js, auth-cognito).
84
+ *
85
+ * Note: this function intentionally does NOT require any specific connection
86
+ * string. A Building Block that connects to an external database (e.g. via
87
+ * `fromExisting()`) is responsible for asserting its own configuration during
88
+ * synth/deploy, where the requirement can be checked against the construct
89
+ * tree rather than guessed at by the generic deploy script.
90
+ */
91
+ export function loadProductionEnv(): void {
92
+ if (existsSync('.env.production')) {
93
+ loadEnvFile('.env.production');
94
+ }
95
+ }
96
+
97
+ /** Load a .env file into process.env. Uses Node 21.7+ API with fallback. */
98
+ export function loadEnvFile(filePath: string): void {
99
+ if (typeof process.loadEnvFile === 'function') {
100
+ process.loadEnvFile(filePath);
101
+ } else {
102
+ const content = readFileSync(filePath, 'utf-8');
103
+ for (const line of content.split('\n')) {
104
+ const trimmed = line.trim();
105
+ if (!trimmed || trimmed.startsWith('#')) continue;
106
+ const eqIdx = trimmed.indexOf('=');
107
+ if (eqIdx === -1) continue;
108
+ const key = trimmed.slice(0, eqIdx).trim();
109
+ const value = trimmed.slice(eqIdx + 1).trim();
110
+ if (!process.env[key]) process.env[key] = value;
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,64 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { test } from 'node:test';
5
+ import assert from 'node:assert';
6
+ import {
7
+ parseProductionRefsFromEnvContent,
8
+ isProductionTarget,
9
+ buildMigrateArgs,
10
+ shouldGuardAgainstProduction,
11
+ } from './external-migrations-step.js';
12
+
13
+ const SUPA = (ref: string) =>
14
+ `postgresql://postgres.${ref}:pw@aws-0-us-east-1.pooler.supabase.com:6543/postgres`;
15
+
16
+ test('parseProductionRefsFromEnvContent extracts DB identity from connection-string vars', () => {
17
+ const content = [
18
+ '# production config',
19
+ `SUPABASE_DB_URL=${SUPA('prodref1')}`,
20
+ 'OTHER=not-a-db',
21
+ `MY_CONNECTION_STRING=${SUPA('prodref2')}`,
22
+ ].join('\n');
23
+ assert.deepStrictEqual(parseProductionRefsFromEnvContent(content).sort(), ['prodref1', 'prodref2']);
24
+ });
25
+
26
+ test('parseProductionRefsFromEnvContent ignores comments, blanks, and non-DB keys', () => {
27
+ assert.deepStrictEqual(parseProductionRefsFromEnvContent('\n# c\nFOO=bar\n'), []);
28
+ });
29
+
30
+ test('isProductionTarget refuses when the dev ref matches a production ref', () => {
31
+ const prod = new Set(['prodref1', 'prodref2']);
32
+ assert.strictEqual(isProductionTarget('prodref1', prod), true);
33
+ });
34
+
35
+ test('isProductionTarget allows a distinct dev database', () => {
36
+ const prod = new Set(['prodref1']);
37
+ assert.strictEqual(isProductionTarget('devref', prod), false);
38
+ });
39
+
40
+ test('isProductionTarget is safe when the dev ref is unknown (null)', () => {
41
+ assert.strictEqual(isProductionTarget(null, new Set(['prodref1'])), false);
42
+ });
43
+
44
+ test('buildMigrateArgs (deploy/sandbox) is schema-only — no --regenerate-types', () => {
45
+ const args = buildMigrateArgs('production', './migrations');
46
+ assert.deepStrictEqual(args, ['--no-install', 'bb-data', 'migrate', '--stage', 'production', './migrations']);
47
+ assert.ok(!args.some(a => a.startsWith('--regenerate-types')), 'deploy must never rewrite source');
48
+ });
49
+
50
+ test('buildMigrateArgs (dev) appends --regenerate-types=<dir> so apply also refreshes types', () => {
51
+ const args = buildMigrateArgs('sandbox', './migrations', './aws-blocks');
52
+ assert.deepStrictEqual(args, [
53
+ '--no-install', 'bb-data', 'migrate', '--stage', 'sandbox', './migrations',
54
+ '--regenerate-types=./aws-blocks',
55
+ ]);
56
+ });
57
+
58
+ test('shouldGuardAgainstProduction: sandbox is guarded (shares .env.local with dev)', () => {
59
+ assert.strictEqual(shouldGuardAgainstProduction('sandbox'), true);
60
+ });
61
+
62
+ test('shouldGuardAgainstProduction: production deploy is intentionally NOT guarded', () => {
63
+ assert.strictEqual(shouldGuardAgainstProduction('production'), false);
64
+ });
@@ -0,0 +1,269 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Apply external-database migrations during the app lifecycle:
6
+ * `npm run dev` (to the dev database), and `npm run sandbox` / `npm run deploy`
7
+ * (to the sandbox / production database, before `cdk deploy`).
8
+ *
9
+ * `core` must not depend on `bb-data` (the dependency runs the other way), so
10
+ * this invokes the `bb-data` CLI as a subprocess — the same pattern the deploy
11
+ * script already uses for client generation. The CLI's migrate path rewrites to
12
+ * the 5432 session port, takes an advisory lock, and applies pending migrations
13
+ * idempotently. The connection string is passed to the child via an environment
14
+ * variable (not argv) so it isn't exposed in the process list.
15
+ *
16
+ * Applying a migration makes the schema change live in the database. In the dev
17
+ * loop (`npm run dev`) the same `bb-data migrate` subprocess also refreshes the
18
+ * generated types (`--regenerate-types`); sandbox/production deploys apply the
19
+ * committed schema only and never rewrite source.
20
+ *
21
+ * No-op unless BOTH a connection string is resolvable from the environment
22
+ * (i.e. the app uses an external/fromExisting DB) AND a `./migrations` directory
23
+ * exists. Aurora-managed databases run migrations via their in-VPC Lambda, not
24
+ * here.
25
+ */
26
+
27
+ import { execFileSync } from 'node:child_process';
28
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
29
+ import { findConnectionString } from './ensure-secrets.js';
30
+ import { extractDbRef, dbConnectionParameterName } from '../db-naming.js';
31
+
32
+ const DEFAULT_MIGRATIONS_DIR = './migrations';
33
+ /** Default output dir for db-pull generated files (database.types.ts / database.meta.ts). */
34
+ const DEFAULT_GENERATED_DIR = './aws-blocks';
35
+
36
+ /**
37
+ * Invoke `bb-data migrate` for a stage. The connection string is passed via the
38
+ * BLOCKS_MIGRATE_URL env var rather than argv, so the credential is not visible
39
+ * in the process list. Arg-array exec (no shell). `--no-install` keeps npx from
40
+ * reaching the public registry for the private bin (already an app dependency).
41
+ */
42
+ /**
43
+ * Build the argv for the `bb-data migrate` subprocess. Extracted as a pure
44
+ * function so the dev-vs-deploy difference is unit-testable. When
45
+ * `regenerateTypesDir` is set (dev loop only), append `--regenerate-types=<dir>`
46
+ * so a successful apply also refreshes generated types. Sandbox/production
47
+ * deploys omit it — they apply the committed schema and must never rewrite
48
+ * source files on a CI/deploy host.
49
+ */
50
+ export function buildMigrateArgs(stage: string, migrationsDir: string, regenerateTypesDir?: string): string[] {
51
+ const args = ['--no-install', 'bb-data', 'migrate', '--stage', stage, migrationsDir];
52
+ if (regenerateTypesDir) args.push(`--regenerate-types=${regenerateTypesDir}`);
53
+ return args;
54
+ }
55
+
56
+ function runMigrateSubprocess(
57
+ connValue: string,
58
+ stage: string,
59
+ migrationsDir: string,
60
+ regenerateTypesDir?: string,
61
+ ): void {
62
+ execFileSync('npx', buildMigrateArgs(stage, migrationsDir, regenerateTypesDir), {
63
+ stdio: 'inherit',
64
+ env: { ...process.env, BLOCKS_MIGRATE_URL: connValue },
65
+ });
66
+ }
67
+
68
+ export interface ApplyExternalMigrationsOptions {
69
+ stage: 'sandbox' | 'production';
70
+ /** Override the migrations directory (default ./migrations). */
71
+ migrationsDir?: string;
72
+ }
73
+
74
+ /**
75
+ * Which apply stages get the production guard. **Security-relevant:** `sandbox`
76
+ * resolves its connection from the same `.env.local` as the dev loop, so it must
77
+ * be guarded against accidentally pointing at production. `production` deploys
78
+ * intentionally target the production database and must NOT be guarded. Keep this
79
+ * as the single source of truth for the decision.
80
+ */
81
+ export function shouldGuardAgainstProduction(stage: 'sandbox' | 'production'): boolean {
82
+ return stage === 'sandbox';
83
+ }
84
+
85
+ /**
86
+ * Apply pending external-DB migrations for the given stage. Returns true if a
87
+ * migration step ran, false if it was skipped (no external DB / no migrations).
88
+ *
89
+ * For `stage: 'sandbox'` it refuses if the resolved connection (`.env.local`)
90
+ * points at a production database — the same guard as the dev loop. `stage:
91
+ * 'production'` is intentionally unguarded (deploy is meant to target prod).
92
+ */
93
+ export async function applyExternalMigrations(opts: ApplyExternalMigrationsOptions): Promise<boolean> {
94
+ const migrationsDir = opts.migrationsDir ?? DEFAULT_MIGRATIONS_DIR;
95
+
96
+ const conn = findConnectionString();
97
+ if (!conn) return false; // not an external-DB app
98
+ if (!existsSync(migrationsDir)) return false; // nothing to apply
99
+ if (readdirSync(migrationsDir).filter(f => f.endsWith('.sql')).length === 0) return false;
100
+
101
+ // Sandbox uses the same `.env.local` as dev, so guard it the same way: never
102
+ // apply schema changes to a production database. Production deploys are
103
+ // intentionally NOT guarded — `npm run deploy` is meant to target production.
104
+ if (shouldGuardAgainstProduction(opts.stage)) {
105
+ await assertNotProductionTarget(conn.value, { command: 'npm run sandbox', announceFailOpen: true });
106
+ }
107
+
108
+ console.log(`🧬 Applying external database migrations (${opts.stage})...`);
109
+ runMigrateSubprocess(conn.value, opts.stage, migrationsDir);
110
+ return true;
111
+ }
112
+
113
+ /** Best-effort DB host for transparency logging. */
114
+ function hostOf(connectionString: string): string {
115
+ try {
116
+ return new URL(connectionString).host;
117
+ } catch {
118
+ return '(unparseable connection string)';
119
+ }
120
+ }
121
+
122
+ /** Best-effort DB identity ref; null if it can't be derived. */
123
+ function safeRef(connectionString: string): string | null {
124
+ try {
125
+ return extractDbRef(connectionString);
126
+ } catch {
127
+ return null;
128
+ }
129
+ }
130
+
131
+ /** Extract production DB identity refs from `.env`-style content (pure/testable). */
132
+ export function parseProductionRefsFromEnvContent(content: string): string[] {
133
+ const refs: string[] = [];
134
+ for (const line of content.split('\n')) {
135
+ const t = line.trim();
136
+ if (!t || t.startsWith('#')) continue;
137
+ const eq = t.indexOf('=');
138
+ if (eq === -1) continue;
139
+ const key = t.slice(0, eq).trim();
140
+ const val = t.slice(eq + 1).trim();
141
+ if (/_(DB_URL|CONNECTION_STRING)$/.test(key) && val) {
142
+ const r = safeRef(val);
143
+ if (r) refs.push(r);
144
+ }
145
+ }
146
+ return refs;
147
+ }
148
+
149
+ /** True when the dev database is one of the known production databases. */
150
+ export function isProductionTarget(devRef: string | null, prodRefs: Set<string>): boolean {
151
+ return devRef != null && prodRefs.has(devRef);
152
+ }
153
+
154
+ /**
155
+ * Collect database identities known to be **production**, to guard the dev loop
156
+ * from accidentally migrating production:
157
+ * - local `.env.production` (read directly, NOT loaded into the environment), and
158
+ * - the production SSM parameter for this ref (best-effort; skipped silently when
159
+ * offline or unauthenticated).
160
+ */
161
+ async function productionRefs(devRef: string): Promise<Set<string>> {
162
+ const refs = new Set<string>();
163
+
164
+ if (existsSync('.env.production')) {
165
+ for (const r of parseProductionRefsFromEnvContent(readFileSync('.env.production', 'utf-8'))) {
166
+ refs.add(r);
167
+ }
168
+ }
169
+
170
+ try {
171
+ const { SSMClient, GetParameterCommand } = await import('@aws-sdk/client-ssm');
172
+ const res = await new SSMClient().send(
173
+ new GetParameterCommand({ Name: dbConnectionParameterName('production'), WithDecryption: true }),
174
+ );
175
+ const v = res.Parameter?.Value;
176
+ const r = v ? safeRef(v) : null;
177
+ if (r) refs.add(r);
178
+ } catch {
179
+ /* best-effort: no creds / offline / parameter absent — skip */
180
+ }
181
+
182
+ return refs;
183
+ }
184
+
185
+ /**
186
+ * Refuse to run schema changes against a known production database. Compares the
187
+ * resolved connection's DB identity against the production refs (`.env.production`
188
+ * + the production SSM parameter). Throws with actionable guidance if they match;
189
+ * no-op when the ref can't be derived or no production ref is known. Shared by the
190
+ * dev loop and the sandbox apply (both resolve their connection from `.env.local`).
191
+ */
192
+ async function assertNotProductionTarget(
193
+ connValue: string,
194
+ opts: { command: string; optOutHint?: string; announceFailOpen?: boolean },
195
+ ): Promise<void> {
196
+ const ref = safeRef(connValue);
197
+ if (!ref) return;
198
+ const prodRefs = await productionRefs(ref);
199
+ if (prodRefs.size === 0) {
200
+ // Best-effort guard, failing OPEN: with no `.env.production` and no resolvable
201
+ // production SSM parameter, we cannot prove the target isn't production, so proceed.
202
+ // The dev loop stays quiet — "no production set up yet" is the normal local case and
203
+ // a note on every `npm run dev` would be false-alarm noise. The consequential,
204
+ // deploy-adjacent sandbox apply announces the blind spot instead (see DESIGN.md).
205
+ if (opts.announceFailOpen) {
206
+ console.log(
207
+ `ℹ️ Could not verify the target database isn't production (.env.production absent ` +
208
+ `and the production SSM parameter was unavailable) — proceeding with \`${opts.command}\`.`,
209
+ );
210
+ }
211
+ return;
212
+ }
213
+ if (!isProductionTarget(ref, prodRefs)) return;
214
+
215
+ const optOut = opts.optOutHint ? `, or ${opts.optOutHint}` : '';
216
+ throw new Error(
217
+ `Refusing to apply migrations: .env.local points at your PRODUCTION database (${hostOf(connValue)}).\n` +
218
+ `\`${opts.command}\` must not run schema changes against production. Point .env.local at a ` +
219
+ `dev/branch database${optOut}.`,
220
+ );
221
+ }
222
+
223
+ /**
224
+ * Apply pending external-database migrations during `npm run dev`, against the
225
+ * dev database, so the schema change is live locally without a sandbox round-trip.
226
+ * (A successful apply also refreshes the generated TypeScript types from the new
227
+ * schema — `database.types.ts` + `database.meta.ts` — so code type-checks against
228
+ * it locally before deploy. To refresh by hand at any time, run `npx bb-data pull`.)
229
+ *
230
+ * Only acts for external (`fromExisting`) apps — the managed/Aurora path uses a
231
+ * local PGlite mock in dev and is unaffected. Guards against accidentally
232
+ * migrating a production database: if `.env.local` resolves to the same database
233
+ * as production (`.env.production` and/or the production SSM parameter), it
234
+ * refuses. Reachability/apply failures warn and let dev continue; only the
235
+ * production-target refusal is fatal. Set `BLOCKS_SKIP_DEV_MIGRATIONS=1` to skip.
236
+ *
237
+ * Returns true if a migration step ran, false if skipped.
238
+ */
239
+ export async function applyDevMigrations(opts?: { migrationsDir?: string; generatedDir?: string }): Promise<boolean> {
240
+ if (process.env.BLOCKS_SKIP_DEV_MIGRATIONS) return false;
241
+
242
+ const migrationsDir = opts?.migrationsDir ?? DEFAULT_MIGRATIONS_DIR;
243
+ const generatedDir = opts?.generatedDir ?? DEFAULT_GENERATED_DIR;
244
+ const conn = findConnectionString();
245
+ if (!conn) return false; // not an external-DB app (e.g. managed Aurora → local PGlite mock)
246
+ if (!existsSync(migrationsDir)) return false;
247
+ if (readdirSync(migrationsDir).filter(f => f.endsWith('.sql')).length === 0) return false;
248
+
249
+ // Guardrail: never auto-apply to a production database from the dev loop.
250
+ await assertNotProductionTarget(conn.value, {
251
+ command: 'npm run dev',
252
+ optOutHint: 'set BLOCKS_SKIP_DEV_MIGRATIONS=1 to opt out',
253
+ });
254
+
255
+ console.log(`🧬 Applying migrations to your dev database (${hostOf(conn.value)})...`);
256
+ try {
257
+ // Dev loop: apply, then refresh generated types from the migrated schema in
258
+ // the SAME subprocess (one developer-visible step). Deploy/sandbox omit the
259
+ // regenerate-types arg — they apply the committed schema, never rewrite source.
260
+ runMigrateSubprocess(conn.value, 'dev', migrationsDir, generatedDir);
261
+ return true;
262
+ } catch (e: any) {
263
+ // Don't block local dev on a migration apply failure (e.g. port 5432 blocked
264
+ // on a corp network). Warn and continue — the app may still run.
265
+ console.warn(`⚠️ Could not apply migrations in dev: ${e?.message ?? e}`);
266
+ console.warn(` Continuing without applying. Run migrations before deploy.`);
267
+ return false;
268
+ }
269
+ }