@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
package/src/hosting.ts ADDED
@@ -0,0 +1,626 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import * as cdk from 'aws-cdk-lib';
5
+ import {
6
+ AllowedMethods,
7
+ CachePolicy,
8
+ OriginRequestPolicy,
9
+ ViewerProtocolPolicy,
10
+ } from 'aws-cdk-lib/aws-cloudfront';
11
+ import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
12
+ import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
13
+ import { Construct } from 'constructs';
14
+ import { execSync } from 'node:child_process';
15
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
16
+ import { join, resolve } from 'node:path';
17
+
18
+ import {
19
+ HostingConstruct,
20
+ generateBuildId,
21
+ type HostingConstructProps,
22
+ type HostingDomainConfig,
23
+ type HostingWafConfig,
24
+ type SkewProtectionConfig,
25
+ } from '@aws-blocks/hosting/constructs';
26
+ import {
27
+ detectFramework,
28
+ getAdapter,
29
+ type FrameworkAdapterFn,
30
+ } from '@aws-blocks/hosting/adapters';
31
+ import type {
32
+ DeployManifest,
33
+ RouteBehavior,
34
+ FrameworkType,
35
+ } from '@aws-blocks/hosting';
36
+ import { BLOCKS_RPC_PREFIX, BLOCKS_AUTH_PREFIX } from './constants.js';
37
+ import { registerConfig } from './cdk/config-registry.js';
38
+ import { getRegisteredRoutes } from './raw-route.js';
39
+
40
+ // ─── Public types ────────────────────────────────────────────────
41
+
42
+ /**
43
+ * Lambda compute configuration for SSR frameworks.
44
+ *
45
+ * Controls the memory, timeout, concurrency, and log retention of the
46
+ * server-side rendering Lambda function.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * compute: {
51
+ * memorySize: 1024,
52
+ * timeout: Duration.seconds(30),
53
+ * reservedConcurrency: 10,
54
+ * }
55
+ * ```
56
+ */
57
+ export type ComputeConfig = {
58
+ /** Lambda memory size in MB. Default: 512. */
59
+ memorySize?: number;
60
+ /**
61
+ * Lambda timeout. Default: 30 seconds.
62
+ *
63
+ * Accepts either a `cdk.Duration` object (e.g. `Duration.seconds(30)`)
64
+ * or a plain number of seconds (e.g. `30`). Both are equivalent.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * // Either form works:
69
+ * timeout: Duration.seconds(30)
70
+ * timeout: 30
71
+ * ```
72
+ */
73
+ timeout?: cdk.Duration | number;
74
+ /** Reserved concurrent executions. Default: undefined (no reservation). */
75
+ reservedConcurrency?: number;
76
+ /** CloudWatch log retention for the SSR Lambda. Default: TWO_WEEKS. */
77
+ logRetention?: cdk.aws_logs.RetentionDays;
78
+ };
79
+
80
+ export type { FrameworkType, HostingDomainConfig, HostingWafConfig, SkewProtectionConfig };
81
+
82
+ /**
83
+ * Structural interface for the Blocks backend stack.
84
+ *
85
+ * Accepts any object that exposes an `apiUrl` — typically a {@link BlocksStack}
86
+ * instance but kept structural so Hosting doesn't depend on the concrete class.
87
+ */
88
+ export interface BlocksStackApi {
89
+ /** Fully-qualified API Gateway URL (e.g. `https://{id}.execute-api.{region}.amazonaws.com/{stage}/aws-blocks`). */
90
+ readonly apiUrl: string;
91
+ }
92
+
93
+ /**
94
+ * Blocks-specific configuration for the {@link Hosting} construct.
95
+ *
96
+ * Wraps the L3 {@link HostingConstruct} with Blocks conventions:
97
+ * • Runs the build command during CDK synth (optional)
98
+ * • Auto-detects the framework (Next.js / SPA / static)
99
+ * • Deploys `.blocks-sandbox/config.json` for client-side config loading
100
+ * • Injects `BLOCKS_API_URL` + `BLOCKS_CONFIG` env vars into compute functions
101
+ * • When `api` is provided, adds CloudFront behaviors to proxy API traffic
102
+ * through the same domain (single-origin architecture)
103
+ */
104
+ export interface HostingProps {
105
+ // ── Build ──────────────────────────────────────────────────────
106
+ /** Absolute or relative path to the frontend app root directory. */
107
+ root: string;
108
+
109
+ /**
110
+ * Shell command to build the frontend (e.g. `'npm run build'`).
111
+ * When provided, it is executed during CDK synth with `BLOCKS_API_URL`
112
+ * injected into the environment.
113
+ * Omit if the app is already pre-built.
114
+ */
115
+ buildCommand?: string;
116
+
117
+ /**
118
+ * Framework type: `'nextjs'`, `'spa'`, or `'static'`.
119
+ * Auto-detected from `package.json` when omitted.
120
+ */
121
+ framework?: FrameworkType;
122
+
123
+ /**
124
+ * Path to the build output directory (e.g. `'dist'` or `'.next'`).
125
+ * Auto-detected based on framework when omitted.
126
+ */
127
+ buildOutputDir?: string;
128
+
129
+ /** Supply a custom adapter when using an unsupported framework. */
130
+ customAdapter?: FrameworkAdapterFn;
131
+
132
+ // ── Blocks backend integration ────────────────────────────────────
133
+ /**
134
+ * The Blocks backend stack (or any object with `apiUrl`).
135
+ *
136
+ * When provided, Hosting creates CloudFront behaviors that proxy API
137
+ * requests through the same domain as the frontend — enabling relative
138
+ * URL access (`/aws-blocks/...`) without CORS.
139
+ *
140
+ * Omit when deploying a static-only site with no backend.
141
+ */
142
+ api?: BlocksStackApi;
143
+
144
+ /**
145
+ * Additional backend configuration to include in config.json.
146
+ * Merged with apiUrl to produce the final config.
147
+ *
148
+ * ⚠️ WARNING: These values will be publicly accessible at /.blocks-sandbox/config.json
149
+ * and in the BLOCKS_CONFIG Lambda environment variable. Do NOT include secrets,
150
+ * API keys, or sensitive configuration here.
151
+ */
152
+ backendConfig?: Record<string, unknown>;
153
+
154
+ // ── Infrastructure options ─────────────────────────────────────
155
+ /** Lambda compute configuration for SSR frameworks. */
156
+ compute?: ComputeConfig;
157
+
158
+ /** Custom domain configuration. */
159
+ domain?: HostingDomainConfig;
160
+
161
+ /** WAF protection configuration. */
162
+ waf?: HostingWafConfig;
163
+
164
+ /** Retain the S3 bucket when the stack is deleted. Default: false. */
165
+ retainOnDelete?: boolean;
166
+
167
+ /** Custom Content-Security-Policy header value. */
168
+ contentSecurityPolicy?: string;
169
+
170
+ /** CloudFront price class. Default: PRICE_CLASS_100. */
171
+ priceClass?: cdk.aws_cloudfront.PriceClass;
172
+
173
+ /**
174
+ * Geo-restriction configuration for the CloudFront distribution.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * geoRestriction: { type: 'whitelist', countries: ['US', 'CA', 'GB'] }
179
+ * ```
180
+ */
181
+ geoRestriction?: {
182
+ type: 'whitelist' | 'blacklist';
183
+ countries: string[];
184
+ };
185
+
186
+ /**
187
+ * Build cache configuration. When enabled, provisions an S3 bucket for
188
+ * framework build caches (e.g. Next.js .next/cache) and exports the bucket
189
+ * name as a CfnOutput. Reduces cold-build times in CI.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * buildCache: { enabled: true }
194
+ * ```
195
+ */
196
+ buildCache?: {
197
+ enabled: boolean;
198
+ /** BYO S3 bucket for build cache storage. Creates one if not provided. */
199
+ bucket?: cdk.aws_s3.IBucket;
200
+ };
201
+
202
+ /**
203
+ * Custom error pages served by CloudFront for 404/500 responses.
204
+ * Paths are relative to the project root and must point to HTML files
205
+ * present in the build output.
206
+ *
207
+ * Note: Custom error pages are incompatible with SPAs that use client-side
208
+ * routing. Error pages disable SPA fallback mode, which breaks deep linking.
209
+ * Use this feature for static sites and SSR apps only.
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * errorPages: { notFound: '/404.html', serverError: '/500.html' }
214
+ * ```
215
+ */
216
+ errorPages?: {
217
+ /** Path to a custom 404 HTML file (relative to project root). */
218
+ notFound?: string;
219
+ /** Path to a custom 500 HTML file (relative to project root). */
220
+ serverError?: string;
221
+ };
222
+
223
+ /**
224
+ * CloudFront access logging configuration.
225
+ * When enabled, access logs are written to a dedicated S3 bucket.
226
+ */
227
+ logging?: {
228
+ /** Enable CloudFront access logging. */
229
+ enabled: boolean;
230
+ /** Days to retain access logs. Default: 90. */
231
+ retentionDays?: number;
232
+ };
233
+
234
+ /**
235
+ * CloudWatch alarms for hosting infrastructure. When enabled, wires
236
+ * CloudFront 5xx, Lambda error/throttle, and revalidation DLQ alarms
237
+ * to an SNS topic.
238
+ *
239
+ * @default { enabled: true }
240
+ */
241
+ monitoring?: {
242
+ enabled?: boolean;
243
+ /** ARN of an existing SNS topic to send alarm actions to. */
244
+ snsTopicArn?: string;
245
+ };
246
+
247
+ /**
248
+ * Cookie-based skew protection to prevent asset mismatches during
249
+ * rolling deployments. When enabled, returning users are pinned to
250
+ * the build they started their session on.
251
+ *
252
+ * @default { enabled: true }
253
+ */
254
+ skewProtection?: SkewProtectionConfig;
255
+ }
256
+
257
+ // ─── Default build output directories per framework ──────────────
258
+
259
+ const DEFAULT_BUILD_DIRS: Record<string, string> = {
260
+ nextjs: '.next',
261
+ spa: 'dist',
262
+ static: 'dist',
263
+ };
264
+
265
+ // ─── Construct ───────────────────────────────────────────────────
266
+
267
+ /**
268
+ * Blocks hosting construct backed by the L3 {@link HostingConstruct}.
269
+ *
270
+ * Supports SPA, static sites, and Next.js SSR out of the box.
271
+ * When the `api` prop is provided, CloudFront behaviors are added to proxy
272
+ * `/aws-blocks/*` (and any registered {@link RawRoute} paths) through the
273
+ * same domain — enabling a single-origin architecture with no CORS issues.
274
+ *
275
+ * @example SPA deployment with API
276
+ * ```ts
277
+ * new Hosting(stack, 'Web', {
278
+ * root: join(__dirname, '..'),
279
+ * buildCommand: 'npm run build',
280
+ * api: blocksStack,
281
+ * });
282
+ * ```
283
+ *
284
+ * @example Next.js SSR deployment
285
+ * ```ts
286
+ * new Hosting(stack, 'Web', {
287
+ * root: join(__dirname, '..'),
288
+ * buildCommand: 'npm run build',
289
+ * framework: 'nextjs',
290
+ * api: blocksStack,
291
+ * compute: { memorySize: 1024, timeout: Duration.seconds(30) },
292
+ * });
293
+ * ```
294
+ *
295
+ * @example Static-only site (no backend)
296
+ * ```ts
297
+ * new Hosting(stack, 'Web', {
298
+ * root: join(__dirname, '..'),
299
+ * buildCommand: 'npm run build',
300
+ * });
301
+ * ```
302
+ */
303
+ export class Hosting extends Construct {
304
+ /** The S3 bucket storing static assets. */
305
+ public readonly bucket: cdk.aws_s3.Bucket;
306
+ /** The CloudFront distribution. */
307
+ public readonly distribution: cdk.aws_cloudfront.Distribution;
308
+ /** The public URL of the deployed site (https://...). */
309
+ public readonly url: string;
310
+ /** The primary SSR/compute Lambda function (first compute resource, if any). */
311
+ public readonly ssrFunction?: cdk.aws_lambda.Function;
312
+ /** S3 bucket for framework build caches (present when `buildCache.enabled` is true). */
313
+ public readonly buildCacheBucket?: cdk.aws_s3.Bucket;
314
+ /** SNS topic for hosting CloudWatch alarms (present when `monitoring.enabled` is true). */
315
+ public readonly monitoringTopic?: cdk.aws_sns.ITopic;
316
+
317
+ constructor(scope: Construct, id: string, props: HostingProps) {
318
+ super(scope, id);
319
+
320
+ const root = resolve(props.root);
321
+
322
+ // ── 1. Detect framework ──────────────────────────────────────
323
+ const framework = props.framework ?? detectFramework(root);
324
+
325
+ // ── 2. Optionally run the build ──────────────────────────────
326
+ if (props.buildCommand) {
327
+ console.log(`🏗️ Building frontend (${framework}): ${props.buildCommand}`);
328
+ const apiUrl = props.api?.apiUrl;
329
+ // Strip CDK's --conditions=cdk from NODE_OPTIONS to prevent it
330
+ // from breaking frontend builds (e.g., Next.js webpack module resolution).
331
+ const nodeOptions = (process.env.NODE_OPTIONS || '')
332
+ .split(/\s+/)
333
+ .filter(opt => opt !== '--conditions=cdk')
334
+ .join(' ');
335
+ const buildEnv = { ...process.env, NODE_OPTIONS: nodeOptions };
336
+ try {
337
+ execSync(props.buildCommand, {
338
+ cwd: root,
339
+ stdio: 'inherit',
340
+ env: {
341
+ ...buildEnv,
342
+ ...(apiUrl ? { BLOCKS_API_URL: apiUrl } : {}),
343
+ },
344
+ });
345
+ } catch (error) {
346
+ throw new Error(
347
+ `Frontend build failed: ${props.buildCommand}\n` +
348
+ `Ensure the build command is correct and all dependencies are installed.`,
349
+ );
350
+ }
351
+ }
352
+
353
+ // ── 3. Resolve build output dir (for validation only) ────────
354
+ const buildOutputDir = props.buildOutputDir;
355
+
356
+ const expectedOutputDir = buildOutputDir
357
+ ? resolve(root, buildOutputDir)
358
+ : resolve(root, DEFAULT_BUILD_DIRS[framework] ?? 'dist');
359
+
360
+ if (!existsSync(expectedOutputDir)) {
361
+ throw new Error(
362
+ `Build output directory not found: ${expectedOutputDir}\n` +
363
+ `Provide a buildCommand or ensure the directory exists before synthesis.`,
364
+ );
365
+ }
366
+
367
+ // ── 4. Run framework adapter → DeployManifest ────────────────
368
+ // For Next.js with buildCommand: the construct already ran `next build`
369
+ // with BLOCKS_API_URL in the env. OpenNext will re-run it but Next.js
370
+ // caches aggressively so it's fast. We still set BLOCKS_API_URL in the
371
+ // process env so OpenNext's build also has access to it.
372
+ if (props.api?.apiUrl) {
373
+ process.env.BLOCKS_API_URL = props.api.apiUrl;
374
+ }
375
+ const adapter = props.customAdapter ?? getAdapter(framework, buildOutputDir);
376
+ const manifest: DeployManifest = adapter(root);
377
+
378
+ // ── 4b. Ensure buildId is set on the manifest ────────────────
379
+ if (!manifest.buildId) {
380
+ manifest.buildId = generateBuildId();
381
+ }
382
+
383
+ // ── 4c. Prevent duplicate error pages ────────────────────────
384
+ // The adapter may auto-detect error pages (e.g. SPA adapter finds
385
+ // 404.html in build output and sets manifest.errorPages). When the
386
+ // user also provides errorPages via props, the CDN construct would
387
+ // create DUPLICATE CloudFront custom error responses — one from the
388
+ // manifest and one from the props.customErrorPages.
389
+ //
390
+ // Fix: when manifest.errorPages already covers the error codes,
391
+ // don't pass props.errorPages to the construct. The manifest's
392
+ // errorPages will drive the CloudFront configuration correctly,
393
+ // and the HTML files are already in the static assets directory
394
+ // (copied by the adapter).
395
+ const manifestHasErrorPages = manifest.errorPages !== undefined &&
396
+ Object.keys(manifest.errorPages).length > 0;
397
+ const skipPropsErrorPages = !!(props.errorPages && manifestHasErrorPages);
398
+
399
+ // ── 5. Write placeholder config.json into static assets ─────────
400
+ // A placeholder is needed so the L3 construct sees
401
+ // .blocks-sandbox/ in the static directory during bundling.
402
+ // The real config with resolved CDK tokens is deployed in
403
+ // step 8 via BucketDeployment + Source.jsonData().
404
+ const staticDir = manifest.staticAssets.directory;
405
+ const blocksSandboxDir = join(staticDir, '.blocks-sandbox');
406
+ mkdirSync(blocksSandboxDir, { recursive: true });
407
+ writeFileSync(
408
+ join(blocksSandboxDir, 'config.json'),
409
+ JSON.stringify({ _placeholder: true }),
410
+ );
411
+
412
+ // ── 5b. Inject static route for .blocks-sandbox config ──────────
413
+ // Insert a static route for /.blocks-sandbox/* so CloudFront
414
+ // serves config.json from S3 instead of routing to compute.
415
+ const blocksConfigRoute: RouteBehavior = {
416
+ pattern: '/.blocks-sandbox/*',
417
+ target: 'static',
418
+ };
419
+ // Insert before any catch-all route
420
+ const catchAllIdx = manifest.routes.findIndex((r) => r.pattern === '/*' || r.pattern === '/(.*)')
421
+ if (catchAllIdx >= 0) {
422
+ manifest.routes.splice(catchAllIdx, 0, blocksConfigRoute);
423
+ } else {
424
+ manifest.routes.push(blocksConfigRoute);
425
+ }
426
+
427
+ // ── 6. Create the L3 hosting construct ─────────────────────────
428
+ // Validate and normalize compute.timeout: accept both number (seconds) and Duration
429
+ if (props.compute && typeof props.compute.timeout === 'number') {
430
+ if (!Number.isFinite(props.compute.timeout) || props.compute.timeout < 1 || props.compute.timeout > 900) {
431
+ throw new Error(`compute.timeout must be between 1-900 seconds, got: ${props.compute.timeout}`);
432
+ }
433
+ }
434
+
435
+ const normalizedCompute = props.compute
436
+ ? {
437
+ ...props.compute,
438
+ timeout: typeof props.compute.timeout === 'number'
439
+ ? cdk.Duration.seconds(props.compute.timeout)
440
+ : props.compute.timeout,
441
+ }
442
+ : undefined;
443
+
444
+ const hostingProps: HostingConstructProps = {
445
+ manifest,
446
+ compute: normalizedCompute,
447
+ domain: props.domain,
448
+ waf: props.waf,
449
+ storage: props.retainOnDelete != null
450
+ ? { retainOnDelete: props.retainOnDelete }
451
+ : undefined,
452
+ cdn: (props.contentSecurityPolicy || props.priceClass || props.geoRestriction)
453
+ ? {
454
+ contentSecurityPolicy: props.contentSecurityPolicy,
455
+ priceClass: props.priceClass,
456
+ geoRestriction: props.geoRestriction,
457
+ }
458
+ : undefined,
459
+ logging: props.logging,
460
+ buildCache: props.buildCache,
461
+ errorPages: skipPropsErrorPages ? undefined : props.errorPages,
462
+ monitoring: props.monitoring,
463
+ skewProtection: props.skewProtection,
464
+ };
465
+
466
+ const hosting = new HostingConstruct(this, 'Hosting', hostingProps);
467
+
468
+ // ── 7. Add CloudFront behaviors for API proxy ────────────────
469
+ if (props.api) {
470
+ this.addApiBehaviors(hosting, props.api.apiUrl);
471
+ }
472
+
473
+ // ── 7a. Inject Blocks env vars into compute functions ───────────
474
+ const primaryFunction = hosting.computeFunctions.values().next().value as cdk.aws_lambda.Function | undefined;
475
+
476
+ for (const [, fn] of hosting.computeFunctions) {
477
+ if (props.api) {
478
+ (fn as cdk.aws_lambda.Function).addEnvironment('BLOCKS_API_URL', props.api.apiUrl);
479
+ }
480
+ if (props.backendConfig) {
481
+ (fn as cdk.aws_lambda.Function).addEnvironment(
482
+ 'BLOCKS_CONFIG',
483
+ JSON.stringify(props.backendConfig),
484
+ );
485
+ }
486
+ }
487
+
488
+ // ── 8. Deploy config.json with resolved CDK tokens ───────────
489
+ const buildId = manifest.buildId;
490
+ if (buildId) {
491
+ const configDeployment = new s3deploy.BucketDeployment(this, 'BlocksConfigDeployment', {
492
+ sources: [
493
+ s3deploy.Source.jsonData('config.json', this.buildConfigJson(props)),
494
+ ],
495
+ destinationBucket: hosting.bucket,
496
+ destinationKeyPrefix: `builds/${buildId}/.blocks-sandbox`,
497
+ prune: false,
498
+ distribution: hosting.distribution,
499
+ distributionPaths: ['/.blocks-sandbox/*'],
500
+ cacheControl: [s3deploy.CacheControl.fromString('public, max-age=60, must-revalidate')],
501
+ });
502
+
503
+ // Ensure config deployment runs after the hosting construct's
504
+ // asset deployment so the resolved config.json is not overwritten.
505
+ const assetDeployment = hosting.node.tryFindChild('AssetDeployment') as Construct | undefined;
506
+ if (assetDeployment) {
507
+ configDeployment.node.addDependency(assetDeployment);
508
+ }
509
+ }
510
+
511
+ // ── 9. Register public origin + CORS hosting origin into S3 config ──
512
+ // The Handler no longer depends on the BucketDeployment, so including
513
+ // the CloudFront domain token via registerConfig() is safe — no cycle.
514
+ // Traffic only flows after the stack is COMPLETE, so the Lambda always
515
+ // sees the full config (including these values) on its first cold start.
516
+ //
517
+ // Both values come from `hosting.distributionUrl` (custom-domain-aware:
518
+ // `https://<customDomain>` when configured, else the CloudFront default)
519
+ // so a custom-domain deploy gets the right public origin and CORS allow.
520
+ if (props.api) {
521
+ // BLOCKS_PUBLIC_ORIGIN: trusted public origin the app is served from. The
522
+ // auth BB (bb-auth-oidc) reads `process.env.BLOCKS_PUBLIC_ORIGIN` to build
523
+ // OIDC redirect_uris (config-derived, not from a forgeable request
524
+ // header) so server-initiated sign-in lands back on the CloudFront/custom
525
+ // domain — where the session cookie is scoped — instead of the raw
526
+ // execute-api host (which strips the viewer Host header). Kept a literal
527
+ // key (like CORS_HOSTING_ORIGINS below) rather than a shared constant.
528
+ registerConfig(this, 'BLOCKS_PUBLIC_ORIGIN', hosting.distributionUrl);
529
+ registerConfig(this, 'CORS_HOSTING_ORIGINS', hosting.distributionUrl);
530
+ }
531
+
532
+ // ── 10. Expose resources ──────────────────────────────────────
533
+ this.bucket = hosting.bucket;
534
+ this.distribution = hosting.distribution;
535
+ this.url = hosting.distributionUrl;
536
+ this.ssrFunction = primaryFunction;
537
+ this.buildCacheBucket = hosting.buildCacheBucket;
538
+ this.monitoringTopic = hosting.monitoringTopic;
539
+
540
+ // ── 11. CfnOutput ────────────────────────────────────────────
541
+ new cdk.CfnOutput(this, 'HostingUrl', {
542
+ value: hosting.distributionUrl,
543
+ description: 'Blocks Hosting URL',
544
+ });
545
+
546
+ if (hosting.buildCacheBucket) {
547
+ new cdk.CfnOutput(this, 'BuildCacheBucketName', {
548
+ value: hosting.buildCacheBucket.bucketName,
549
+ description: 'S3 bucket for framework build caches',
550
+ });
551
+ }
552
+ }
553
+
554
+ /**
555
+ * Build the config.json payload from props.
556
+ *
557
+ * When `api` is provided, the config uses a relative `/aws-blocks/api` URL
558
+ * so the frontend fetches through the same CloudFront domain (no CORS).
559
+ */
560
+ private buildConfigJson(props: HostingProps): Record<string, unknown> {
561
+ return {
562
+ ...(props.backendConfig ?? {}),
563
+ ...(props.api ? { apiUrl: BLOCKS_RPC_PREFIX } : {}),
564
+ };
565
+ }
566
+
567
+ /**
568
+ * Add CloudFront behaviors that proxy API traffic to the API Gateway origin.
569
+ */
570
+ private addApiBehaviors(hosting: HostingConstruct, apiUrl: string): void {
571
+ const baseUrl = cdk.Fn.select(0, cdk.Fn.split(BLOCKS_RPC_PREFIX, apiUrl));
572
+ const withoutScheme = cdk.Fn.select(1, cdk.Fn.split('https://', baseUrl));
573
+ const hostname = cdk.Fn.select(0, cdk.Fn.split('/', withoutScheme));
574
+ const stage = cdk.Fn.select(1, cdk.Fn.split('/', withoutScheme));
575
+
576
+ const apiGatewayOrigin = new HttpOrigin(hostname, {
577
+ originPath: `/${stage}`,
578
+ });
579
+
580
+ const behaviorDefaults = {
581
+ allowedMethods: AllowedMethods.ALLOW_ALL,
582
+ cachePolicy: CachePolicy.CACHING_DISABLED,
583
+ originRequestPolicy: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
584
+ viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
585
+ };
586
+
587
+ hosting.distribution.addBehavior(BLOCKS_RPC_PREFIX, apiGatewayOrigin, behaviorDefaults);
588
+ hosting.distribution.addBehavior(`${BLOCKS_RPC_PREFIX}/*`, apiGatewayOrigin, behaviorDefaults);
589
+
590
+ // Proxy the auth BB's reserved subtree as a single behavior. The auth flow
591
+ // (callback, sign-in, exchange, authorize-params, the stub IdP) is mounted
592
+ // only at runtime; declaring the subtree wildcard here — rather than per
593
+ // route at synth — proxies the whole flow regardless of providers or
594
+ // instance count, and never drifts as routes are added. Added directly (not
595
+ // via the route loop below) so it's emitted exactly once even with multiple
596
+ // AuthOIDC instances.
597
+ hosting.distribution.addBehavior(`${BLOCKS_AUTH_PREFIX}/*`, apiGatewayOrigin, behaviorDefaults);
598
+
599
+ const addedPatterns = new Set<string>([`${BLOCKS_RPC_PREFIX}/*`, `${BLOCKS_AUTH_PREFIX}/*`]);
600
+ for (const route of getRegisteredRoutes()) {
601
+ if (route.path.startsWith(`${BLOCKS_RPC_PREFIX}/`)) continue;
602
+ if (route.path === BLOCKS_AUTH_PREFIX || route.path.startsWith(`${BLOCKS_AUTH_PREFIX}/`)) continue;
603
+
604
+ let behaviorPattern: string;
605
+ const paramIndex = route.path.indexOf('/{');
606
+ if (paramIndex !== -1) {
607
+ behaviorPattern = route.path.substring(0, paramIndex) + '/*';
608
+ } else {
609
+ behaviorPattern = route.path;
610
+ }
611
+
612
+ if (addedPatterns.has(behaviorPattern)) continue;
613
+
614
+ if (behaviorPattern.endsWith('/*')) {
615
+ console.warn(
616
+ `[Hosting] ⚠️ RawRoute '${route.path}' creates CloudFront behavior '${behaviorPattern}' ` +
617
+ `which may shadow SSR/frontend routes under the same prefix. ` +
618
+ `Consider placing this route under ${BLOCKS_RPC_PREFIX}/ to avoid conflicts.`,
619
+ );
620
+ }
621
+
622
+ addedPatterns.add(behaviorPattern);
623
+ hosting.distribution.addBehavior(behaviorPattern, apiGatewayOrigin, behaviorDefaults);
624
+ }
625
+ }
626
+ }
@@ -0,0 +1,45 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { ApiNamespace, type BlocksContext, type ApiHandler } from './api.js';
5
+ export { BLOCKS_RPC_PREFIX, BLOCKS_AUTH_PREFIX } from './constants.js';
6
+ export { ApiError, isBlocksError } from './errors.js';
7
+ export { EventSourceMapping } from './lambda-handler.js';
8
+ export { BlocksStackProps } from './common/index.js';
9
+ export { registerSdkIdentifiers, getSdkIdentifiers, getAllSdkIdentifiers, _resetSdkRegistry } from './common/sdk-registry.js';
10
+ export { getConfig, getConfigSync, preloadConfig, loadConfigToProcessEnv, _resetConfigCache } from './common/config.js';
11
+ export { BlocksStack, Scope, SandboxDisableDeletionProtection, BlocksBackend, registerConfig, finalizeConfigRegistry, synthGuard, DEFAULT_NODE_RUNTIME, type BlocksBackendProps } from './cdk/index.js';
12
+ export {
13
+ Hosting,
14
+ type HostingProps,
15
+ type BlocksStackApi,
16
+ type FrameworkType,
17
+ type ComputeConfig,
18
+ type HostingDomainConfig,
19
+ type HostingWafConfig,
20
+ } from './hosting.js';
21
+ export {
22
+ RawRoute,
23
+ RawRouteErrors,
24
+ type RawRouteOptions,
25
+ type HttpMethod,
26
+ } from './raw-route.cdk.js';
27
+ export {
28
+ registerRoute,
29
+ matchRoute,
30
+ getRegisteredRoutes,
31
+ clearRouteRegistry,
32
+ lockRouteRegistry,
33
+ unlockRouteRegistry,
34
+ type RegisteredRoute,
35
+ } from './raw-route.js';
36
+ export {
37
+ Pipeline,
38
+ DeployStage,
39
+ type DeployStageProps,
40
+ type BranchConfig,
41
+ type PipelineProps,
42
+ type PipelineSourceConfig,
43
+ type PipelineSynthConfig,
44
+ type PipelineStageConfig,
45
+ } from './pipeline/index.js';
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { ApiNamespace, type BlocksContext, type ApiHandler } from './api.js';
5
+ export { BLOCKS_RPC_PREFIX, BLOCKS_AUTH_PREFIX } from './constants.js';
6
+ export { ApiError, isBlocksError } from './errors.js';
7
+ export { Scope, type ScopeOptions, type ScopeParent, type BuildingBlockMeta } from './common/index.js';
8
+ export { registerSdkIdentifiers, getSdkIdentifiers, getAllSdkIdentifiers, _resetSdkRegistry } from './common/sdk-registry.js';
9
+ export { getConfig, getConfigSync, preloadConfig, loadConfigToProcessEnv, _resetConfigCache } from './common/config.js';
10
+ export {
11
+ registerRoute,
12
+ matchRoute,
13
+ getRegisteredRoutes,
14
+ clearRouteRegistry,
15
+ lockRouteRegistry,
16
+ unlockRouteRegistry,
17
+ RawRouteErrors,
18
+ type RawRouteOptions,
19
+ type HttpMethod,
20
+ type RegisteredRoute,
21
+ } from './raw-route.js';
22
+ export { RawRoute } from './raw-route.mock.js';