@sst-community/sst 4.20.0 → 5.0.0-alpha.1

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 (832) hide show
  1. package/README.md +92 -52
  2. package/package.json +35 -11
  3. package/platform/js/chunks/chunk-HIZZCEDS.js +328 -0
  4. package/platform/js/chunks/chunk-HIZZCEDS.js.map +6 -0
  5. package/platform/js/chunks/chunk-KOKHGKJ2.js +639 -0
  6. package/platform/js/chunks/chunk-KOKHGKJ2.js.map +6 -0
  7. package/platform/js/chunks/chunk-ONNI4XNK.js +367 -0
  8. package/platform/js/chunks/chunk-ONNI4XNK.js.map +6 -0
  9. package/platform/js/chunks/chunk-VIFHC73J.js +108 -0
  10. package/platform/js/chunks/chunk-VIFHC73J.js.map +6 -0
  11. package/platform/js/chunks/chunk-WJ6BVA46.js +10 -0
  12. package/platform/js/chunks/chunk-WJ6BVA46.js.map +6 -0
  13. package/platform/js/chunks/chunk-ZOXXXME5.js +472 -0
  14. package/platform/js/chunks/chunk-ZOXXXME5.js.map +6 -0
  15. package/platform/js/chunks/component-32FCLIRK.js +26 -0
  16. package/platform/js/chunks/component-32FCLIRK.js.map +6 -0
  17. package/platform/js/chunks/config-DMGMTLNB.js +10 -0
  18. package/platform/js/chunks/config-DMGMTLNB.js.map +6 -0
  19. package/platform/js/chunks/link-OJ3RNGQ3.js +9 -0
  20. package/platform/js/chunks/link-OJ3RNGQ3.js.map +6 -0
  21. package/platform/js/components/aws/index.js +35362 -0
  22. package/platform/js/components/aws/index.js.map +6 -0
  23. package/platform/js/components/cloudflare/index.js +3246 -0
  24. package/platform/js/components/cloudflare/index.js.map +6 -0
  25. package/platform/js/components/core.js +114 -0
  26. package/platform/js/components/core.js.map +6 -0
  27. package/platform/js/components/vercel/index.js +120 -0
  28. package/platform/js/components/vercel/index.js.map +6 -0
  29. package/platform/js/testing/index.js +569 -0
  30. package/platform/js/testing/index.js.map +6 -0
  31. package/platform/package.json +25 -0
  32. package/platform/src/ast/add.mjs +190 -0
  33. package/platform/src/auto/run.ts +109 -0
  34. package/platform/src/components/README.md +652 -0
  35. package/platform/src/components/args.ts +133 -0
  36. package/platform/src/components/aws/alb.ts +577 -0
  37. package/platform/src/components/aws/analog.ts +462 -0
  38. package/platform/src/components/aws/apigateway-websocket-route.ts +206 -0
  39. package/platform/src/components/aws/apigateway-websocket.ts +894 -0
  40. package/platform/src/components/aws/apigatewayv1-api-key.ts +90 -0
  41. package/platform/src/components/aws/apigatewayv1-authorizer.ts +178 -0
  42. package/platform/src/components/aws/apigatewayv1-base-route.ts +78 -0
  43. package/platform/src/components/aws/apigatewayv1-integration-route.ts +92 -0
  44. package/platform/src/components/aws/apigatewayv1-lambda-route.ts +152 -0
  45. package/platform/src/components/aws/apigatewayv1-usage-plan.ts +109 -0
  46. package/platform/src/components/aws/apigatewayv1.ts +1691 -0
  47. package/platform/src/components/aws/apigatewayv2-authorizer.ts +199 -0
  48. package/platform/src/components/aws/apigatewayv2-base-route.ts +69 -0
  49. package/platform/src/components/aws/apigatewayv2-lambda-route.ts +141 -0
  50. package/platform/src/components/aws/apigatewayv2-private-route.ts +101 -0
  51. package/platform/src/components/aws/apigatewayv2-url-route.ts +90 -0
  52. package/platform/src/components/aws/apigatewayv2.ts +1439 -0
  53. package/platform/src/components/aws/app-sync-data-source.ts +264 -0
  54. package/platform/src/components/aws/app-sync-function.ts +79 -0
  55. package/platform/src/components/aws/app-sync-resolver.ts +110 -0
  56. package/platform/src/components/aws/app-sync.ts +849 -0
  57. package/platform/src/components/aws/astro.ts +580 -0
  58. package/platform/src/components/aws/aurora.ts +1356 -0
  59. package/platform/src/components/aws/auth-v1.ts +69 -0
  60. package/platform/src/components/aws/auth.ts +417 -0
  61. package/platform/src/components/aws/bucket-lambda-subscriber.ts +162 -0
  62. package/platform/src/components/aws/bucket-notification.ts +254 -0
  63. package/platform/src/components/aws/bucket-queue-subscriber.ts +122 -0
  64. package/platform/src/components/aws/bucket-topic-subscriber.ts +144 -0
  65. package/platform/src/components/aws/bucket.ts +2046 -0
  66. package/platform/src/components/aws/bus-base-subscriber.ts +52 -0
  67. package/platform/src/components/aws/bus-lambda-subscriber.ts +125 -0
  68. package/platform/src/components/aws/bus-queue-subscriber.ts +88 -0
  69. package/platform/src/components/aws/bus.ts +630 -0
  70. package/platform/src/components/aws/cdn.ts +561 -0
  71. package/platform/src/components/aws/cluster-v1.ts +932 -0
  72. package/platform/src/components/aws/cluster.ts +584 -0
  73. package/platform/src/components/aws/cognito-identity-pool.ts +433 -0
  74. package/platform/src/components/aws/cognito-identity-provider.ts +96 -0
  75. package/platform/src/components/aws/cognito-user-pool-client.ts +114 -0
  76. package/platform/src/components/aws/cognito-user-pool.ts +1089 -0
  77. package/platform/src/components/aws/cron-v2.ts +555 -0
  78. package/platform/src/components/aws/cron.ts +435 -0
  79. package/platform/src/components/aws/dns-validated-certificate.ts +108 -0
  80. package/platform/src/components/aws/dns.ts +221 -0
  81. package/platform/src/components/aws/dsql.ts +741 -0
  82. package/platform/src/components/aws/dynamo-lambda-subscriber.ts +124 -0
  83. package/platform/src/components/aws/dynamo.ts +929 -0
  84. package/platform/src/components/aws/efs.ts +410 -0
  85. package/platform/src/components/aws/email.ts +673 -0
  86. package/platform/src/components/aws/fargate.ts +1279 -0
  87. package/platform/src/components/aws/function.ts +3227 -0
  88. package/platform/src/components/aws/helpers/apigateway-account.ts +78 -0
  89. package/platform/src/components/aws/helpers/apigatewayv2-domain.ts +144 -0
  90. package/platform/src/components/aws/helpers/arn.ts +182 -0
  91. package/platform/src/components/aws/helpers/bootstrap.ts +16 -0
  92. package/platform/src/components/aws/helpers/client.ts +76 -0
  93. package/platform/src/components/aws/helpers/container-builder.ts +33 -0
  94. package/platform/src/components/aws/helpers/custom-domain.ts +128 -0
  95. package/platform/src/components/aws/helpers/event-source.ts +41 -0
  96. package/platform/src/components/aws/helpers/fargate.ts +727 -0
  97. package/platform/src/components/aws/helpers/function-builder.ts +133 -0
  98. package/platform/src/components/aws/helpers/function-code.ts +224 -0
  99. package/platform/src/components/aws/helpers/function-part.ts +202 -0
  100. package/platform/src/components/aws/helpers/function-permission.ts +29 -0
  101. package/platform/src/components/aws/helpers/load-balancer-args.ts +88 -0
  102. package/platform/src/components/aws/helpers/load-balancer.ts +17 -0
  103. package/platform/src/components/aws/helpers/provider.ts +36 -0
  104. package/platform/src/components/aws/helpers/queue-policy.ts +33 -0
  105. package/platform/src/components/aws/helpers/rds.ts +212 -0
  106. package/platform/src/components/aws/helpers/site-builder.ts +41 -0
  107. package/platform/src/components/aws/helpers/subscriber.ts +23 -0
  108. package/platform/src/components/aws/helpers/vpc.ts +27 -0
  109. package/platform/src/components/aws/https-redirect.ts +216 -0
  110. package/platform/src/components/aws/iam-edit.ts +50 -0
  111. package/platform/src/components/aws/index.ts +61 -0
  112. package/platform/src/components/aws/kinesis-stream-lambda-subscriber.ts +122 -0
  113. package/platform/src/components/aws/kinesis-stream.ts +416 -0
  114. package/platform/src/components/aws/linkable.ts +32 -0
  115. package/platform/src/components/aws/logging.ts +25 -0
  116. package/platform/src/components/aws/microvm.ts +988 -0
  117. package/platform/src/components/aws/mysql.ts +1047 -0
  118. package/platform/src/components/aws/nextjs.ts +1052 -0
  119. package/platform/src/components/aws/nuxt.ts +527 -0
  120. package/platform/src/components/aws/open-search.ts +603 -0
  121. package/platform/src/components/aws/opencontrol.ts +235 -0
  122. package/platform/src/components/aws/permission.ts +80 -0
  123. package/platform/src/components/aws/postgres-v1.ts +537 -0
  124. package/platform/src/components/aws/postgres.ts +1074 -0
  125. package/platform/src/components/aws/providers/bucket-files.ts +32 -0
  126. package/platform/src/components/aws/providers/distribution-deployment-waiter.ts +27 -0
  127. package/platform/src/components/aws/providers/distribution-invalidation.ts +24 -0
  128. package/platform/src/components/aws/providers/function-environment-update.ts +46 -0
  129. package/platform/src/components/aws/providers/hosted-zone-lookup.ts +25 -0
  130. package/platform/src/components/aws/providers/kv-keys.ts +15 -0
  131. package/platform/src/components/aws/providers/kv-routes-update.ts +24 -0
  132. package/platform/src/components/aws/providers/microvm-image-prune.ts +48 -0
  133. package/platform/src/components/aws/providers/origin-access-control.ts +21 -0
  134. package/platform/src/components/aws/providers/rds-role-lookup.ts +21 -0
  135. package/platform/src/components/aws/providers/vector-table.ts +25 -0
  136. package/platform/src/components/aws/queue-lambda-subscriber.ts +135 -0
  137. package/platform/src/components/aws/queue.ts +712 -0
  138. package/platform/src/components/aws/react.ts +510 -0
  139. package/platform/src/components/aws/realtime-lambda-subscriber.ts +129 -0
  140. package/platform/src/components/aws/realtime.ts +345 -0
  141. package/platform/src/components/aws/redis-v1.ts +595 -0
  142. package/platform/src/components/aws/redis.ts +1078 -0
  143. package/platform/src/components/aws/remix.ts +576 -0
  144. package/platform/src/components/aws/router-base-route.ts +83 -0
  145. package/platform/src/components/aws/router-bucket-route.ts +63 -0
  146. package/platform/src/components/aws/router-url-route.ts +75 -0
  147. package/platform/src/components/aws/router.ts +3281 -0
  148. package/platform/src/components/aws/service-v1.ts +876 -0
  149. package/platform/src/components/aws/service.ts +2994 -0
  150. package/platform/src/components/aws/sns-topic-lambda-subscriber.ts +127 -0
  151. package/platform/src/components/aws/sns-topic-queue-subscriber.ts +105 -0
  152. package/platform/src/components/aws/sns-topic.ts +700 -0
  153. package/platform/src/components/aws/solid-start.ts +467 -0
  154. package/platform/src/components/aws/ssr-site.ts +2204 -0
  155. package/platform/src/components/aws/static-site.ts +1389 -0
  156. package/platform/src/components/aws/step-functions/choice.ts +123 -0
  157. package/platform/src/components/aws/step-functions/fail.ts +69 -0
  158. package/platform/src/components/aws/step-functions/map.ts +264 -0
  159. package/platform/src/components/aws/step-functions/parallel.ts +170 -0
  160. package/platform/src/components/aws/step-functions/pass.ts +48 -0
  161. package/platform/src/components/aws/step-functions/state.ts +376 -0
  162. package/platform/src/components/aws/step-functions/succeed.ts +31 -0
  163. package/platform/src/components/aws/step-functions/task.ts +538 -0
  164. package/platform/src/components/aws/step-functions/wait.ts +105 -0
  165. package/platform/src/components/aws/step-functions.ts +804 -0
  166. package/platform/src/components/aws/svelte-kit.ts +563 -0
  167. package/platform/src/components/aws/takeover/alb.ts +9 -0
  168. package/platform/src/components/aws/takeover/apigatewayv2.ts +43 -0
  169. package/platform/src/components/aws/takeover/app-sync.ts +45 -0
  170. package/platform/src/components/aws/takeover/aurora.ts +19 -0
  171. package/platform/src/components/aws/takeover/bucket.ts +94 -0
  172. package/platform/src/components/aws/takeover/bus.ts +43 -0
  173. package/platform/src/components/aws/takeover/cognito-user-pool.ts +21 -0
  174. package/platform/src/components/aws/takeover/cron-v2.ts +9 -0
  175. package/platform/src/components/aws/takeover/dsql.ts +12 -0
  176. package/platform/src/components/aws/takeover/dynamo.ts +31 -0
  177. package/platform/src/components/aws/takeover/efs.ts +9 -0
  178. package/platform/src/components/aws/takeover/function.ts +21 -0
  179. package/platform/src/components/aws/takeover/helpers.ts +26 -0
  180. package/platform/src/components/aws/takeover/index.ts +27 -0
  181. package/platform/src/components/aws/takeover/mysql.ts +17 -0
  182. package/platform/src/components/aws/takeover/postgres.ts +17 -0
  183. package/platform/src/components/aws/takeover/queue.ts +21 -0
  184. package/platform/src/components/aws/takeover/redis.ts +10 -0
  185. package/platform/src/components/aws/takeover/service.ts +22 -0
  186. package/platform/src/components/aws/takeover/sns-topic.ts +27 -0
  187. package/platform/src/components/aws/takeover/task.ts +13 -0
  188. package/platform/src/components/aws/tan-stack-start.ts +479 -0
  189. package/platform/src/components/aws/task.ts +571 -0
  190. package/platform/src/components/aws/v5/alb.ts +310 -0
  191. package/platform/src/components/aws/v5/apigatewayv2.ts +845 -0
  192. package/platform/src/components/aws/v5/app-sync.ts +673 -0
  193. package/platform/src/components/aws/v5/aurora.ts +855 -0
  194. package/platform/src/components/aws/v5/bucket.ts +1001 -0
  195. package/platform/src/components/aws/v5/bus.ts +321 -0
  196. package/platform/src/components/aws/v5/cluster.ts +230 -0
  197. package/platform/src/components/aws/v5/cognito-user-pool-client.ts +100 -0
  198. package/platform/src/components/aws/v5/cognito-user-pool.ts +693 -0
  199. package/platform/src/components/aws/v5/cron-v2.ts +316 -0
  200. package/platform/src/components/aws/v5/dsql.ts +665 -0
  201. package/platform/src/components/aws/v5/dynamo.ts +477 -0
  202. package/platform/src/components/aws/v5/efs.ts +311 -0
  203. package/platform/src/components/aws/v5/function.ts +1527 -0
  204. package/platform/src/components/aws/v5/index.ts +26 -0
  205. package/platform/src/components/aws/v5/mysql.ts +604 -0
  206. package/platform/src/components/aws/v5/postgres.ts +612 -0
  207. package/platform/src/components/aws/v5/queue.ts +271 -0
  208. package/platform/src/components/aws/v5/redis.ts +550 -0
  209. package/platform/src/components/aws/v5/service.ts +2209 -0
  210. package/platform/src/components/aws/v5/sns-topic.ts +284 -0
  211. package/platform/src/components/aws/v5/task.ts +549 -0
  212. package/platform/src/components/aws/vector.ts +316 -0
  213. package/platform/src/components/aws/vpc-v1.ts +580 -0
  214. package/platform/src/components/aws/vpc.ts +1641 -0
  215. package/platform/src/components/aws/workflow.ts +421 -0
  216. package/platform/src/components/base/base-site.ts +101 -0
  217. package/platform/src/components/base/base-ssr-site.ts +120 -0
  218. package/platform/src/components/base/base-static-site.ts +314 -0
  219. package/platform/src/components/cloudflare/account-id.ts +1 -0
  220. package/platform/src/components/cloudflare/ai.ts +77 -0
  221. package/platform/src/components/cloudflare/astro.ts +355 -0
  222. package/platform/src/components/cloudflare/auth.ts +69 -0
  223. package/platform/src/components/cloudflare/binding.ts +132 -0
  224. package/platform/src/components/cloudflare/bucket.ts +142 -0
  225. package/platform/src/components/cloudflare/cron.ts +207 -0
  226. package/platform/src/components/cloudflare/d1.ts +230 -0
  227. package/platform/src/components/cloudflare/dns.ts +253 -0
  228. package/platform/src/components/cloudflare/durable-object.ts +144 -0
  229. package/platform/src/components/cloudflare/experimental/index.ts +3 -0
  230. package/platform/src/components/cloudflare/experimental/solid-start.ts +288 -0
  231. package/platform/src/components/cloudflare/experimental/static-site.ts +4 -0
  232. package/platform/src/components/cloudflare/helpers/compatibility.ts +44 -0
  233. package/platform/src/components/cloudflare/helpers/fetch.ts +81 -0
  234. package/platform/src/components/cloudflare/helpers/validation.ts +74 -0
  235. package/platform/src/components/cloudflare/helpers/worker-builder.ts +57 -0
  236. package/platform/src/components/cloudflare/helpers/wrangler.ts +222 -0
  237. package/platform/src/components/cloudflare/hyperdrive.ts +402 -0
  238. package/platform/src/components/cloudflare/index.ts +25 -0
  239. package/platform/src/components/cloudflare/kv.ts +218 -0
  240. package/platform/src/components/cloudflare/providers/dns-record.ts +43 -0
  241. package/platform/src/components/cloudflare/providers/kv-data.ts +107 -0
  242. package/platform/src/components/cloudflare/providers/worker-assets.ts +41 -0
  243. package/platform/src/components/cloudflare/providers/worker-placement.ts +93 -0
  244. package/platform/src/components/cloudflare/providers/worker-script.ts +47 -0
  245. package/platform/src/components/cloudflare/providers/worker-url.ts +109 -0
  246. package/platform/src/components/cloudflare/providers/zone-lookup.ts +85 -0
  247. package/platform/src/components/cloudflare/queue-worker-subscriber.ts +192 -0
  248. package/platform/src/components/cloudflare/queue.ts +310 -0
  249. package/platform/src/components/cloudflare/rate-limit.ts +178 -0
  250. package/platform/src/components/cloudflare/react-router.ts +322 -0
  251. package/platform/src/components/cloudflare/ssr-site.ts +293 -0
  252. package/platform/src/components/cloudflare/static-site-v2.ts +428 -0
  253. package/platform/src/components/cloudflare/static-site.ts +470 -0
  254. package/platform/src/components/cloudflare/tan-stack-start.ts +408 -0
  255. package/platform/src/components/cloudflare/worker.ts +1080 -0
  256. package/platform/src/components/cloudflare/workflow.ts +319 -0
  257. package/platform/src/components/component.ts +242 -0
  258. package/platform/src/components/core.ts +43 -0
  259. package/platform/src/components/cpu.ts +10 -0
  260. package/platform/src/components/dns.ts +82 -0
  261. package/platform/src/components/duration.ts +67 -0
  262. package/platform/src/components/error.ts +5 -0
  263. package/platform/src/components/esbuild.ts +15 -0
  264. package/platform/src/components/experimental/dev-command.ts +127 -0
  265. package/platform/src/components/experimental/index.ts +1 -0
  266. package/platform/src/components/groups.ts +9 -0
  267. package/platform/src/components/index.ts +9 -0
  268. package/platform/src/components/input.ts +2 -0
  269. package/platform/src/components/link.ts +201 -0
  270. package/platform/src/components/linkable.ts +360 -0
  271. package/platform/src/components/naming-rules.ts +299 -0
  272. package/platform/src/components/naming.ts +189 -0
  273. package/platform/src/components/parts-component.ts +662 -0
  274. package/platform/src/components/parts.ts +299 -0
  275. package/platform/src/components/path.ts +5 -0
  276. package/platform/src/components/rpc/rpc.ts +110 -0
  277. package/platform/src/components/secret.ts +159 -0
  278. package/platform/src/components/size.ts +28 -0
  279. package/platform/src/components/takeover.ts +131 -0
  280. package/platform/src/components/transform.ts +107 -0
  281. package/platform/src/components/vercel/account-id.ts +1 -0
  282. package/platform/src/components/vercel/dns.ts +171 -0
  283. package/platform/src/components/vercel/index.ts +2 -0
  284. package/platform/src/components/vercel/providers/dns-record.ts +34 -0
  285. package/platform/src/config.ts +1460 -0
  286. package/platform/src/global-aliases.d.ts +37 -0
  287. package/platform/src/global.d.ts +374 -0
  288. package/platform/src/internal.d.ts +18 -0
  289. package/platform/src/runtime/worker/unenv.d.ts +14 -0
  290. package/platform/src/runtime/worker/unenv.mjs +26 -0
  291. package/platform/src/shim/run.js +25 -0
  292. package/platform/src/testing/global.ts +83 -0
  293. package/platform/src/testing/index.ts +103 -0
  294. package/platform/src/testing/mock.ts +646 -0
  295. package/platform/src/testing/vitest.ts +36 -0
  296. package/platform/src/util/compare-semver.ts +23 -0
  297. package/platform/src/util/fs.ts +49 -0
  298. package/platform/src/util/lazy.ts +12 -0
  299. package/platform/src/util/minify.ts +10 -0
  300. package/platform/src/util/package.ts +29 -0
  301. package/platform/src/util/semaphore.ts +29 -0
  302. package/platform/src/util/warn.ts +7 -0
  303. package/platform/types/auto/run.d.ts +9 -0
  304. package/platform/types/auto/run.d.ts.map +1 -0
  305. package/platform/types/components/args.d.ts +77 -0
  306. package/platform/types/components/args.d.ts.map +1 -0
  307. package/platform/types/components/aws/alb.d.ts +283 -0
  308. package/platform/types/components/aws/alb.d.ts.map +1 -0
  309. package/platform/types/components/aws/analog.d.ts +408 -0
  310. package/platform/types/components/aws/analog.d.ts.map +1 -0
  311. package/platform/types/components/aws/apigateway-websocket-route.d.ts +74 -0
  312. package/platform/types/components/aws/apigateway-websocket-route.d.ts.map +1 -0
  313. package/platform/types/components/aws/apigateway-websocket.d.ts +560 -0
  314. package/platform/types/components/aws/apigateway-websocket.d.ts.map +1 -0
  315. package/platform/types/components/aws/apigatewayv1-api-key.d.ts +48 -0
  316. package/platform/types/components/aws/apigatewayv1-api-key.d.ts.map +1 -0
  317. package/platform/types/components/aws/apigatewayv1-authorizer.d.ts +55 -0
  318. package/platform/types/components/aws/apigatewayv1-authorizer.d.ts.map +1 -0
  319. package/platform/types/components/aws/apigatewayv1-base-route.d.ts +36 -0
  320. package/platform/types/components/aws/apigatewayv1-base-route.d.ts.map +1 -0
  321. package/platform/types/components/aws/apigatewayv1-integration-route.d.ts +39 -0
  322. package/platform/types/components/aws/apigatewayv1-integration-route.d.ts.map +1 -0
  323. package/platform/types/components/aws/apigatewayv1-lambda-route.d.ts +53 -0
  324. package/platform/types/components/aws/apigatewayv1-lambda-route.d.ts.map +1 -0
  325. package/platform/types/components/aws/apigatewayv1-usage-plan.d.ts +53 -0
  326. package/platform/types/components/aws/apigatewayv1-usage-plan.d.ts.map +1 -0
  327. package/platform/types/components/aws/apigatewayv1.d.ts +1028 -0
  328. package/platform/types/components/aws/apigatewayv1.d.ts.map +1 -0
  329. package/platform/types/components/aws/apigatewayv2-authorizer.d.ts +54 -0
  330. package/platform/types/components/aws/apigatewayv2-authorizer.d.ts.map +1 -0
  331. package/platform/types/components/aws/apigatewayv2-base-route.d.ts +28 -0
  332. package/platform/types/components/aws/apigatewayv2-base-route.d.ts.map +1 -0
  333. package/platform/types/components/aws/apigatewayv2-lambda-route.d.ts +59 -0
  334. package/platform/types/components/aws/apigatewayv2-lambda-route.d.ts.map +1 -0
  335. package/platform/types/components/aws/apigatewayv2-private-route.d.ts +54 -0
  336. package/platform/types/components/aws/apigatewayv2-private-route.d.ts.map +1 -0
  337. package/platform/types/components/aws/apigatewayv2-url-route.d.ts +44 -0
  338. package/platform/types/components/aws/apigatewayv2-url-route.d.ts.map +1 -0
  339. package/platform/types/components/aws/apigatewayv2.d.ts +955 -0
  340. package/platform/types/components/aws/apigatewayv2.d.ts.map +1 -0
  341. package/platform/types/components/aws/app-sync-data-source.d.ts +52 -0
  342. package/platform/types/components/aws/app-sync-data-source.d.ts.map +1 -0
  343. package/platform/types/components/aws/app-sync-function.d.ts +33 -0
  344. package/platform/types/components/aws/app-sync-function.d.ts.map +1 -0
  345. package/platform/types/components/aws/app-sync-resolver.d.ts +41 -0
  346. package/platform/types/components/aws/app-sync-resolver.d.ts.map +1 -0
  347. package/platform/types/components/aws/app-sync.d.ts +638 -0
  348. package/platform/types/components/aws/app-sync.d.ts.map +1 -0
  349. package/platform/types/components/aws/astro.d.ts +409 -0
  350. package/platform/types/components/aws/astro.d.ts.map +1 -0
  351. package/platform/types/components/aws/aurora.d.ts +720 -0
  352. package/platform/types/components/aws/aurora.d.ts.map +1 -0
  353. package/platform/types/components/aws/auth-v1.d.ts +26 -0
  354. package/platform/types/components/aws/auth-v1.d.ts.map +1 -0
  355. package/platform/types/components/aws/auth.d.ts +295 -0
  356. package/platform/types/components/aws/auth.d.ts.map +1 -0
  357. package/platform/types/components/aws/bucket-lambda-subscriber.d.ts +61 -0
  358. package/platform/types/components/aws/bucket-lambda-subscriber.d.ts.map +1 -0
  359. package/platform/types/components/aws/bucket-notification.d.ts +47 -0
  360. package/platform/types/components/aws/bucket-notification.d.ts.map +1 -0
  361. package/platform/types/components/aws/bucket-queue-subscriber.d.ts +55 -0
  362. package/platform/types/components/aws/bucket-queue-subscriber.d.ts.map +1 -0
  363. package/platform/types/components/aws/bucket-topic-subscriber.d.ts +55 -0
  364. package/platform/types/components/aws/bucket-topic-subscriber.d.ts.map +1 -0
  365. package/platform/types/components/aws/bucket.d.ts +1356 -0
  366. package/platform/types/components/aws/bucket.d.ts.map +1 -0
  367. package/platform/types/components/aws/bus-base-subscriber.d.ts +20 -0
  368. package/platform/types/components/aws/bus-base-subscriber.d.ts.map +1 -0
  369. package/platform/types/components/aws/bus-lambda-subscriber.d.ts +50 -0
  370. package/platform/types/components/aws/bus-lambda-subscriber.d.ts.map +1 -0
  371. package/platform/types/components/aws/bus-queue-subscriber.d.ts +44 -0
  372. package/platform/types/components/aws/bus-queue-subscriber.d.ts.map +1 -0
  373. package/platform/types/components/aws/bus.d.ts +447 -0
  374. package/platform/types/components/aws/bus.d.ts.map +1 -0
  375. package/platform/types/components/aws/cdn.d.ts +310 -0
  376. package/platform/types/components/aws/cdn.d.ts.map +1 -0
  377. package/platform/types/components/aws/cluster-v1.d.ts +885 -0
  378. package/platform/types/components/aws/cluster-v1.d.ts.map +1 -0
  379. package/platform/types/components/aws/cluster.d.ts +364 -0
  380. package/platform/types/components/aws/cluster.d.ts.map +1 -0
  381. package/platform/types/components/aws/cognito-identity-pool.d.ts +199 -0
  382. package/platform/types/components/aws/cognito-identity-pool.d.ts.map +1 -0
  383. package/platform/types/components/aws/cognito-identity-provider.d.ts +38 -0
  384. package/platform/types/components/aws/cognito-identity-provider.d.ts.map +1 -0
  385. package/platform/types/components/aws/cognito-user-pool-client.d.ts +50 -0
  386. package/platform/types/components/aws/cognito-user-pool-client.d.ts.map +1 -0
  387. package/platform/types/components/aws/cognito-user-pool.d.ts +703 -0
  388. package/platform/types/components/aws/cognito-user-pool.d.ts.map +1 -0
  389. package/platform/types/components/aws/cron-v2.d.ts +325 -0
  390. package/platform/types/components/aws/cron-v2.d.ts.map +1 -0
  391. package/platform/types/components/aws/cron.d.ts +259 -0
  392. package/platform/types/components/aws/cron.d.ts.map +1 -0
  393. package/platform/types/components/aws/dns-validated-certificate.d.ts +27 -0
  394. package/platform/types/components/aws/dns-validated-certificate.d.ts.map +1 -0
  395. package/platform/types/components/aws/dns.d.ts +94 -0
  396. package/platform/types/components/aws/dns.d.ts.map +1 -0
  397. package/platform/types/components/aws/dsql.d.ts +369 -0
  398. package/platform/types/components/aws/dsql.d.ts.map +1 -0
  399. package/platform/types/components/aws/dynamo-lambda-subscriber.d.ts +55 -0
  400. package/platform/types/components/aws/dynamo-lambda-subscriber.d.ts.map +1 -0
  401. package/platform/types/components/aws/dynamo.d.ts +628 -0
  402. package/platform/types/components/aws/dynamo.d.ts.map +1 -0
  403. package/platform/types/components/aws/efs.d.ts +217 -0
  404. package/platform/types/components/aws/efs.d.ts.map +1 -0
  405. package/platform/types/components/aws/email.d.ts +370 -0
  406. package/platform/types/components/aws/email.d.ts.map +1 -0
  407. package/platform/types/components/aws/fargate.d.ts +894 -0
  408. package/platform/types/components/aws/fargate.d.ts.map +1 -0
  409. package/platform/types/components/aws/function.d.ts +1755 -0
  410. package/platform/types/components/aws/function.d.ts.map +1 -0
  411. package/platform/types/components/aws/helpers/apigateway-account.d.ts +3 -0
  412. package/platform/types/components/aws/helpers/apigateway-account.d.ts.map +1 -0
  413. package/platform/types/components/aws/helpers/apigatewayv2-domain.d.ts +144 -0
  414. package/platform/types/components/aws/helpers/apigatewayv2-domain.d.ts.map +1 -0
  415. package/platform/types/components/aws/helpers/arn.d.ts +51 -0
  416. package/platform/types/components/aws/helpers/arn.d.ts.map +1 -0
  417. package/platform/types/components/aws/helpers/bootstrap.d.ts +13 -0
  418. package/platform/types/components/aws/helpers/bootstrap.d.ts.map +1 -0
  419. package/platform/types/components/aws/helpers/client.d.ts +7 -0
  420. package/platform/types/components/aws/helpers/client.d.ts.map +1 -0
  421. package/platform/types/components/aws/helpers/container-builder.d.ts +4 -0
  422. package/platform/types/components/aws/helpers/container-builder.d.ts.map +1 -0
  423. package/platform/types/components/aws/helpers/custom-domain.d.ts +111 -0
  424. package/platform/types/components/aws/helpers/custom-domain.d.ts.map +1 -0
  425. package/platform/types/components/aws/helpers/event-source.d.ts +26 -0
  426. package/platform/types/components/aws/helpers/event-source.d.ts.map +1 -0
  427. package/platform/types/components/aws/helpers/fargate.d.ts +225 -0
  428. package/platform/types/components/aws/helpers/fargate.d.ts.map +1 -0
  429. package/platform/types/components/aws/helpers/function-builder.d.ts +14 -0
  430. package/platform/types/components/aws/helpers/function-builder.d.ts.map +1 -0
  431. package/platform/types/components/aws/helpers/function-code.d.ts +80 -0
  432. package/platform/types/components/aws/helpers/function-code.d.ts.map +1 -0
  433. package/platform/types/components/aws/helpers/function-part.d.ts +61 -0
  434. package/platform/types/components/aws/helpers/function-part.d.ts.map +1 -0
  435. package/platform/types/components/aws/helpers/function-permission.d.ts +17 -0
  436. package/platform/types/components/aws/helpers/function-permission.d.ts.map +1 -0
  437. package/platform/types/components/aws/helpers/load-balancer-args.d.ts +40 -0
  438. package/platform/types/components/aws/helpers/load-balancer-args.d.ts.map +1 -0
  439. package/platform/types/components/aws/helpers/load-balancer.d.ts +9 -0
  440. package/platform/types/components/aws/helpers/load-balancer.d.ts.map +1 -0
  441. package/platform/types/components/aws/helpers/provider.d.ts +3 -0
  442. package/platform/types/components/aws/helpers/provider.d.ts.map +1 -0
  443. package/platform/types/components/aws/helpers/queue-policy.d.ts +11 -0
  444. package/platform/types/components/aws/helpers/queue-policy.d.ts.map +1 -0
  445. package/platform/types/components/aws/helpers/rds.d.ts +98 -0
  446. package/platform/types/components/aws/helpers/rds.d.ts.map +1 -0
  447. package/platform/types/components/aws/helpers/site-builder.d.ts +4 -0
  448. package/platform/types/components/aws/helpers/site-builder.d.ts.map +1 -0
  449. package/platform/types/components/aws/helpers/subscriber.d.ts +6 -0
  450. package/platform/types/components/aws/helpers/subscriber.d.ts.map +1 -0
  451. package/platform/types/components/aws/helpers/vpc.d.ts +14 -0
  452. package/platform/types/components/aws/helpers/vpc.d.ts.map +1 -0
  453. package/platform/types/components/aws/https-redirect.d.ts +38 -0
  454. package/platform/types/components/aws/https-redirect.d.ts.map +1 -0
  455. package/platform/types/components/aws/iam-edit.d.ts +39 -0
  456. package/platform/types/components/aws/iam-edit.d.ts.map +1 -0
  457. package/platform/types/components/aws/index.d.ts +56 -0
  458. package/platform/types/components/aws/index.d.ts.map +1 -0
  459. package/platform/types/components/aws/kinesis-stream-lambda-subscriber.d.ts +49 -0
  460. package/platform/types/components/aws/kinesis-stream-lambda-subscriber.d.ts.map +1 -0
  461. package/platform/types/components/aws/kinesis-stream.d.ts +254 -0
  462. package/platform/types/components/aws/kinesis-stream.d.ts.map +1 -0
  463. package/platform/types/components/aws/linkable.d.ts +17 -0
  464. package/platform/types/components/aws/linkable.d.ts.map +1 -0
  465. package/platform/types/components/aws/logging.d.ts +26 -0
  466. package/platform/types/components/aws/logging.d.ts.map +1 -0
  467. package/platform/types/components/aws/microvm.d.ts +439 -0
  468. package/platform/types/components/aws/microvm.d.ts.map +1 -0
  469. package/platform/types/components/aws/mysql.d.ts +525 -0
  470. package/platform/types/components/aws/mysql.d.ts.map +1 -0
  471. package/platform/types/components/aws/nextjs.d.ts +534 -0
  472. package/platform/types/components/aws/nextjs.d.ts.map +1 -0
  473. package/platform/types/components/aws/nuxt.d.ts +480 -0
  474. package/platform/types/components/aws/nuxt.d.ts.map +1 -0
  475. package/platform/types/components/aws/open-search.d.ts +306 -0
  476. package/platform/types/components/aws/open-search.d.ts.map +1 -0
  477. package/platform/types/components/aws/opencontrol.d.ts +169 -0
  478. package/platform/types/components/aws/opencontrol.d.ts.map +1 -0
  479. package/platform/types/components/aws/permission.d.ts +80 -0
  480. package/platform/types/components/aws/permission.d.ts.map +1 -0
  481. package/platform/types/components/aws/postgres-v1.d.ts +328 -0
  482. package/platform/types/components/aws/postgres-v1.d.ts.map +1 -0
  483. package/platform/types/components/aws/postgres.d.ts +529 -0
  484. package/platform/types/components/aws/postgres.d.ts.map +1 -0
  485. package/platform/types/components/aws/providers/bucket-files.d.ts +18 -0
  486. package/platform/types/components/aws/providers/bucket-files.d.ts.map +1 -0
  487. package/platform/types/components/aws/providers/distribution-deployment-waiter.d.ts +13 -0
  488. package/platform/types/components/aws/providers/distribution-deployment-waiter.d.ts.map +1 -0
  489. package/platform/types/components/aws/providers/distribution-invalidation.d.ts +11 -0
  490. package/platform/types/components/aws/providers/distribution-invalidation.d.ts.map +1 -0
  491. package/platform/types/components/aws/providers/function-environment-update.d.ts +33 -0
  492. package/platform/types/components/aws/providers/function-environment-update.d.ts.map +1 -0
  493. package/platform/types/components/aws/providers/hosted-zone-lookup.d.ts +11 -0
  494. package/platform/types/components/aws/providers/hosted-zone-lookup.d.ts.map +1 -0
  495. package/platform/types/components/aws/providers/kv-keys.d.ts +11 -0
  496. package/platform/types/components/aws/providers/kv-keys.d.ts.map +1 -0
  497. package/platform/types/components/aws/providers/kv-routes-update.d.ts +11 -0
  498. package/platform/types/components/aws/providers/kv-routes-update.d.ts.map +1 -0
  499. package/platform/types/components/aws/providers/microvm-image-prune.d.ts +35 -0
  500. package/platform/types/components/aws/providers/microvm-image-prune.d.ts.map +1 -0
  501. package/platform/types/components/aws/providers/origin-access-control.d.ts +8 -0
  502. package/platform/types/components/aws/providers/origin-access-control.d.ts.map +1 -0
  503. package/platform/types/components/aws/providers/rds-role-lookup.d.ts +8 -0
  504. package/platform/types/components/aws/providers/rds-role-lookup.d.ts.map +1 -0
  505. package/platform/types/components/aws/providers/vector-table.d.ts +12 -0
  506. package/platform/types/components/aws/providers/vector-table.d.ts.map +1 -0
  507. package/platform/types/components/aws/queue-lambda-subscriber.d.ts +53 -0
  508. package/platform/types/components/aws/queue-lambda-subscriber.d.ts.map +1 -0
  509. package/platform/types/components/aws/queue.d.ts +494 -0
  510. package/platform/types/components/aws/queue.d.ts.map +1 -0
  511. package/platform/types/components/aws/react.d.ts +407 -0
  512. package/platform/types/components/aws/react.d.ts.map +1 -0
  513. package/platform/types/components/aws/realtime-lambda-subscriber.d.ts +53 -0
  514. package/platform/types/components/aws/realtime-lambda-subscriber.d.ts.map +1 -0
  515. package/platform/types/components/aws/realtime.d.ts +237 -0
  516. package/platform/types/components/aws/realtime.d.ts.map +1 -0
  517. package/platform/types/components/aws/redis-v1.d.ts +348 -0
  518. package/platform/types/components/aws/redis-v1.d.ts.map +1 -0
  519. package/platform/types/components/aws/redis.d.ts +545 -0
  520. package/platform/types/components/aws/redis.d.ts.map +1 -0
  521. package/platform/types/components/aws/remix.d.ts +408 -0
  522. package/platform/types/components/aws/remix.d.ts.map +1 -0
  523. package/platform/types/components/aws/router-base-route.d.ts +28 -0
  524. package/platform/types/components/aws/router-base-route.d.ts.map +1 -0
  525. package/platform/types/components/aws/router-bucket-route.d.ts +29 -0
  526. package/platform/types/components/aws/router-bucket-route.d.ts.map +1 -0
  527. package/platform/types/components/aws/router-url-route.d.ts +28 -0
  528. package/platform/types/components/aws/router-url-route.d.ts.map +1 -0
  529. package/platform/types/components/aws/router.d.ts +1754 -0
  530. package/platform/types/components/aws/router.d.ts.map +1 -0
  531. package/platform/types/components/aws/service-v1.d.ts +78 -0
  532. package/platform/types/components/aws/service-v1.d.ts.map +1 -0
  533. package/platform/types/components/aws/service.d.ts +1756 -0
  534. package/platform/types/components/aws/service.d.ts.map +1 -0
  535. package/platform/types/components/aws/sns-topic-lambda-subscriber.d.ts +53 -0
  536. package/platform/types/components/aws/sns-topic-lambda-subscriber.d.ts.map +1 -0
  537. package/platform/types/components/aws/sns-topic-queue-subscriber.d.ts +55 -0
  538. package/platform/types/components/aws/sns-topic-queue-subscriber.d.ts.map +1 -0
  539. package/platform/types/components/aws/sns-topic.d.ts +394 -0
  540. package/platform/types/components/aws/sns-topic.d.ts.map +1 -0
  541. package/platform/types/components/aws/solid-start.d.ts +399 -0
  542. package/platform/types/components/aws/solid-start.d.ts.map +1 -0
  543. package/platform/types/components/aws/ssr-site.d.ts +895 -0
  544. package/platform/types/components/aws/ssr-site.d.ts.map +1 -0
  545. package/platform/types/components/aws/static-site.d.ts +744 -0
  546. package/platform/types/components/aws/static-site.d.ts.map +1 -0
  547. package/platform/types/components/aws/step-functions/choice.d.ts +73 -0
  548. package/platform/types/components/aws/step-functions/choice.d.ts.map +1 -0
  549. package/platform/types/components/aws/step-functions/fail.d.ts +63 -0
  550. package/platform/types/components/aws/step-functions/fail.d.ts.map +1 -0
  551. package/platform/types/components/aws/step-functions/map.d.ts +236 -0
  552. package/platform/types/components/aws/step-functions/map.d.ts.map +1 -0
  553. package/platform/types/components/aws/step-functions/parallel.d.ts +127 -0
  554. package/platform/types/components/aws/step-functions/parallel.d.ts.map +1 -0
  555. package/platform/types/components/aws/step-functions/pass.d.ts +39 -0
  556. package/platform/types/components/aws/step-functions/pass.d.ts.map +1 -0
  557. package/platform/types/components/aws/step-functions/state.d.ts +231 -0
  558. package/platform/types/components/aws/step-functions/state.d.ts.map +1 -0
  559. package/platform/types/components/aws/step-functions/succeed.d.ts +26 -0
  560. package/platform/types/components/aws/step-functions/succeed.d.ts.map +1 -0
  561. package/platform/types/components/aws/step-functions/task.d.ts +485 -0
  562. package/platform/types/components/aws/step-functions/task.d.ts.map +1 -0
  563. package/platform/types/components/aws/step-functions/wait.d.ts +91 -0
  564. package/platform/types/components/aws/step-functions/wait.d.ts.map +1 -0
  565. package/platform/types/components/aws/step-functions.d.ts +478 -0
  566. package/platform/types/components/aws/step-functions.d.ts.map +1 -0
  567. package/platform/types/components/aws/svelte-kit.d.ts +456 -0
  568. package/platform/types/components/aws/svelte-kit.d.ts.map +1 -0
  569. package/platform/types/components/aws/takeover/alb.d.ts +2 -0
  570. package/platform/types/components/aws/takeover/alb.d.ts.map +1 -0
  571. package/platform/types/components/aws/takeover/apigatewayv2.d.ts +2 -0
  572. package/platform/types/components/aws/takeover/apigatewayv2.d.ts.map +1 -0
  573. package/platform/types/components/aws/takeover/app-sync.d.ts +2 -0
  574. package/platform/types/components/aws/takeover/app-sync.d.ts.map +1 -0
  575. package/platform/types/components/aws/takeover/aurora.d.ts +2 -0
  576. package/platform/types/components/aws/takeover/aurora.d.ts.map +1 -0
  577. package/platform/types/components/aws/takeover/bucket.d.ts +2 -0
  578. package/platform/types/components/aws/takeover/bucket.d.ts.map +1 -0
  579. package/platform/types/components/aws/takeover/bus.d.ts +2 -0
  580. package/platform/types/components/aws/takeover/bus.d.ts.map +1 -0
  581. package/platform/types/components/aws/takeover/cognito-user-pool.d.ts +2 -0
  582. package/platform/types/components/aws/takeover/cognito-user-pool.d.ts.map +1 -0
  583. package/platform/types/components/aws/takeover/cron-v2.d.ts +2 -0
  584. package/platform/types/components/aws/takeover/cron-v2.d.ts.map +1 -0
  585. package/platform/types/components/aws/takeover/dsql.d.ts +2 -0
  586. package/platform/types/components/aws/takeover/dsql.d.ts.map +1 -0
  587. package/platform/types/components/aws/takeover/dynamo.d.ts +2 -0
  588. package/platform/types/components/aws/takeover/dynamo.d.ts.map +1 -0
  589. package/platform/types/components/aws/takeover/efs.d.ts +2 -0
  590. package/platform/types/components/aws/takeover/efs.d.ts.map +1 -0
  591. package/platform/types/components/aws/takeover/function.d.ts +2 -0
  592. package/platform/types/components/aws/takeover/function.d.ts.map +1 -0
  593. package/platform/types/components/aws/takeover/helpers.d.ts +16 -0
  594. package/platform/types/components/aws/takeover/helpers.d.ts.map +1 -0
  595. package/platform/types/components/aws/takeover/index.d.ts +28 -0
  596. package/platform/types/components/aws/takeover/index.d.ts.map +1 -0
  597. package/platform/types/components/aws/takeover/mysql.d.ts +2 -0
  598. package/platform/types/components/aws/takeover/mysql.d.ts.map +1 -0
  599. package/platform/types/components/aws/takeover/postgres.d.ts +2 -0
  600. package/platform/types/components/aws/takeover/postgres.d.ts.map +1 -0
  601. package/platform/types/components/aws/takeover/queue.d.ts +2 -0
  602. package/platform/types/components/aws/takeover/queue.d.ts.map +1 -0
  603. package/platform/types/components/aws/takeover/redis.d.ts +2 -0
  604. package/platform/types/components/aws/takeover/redis.d.ts.map +1 -0
  605. package/platform/types/components/aws/takeover/service.d.ts +2 -0
  606. package/platform/types/components/aws/takeover/service.d.ts.map +1 -0
  607. package/platform/types/components/aws/takeover/sns-topic.d.ts +2 -0
  608. package/platform/types/components/aws/takeover/sns-topic.d.ts.map +1 -0
  609. package/platform/types/components/aws/takeover/task.d.ts +2 -0
  610. package/platform/types/components/aws/takeover/task.d.ts.map +1 -0
  611. package/platform/types/components/aws/tan-stack-start.d.ts +359 -0
  612. package/platform/types/components/aws/tan-stack-start.d.ts.map +1 -0
  613. package/platform/types/components/aws/task.d.ts +342 -0
  614. package/platform/types/components/aws/task.d.ts.map +1 -0
  615. package/platform/types/components/aws/v5/alb.d.ts +177 -0
  616. package/platform/types/components/aws/v5/alb.d.ts.map +1 -0
  617. package/platform/types/components/aws/v5/apigatewayv2.d.ts +482 -0
  618. package/platform/types/components/aws/v5/apigatewayv2.d.ts.map +1 -0
  619. package/platform/types/components/aws/v5/app-sync.d.ts +424 -0
  620. package/platform/types/components/aws/v5/app-sync.d.ts.map +1 -0
  621. package/platform/types/components/aws/v5/aurora.d.ts +459 -0
  622. package/platform/types/components/aws/v5/aurora.d.ts.map +1 -0
  623. package/platform/types/components/aws/v5/bucket.d.ts +578 -0
  624. package/platform/types/components/aws/v5/bucket.d.ts.map +1 -0
  625. package/platform/types/components/aws/v5/bus.d.ts +255 -0
  626. package/platform/types/components/aws/v5/bus.d.ts.map +1 -0
  627. package/platform/types/components/aws/v5/cluster.d.ts +167 -0
  628. package/platform/types/components/aws/v5/cluster.d.ts.map +1 -0
  629. package/platform/types/components/aws/v5/cognito-user-pool-client.d.ts +69 -0
  630. package/platform/types/components/aws/v5/cognito-user-pool-client.d.ts.map +1 -0
  631. package/platform/types/components/aws/v5/cognito-user-pool.d.ts +396 -0
  632. package/platform/types/components/aws/v5/cognito-user-pool.d.ts.map +1 -0
  633. package/platform/types/components/aws/v5/cron-v2.d.ts +206 -0
  634. package/platform/types/components/aws/v5/cron-v2.d.ts.map +1 -0
  635. package/platform/types/components/aws/v5/dsql.d.ts +453 -0
  636. package/platform/types/components/aws/v5/dsql.d.ts.map +1 -0
  637. package/platform/types/components/aws/v5/dynamo.d.ts +328 -0
  638. package/platform/types/components/aws/v5/dynamo.d.ts.map +1 -0
  639. package/platform/types/components/aws/v5/efs.d.ts +178 -0
  640. package/platform/types/components/aws/v5/efs.d.ts.map +1 -0
  641. package/platform/types/components/aws/v5/function.d.ts +582 -0
  642. package/platform/types/components/aws/v5/function.d.ts.map +1 -0
  643. package/platform/types/components/aws/v5/index.d.ts +27 -0
  644. package/platform/types/components/aws/v5/index.d.ts.map +1 -0
  645. package/platform/types/components/aws/v5/mysql.d.ts +347 -0
  646. package/platform/types/components/aws/v5/mysql.d.ts.map +1 -0
  647. package/platform/types/components/aws/v5/postgres.d.ts +348 -0
  648. package/platform/types/components/aws/v5/postgres.d.ts.map +1 -0
  649. package/platform/types/components/aws/v5/queue.d.ts +190 -0
  650. package/platform/types/components/aws/v5/queue.d.ts.map +1 -0
  651. package/platform/types/components/aws/v5/redis.d.ts +214 -0
  652. package/platform/types/components/aws/v5/redis.d.ts.map +1 -0
  653. package/platform/types/components/aws/v5/service.d.ts +1347 -0
  654. package/platform/types/components/aws/v5/service.d.ts.map +1 -0
  655. package/platform/types/components/aws/v5/sns-topic.d.ts +226 -0
  656. package/platform/types/components/aws/v5/sns-topic.d.ts.map +1 -0
  657. package/platform/types/components/aws/v5/task.d.ts +346 -0
  658. package/platform/types/components/aws/v5/task.d.ts.map +1 -0
  659. package/platform/types/components/aws/vector.d.ts +163 -0
  660. package/platform/types/components/aws/vector.d.ts.map +1 -0
  661. package/platform/types/components/aws/vpc-v1.d.ts +208 -0
  662. package/platform/types/components/aws/vpc-v1.d.ts.map +1 -0
  663. package/platform/types/components/aws/vpc.d.ts +491 -0
  664. package/platform/types/components/aws/vpc.d.ts.map +1 -0
  665. package/platform/types/components/aws/workflow.d.ts +331 -0
  666. package/platform/types/components/aws/workflow.d.ts.map +1 -0
  667. package/platform/types/components/base/base-site.d.ts +53 -0
  668. package/platform/types/components/base/base-site.d.ts.map +1 -0
  669. package/platform/types/components/base/base-ssr-site.d.ts +13 -0
  670. package/platform/types/components/base/base-ssr-site.d.ts.map +1 -0
  671. package/platform/types/components/base/base-static-site.d.ts +199 -0
  672. package/platform/types/components/base/base-static-site.d.ts.map +1 -0
  673. package/platform/types/components/cloudflare/account-id.d.ts +2 -0
  674. package/platform/types/components/cloudflare/account-id.d.ts.map +1 -0
  675. package/platform/types/components/cloudflare/ai.d.ts +68 -0
  676. package/platform/types/components/cloudflare/ai.d.ts.map +1 -0
  677. package/platform/types/components/cloudflare/astro.d.ts +249 -0
  678. package/platform/types/components/cloudflare/astro.d.ts.map +1 -0
  679. package/platform/types/components/cloudflare/auth.d.ts +22 -0
  680. package/platform/types/components/cloudflare/auth.d.ts.map +1 -0
  681. package/platform/types/components/cloudflare/binding.d.ts +109 -0
  682. package/platform/types/components/cloudflare/binding.d.ts.map +1 -0
  683. package/platform/types/components/cloudflare/bucket.d.ts +98 -0
  684. package/platform/types/components/cloudflare/bucket.d.ts.map +1 -0
  685. package/platform/types/components/cloudflare/cron.d.ts +151 -0
  686. package/platform/types/components/cloudflare/cron.d.ts.map +1 -0
  687. package/platform/types/components/cloudflare/d1.d.ts +142 -0
  688. package/platform/types/components/cloudflare/d1.d.ts.map +1 -0
  689. package/platform/types/components/cloudflare/dns.d.ts +100 -0
  690. package/platform/types/components/cloudflare/dns.d.ts.map +1 -0
  691. package/platform/types/components/cloudflare/durable-object.d.ts +125 -0
  692. package/platform/types/components/cloudflare/durable-object.d.ts.map +1 -0
  693. package/platform/types/components/cloudflare/experimental/index.d.ts +4 -0
  694. package/platform/types/components/cloudflare/experimental/index.d.ts.map +1 -0
  695. package/platform/types/components/cloudflare/experimental/solid-start.d.ts +219 -0
  696. package/platform/types/components/cloudflare/experimental/solid-start.d.ts.map +1 -0
  697. package/platform/types/components/cloudflare/experimental/static-site.d.ts +3 -0
  698. package/platform/types/components/cloudflare/experimental/static-site.d.ts.map +1 -0
  699. package/platform/types/components/cloudflare/helpers/compatibility.d.ts +21 -0
  700. package/platform/types/components/cloudflare/helpers/compatibility.d.ts.map +1 -0
  701. package/platform/types/components/cloudflare/helpers/fetch.d.ts +19 -0
  702. package/platform/types/components/cloudflare/helpers/fetch.d.ts.map +1 -0
  703. package/platform/types/components/cloudflare/helpers/validation.d.ts +15 -0
  704. package/platform/types/components/cloudflare/helpers/validation.d.ts.map +1 -0
  705. package/platform/types/components/cloudflare/helpers/worker-builder.d.ts +10 -0
  706. package/platform/types/components/cloudflare/helpers/worker-builder.d.ts.map +1 -0
  707. package/platform/types/components/cloudflare/helpers/wrangler.d.ts +31 -0
  708. package/platform/types/components/cloudflare/helpers/wrangler.d.ts.map +1 -0
  709. package/platform/types/components/cloudflare/hyperdrive.d.ts +302 -0
  710. package/platform/types/components/cloudflare/hyperdrive.d.ts.map +1 -0
  711. package/platform/types/components/cloudflare/index.d.ts +25 -0
  712. package/platform/types/components/cloudflare/index.d.ts.map +1 -0
  713. package/platform/types/components/cloudflare/kv.d.ts +140 -0
  714. package/platform/types/components/cloudflare/kv.d.ts.map +1 -0
  715. package/platform/types/components/cloudflare/providers/dns-record.d.ts +21 -0
  716. package/platform/types/components/cloudflare/providers/dns-record.d.ts.map +1 -0
  717. package/platform/types/components/cloudflare/providers/kv-data.d.ts +23 -0
  718. package/platform/types/components/cloudflare/providers/kv-data.d.ts.map +1 -0
  719. package/platform/types/components/cloudflare/providers/worker-assets.d.ts +19 -0
  720. package/platform/types/components/cloudflare/providers/worker-assets.d.ts.map +1 -0
  721. package/platform/types/components/cloudflare/providers/worker-placement.d.ts +27 -0
  722. package/platform/types/components/cloudflare/providers/worker-placement.d.ts.map +1 -0
  723. package/platform/types/components/cloudflare/providers/worker-script.d.ts +23 -0
  724. package/platform/types/components/cloudflare/providers/worker-script.d.ts.map +1 -0
  725. package/platform/types/components/cloudflare/providers/worker-url.d.ts +24 -0
  726. package/platform/types/components/cloudflare/providers/worker-url.d.ts.map +1 -0
  727. package/platform/types/components/cloudflare/providers/zone-lookup.d.ts +22 -0
  728. package/platform/types/components/cloudflare/providers/zone-lookup.d.ts.map +1 -0
  729. package/platform/types/components/cloudflare/queue-worker-subscriber.d.ts +122 -0
  730. package/platform/types/components/cloudflare/queue-worker-subscriber.d.ts.map +1 -0
  731. package/platform/types/components/cloudflare/queue.d.ts +235 -0
  732. package/platform/types/components/cloudflare/queue.d.ts.map +1 -0
  733. package/platform/types/components/cloudflare/rate-limit.d.ts +117 -0
  734. package/platform/types/components/cloudflare/rate-limit.d.ts.map +1 -0
  735. package/platform/types/components/cloudflare/react-router.d.ts +262 -0
  736. package/platform/types/components/cloudflare/react-router.d.ts.map +1 -0
  737. package/platform/types/components/cloudflare/ssr-site.d.ts +60 -0
  738. package/platform/types/components/cloudflare/ssr-site.d.ts.map +1 -0
  739. package/platform/types/components/cloudflare/static-site-v2.d.ts +302 -0
  740. package/platform/types/components/cloudflare/static-site-v2.d.ts.map +1 -0
  741. package/platform/types/components/cloudflare/static-site.d.ts +270 -0
  742. package/platform/types/components/cloudflare/static-site.d.ts.map +1 -0
  743. package/platform/types/components/cloudflare/tan-stack-start.d.ts +259 -0
  744. package/platform/types/components/cloudflare/tan-stack-start.d.ts.map +1 -0
  745. package/platform/types/components/cloudflare/worker.d.ts +483 -0
  746. package/platform/types/components/cloudflare/worker.d.ts.map +1 -0
  747. package/platform/types/components/cloudflare/workflow.d.ts +248 -0
  748. package/platform/types/components/cloudflare/workflow.d.ts.map +1 -0
  749. package/platform/types/components/component.d.ts +67 -0
  750. package/platform/types/components/component.d.ts.map +1 -0
  751. package/platform/types/components/core.d.ts +16 -0
  752. package/platform/types/components/core.d.ts.map +1 -0
  753. package/platform/types/components/cpu.d.ts +3 -0
  754. package/platform/types/components/cpu.d.ts.map +1 -0
  755. package/platform/types/components/dns.d.ts +63 -0
  756. package/platform/types/components/dns.d.ts.map +1 -0
  757. package/platform/types/components/duration.d.ts +9 -0
  758. package/platform/types/components/duration.d.ts.map +1 -0
  759. package/platform/types/components/error.d.ts +4 -0
  760. package/platform/types/components/error.d.ts.map +1 -0
  761. package/platform/types/components/esbuild.d.ts +3 -0
  762. package/platform/types/components/esbuild.d.ts.map +1 -0
  763. package/platform/types/components/experimental/dev-command.d.ts +99 -0
  764. package/platform/types/components/experimental/dev-command.d.ts.map +1 -0
  765. package/platform/types/components/experimental/index.d.ts +2 -0
  766. package/platform/types/components/experimental/index.d.ts.map +1 -0
  767. package/platform/types/components/groups.d.ts +6 -0
  768. package/platform/types/components/groups.d.ts.map +1 -0
  769. package/platform/types/components/index.d.ts +5 -0
  770. package/platform/types/components/index.d.ts.map +1 -0
  771. package/platform/types/components/input.d.ts +3 -0
  772. package/platform/types/components/input.d.ts.map +1 -0
  773. package/platform/types/components/link.d.ts +41 -0
  774. package/platform/types/components/link.d.ts.map +1 -0
  775. package/platform/types/components/linkable.d.ts +301 -0
  776. package/platform/types/components/linkable.d.ts.map +1 -0
  777. package/platform/types/components/naming-rules.d.ts +32 -0
  778. package/platform/types/components/naming-rules.d.ts.map +1 -0
  779. package/platform/types/components/naming.d.ts +21 -0
  780. package/platform/types/components/naming.d.ts.map +1 -0
  781. package/platform/types/components/parts-component.d.ts +241 -0
  782. package/platform/types/components/parts-component.d.ts.map +1 -0
  783. package/platform/types/components/parts.d.ts +194 -0
  784. package/platform/types/components/parts.d.ts.map +1 -0
  785. package/platform/types/components/path.d.ts +2 -0
  786. package/platform/types/components/path.d.ts.map +1 -0
  787. package/platform/types/components/rpc/rpc.d.ts +19 -0
  788. package/platform/types/components/rpc/rpc.d.ts.map +1 -0
  789. package/platform/types/components/secret.d.ts +123 -0
  790. package/platform/types/components/secret.d.ts.map +1 -0
  791. package/platform/types/components/size.d.ts +5 -0
  792. package/platform/types/components/size.d.ts.map +1 -0
  793. package/platform/types/components/takeover.d.ts +88 -0
  794. package/platform/types/components/takeover.d.ts.map +1 -0
  795. package/platform/types/components/transform.d.ts +34 -0
  796. package/platform/types/components/transform.d.ts.map +1 -0
  797. package/platform/types/components/vercel/account-id.d.ts +2 -0
  798. package/platform/types/components/vercel/account-id.d.ts.map +1 -0
  799. package/platform/types/components/vercel/dns.d.ts +73 -0
  800. package/platform/types/components/vercel/dns.d.ts.map +1 -0
  801. package/platform/types/components/vercel/index.d.ts +3 -0
  802. package/platform/types/components/vercel/index.d.ts.map +1 -0
  803. package/platform/types/components/vercel/providers/dns-record.d.ts +15 -0
  804. package/platform/types/components/vercel/providers/dns-record.d.ts.map +1 -0
  805. package/platform/types/config.d.ts +1437 -0
  806. package/platform/types/config.d.ts.map +1 -0
  807. package/platform/types/global-aliases.d.ts +37 -0
  808. package/platform/types/global.d.ts +374 -0
  809. package/platform/types/internal.d.ts +18 -0
  810. package/platform/types/runtime/worker/unenv.d.ts +14 -0
  811. package/platform/types/testing/global.d.ts +11 -0
  812. package/platform/types/testing/global.d.ts.map +1 -0
  813. package/platform/types/testing/index.d.ts +80 -0
  814. package/platform/types/testing/index.d.ts.map +1 -0
  815. package/platform/types/testing/mock.d.ts +136 -0
  816. package/platform/types/testing/mock.d.ts.map +1 -0
  817. package/platform/types/testing/vitest.d.ts +19 -0
  818. package/platform/types/testing/vitest.d.ts.map +1 -0
  819. package/platform/types/util/compare-semver.d.ts +4 -0
  820. package/platform/types/util/compare-semver.d.ts.map +1 -0
  821. package/platform/types/util/fs.d.ts +5 -0
  822. package/platform/types/util/fs.d.ts.map +1 -0
  823. package/platform/types/util/lazy.d.ts +2 -0
  824. package/platform/types/util/lazy.d.ts.map +1 -0
  825. package/platform/types/util/minify.d.ts +2 -0
  826. package/platform/types/util/minify.d.ts.map +1 -0
  827. package/platform/types/util/package.d.ts +10 -0
  828. package/platform/types/util/package.d.ts.map +1 -0
  829. package/platform/types/util/semaphore.d.ts +9 -0
  830. package/platform/types/util/semaphore.d.ts.map +1 -0
  831. package/platform/types/util/warn.d.ts +2 -0
  832. package/platform/types/util/warn.d.ts.map +1 -0
@@ -0,0 +1,3281 @@
1
+ import path from "path";
2
+ import {
3
+ ComponentResourceOptions,
4
+ Output,
5
+ all,
6
+ interpolate,
7
+ output,
8
+ } from "@pulumi/pulumi";
9
+ import { asset } from "@pulumi/pulumi";
10
+ import { iam, lambda } from "@pulumi/aws";
11
+ import crypto from "crypto";
12
+ import { Component, Transform, transform } from "../component";
13
+ import { Link } from "../link";
14
+ import type { Input } from "../input";
15
+ import { Cdn, CdnArgs } from "./cdn";
16
+ import { cloudfront, cloudwatch, wafv2 } from "@pulumi/aws";
17
+ import { useProvider } from "./helpers/provider";
18
+ import { hashStringToPrettyString, physicalName } from "../naming";
19
+ import { Bucket } from "./bucket";
20
+ import { OriginAccessControl } from "./providers/origin-access-control";
21
+ import { VisibleError } from "../error";
22
+ import { RouterUrlRoute } from "./router-url-route";
23
+ import { RouterBucketRoute } from "./router-bucket-route";
24
+ import { DurationSeconds, toSeconds } from "../duration";
25
+ import { FunctionArn } from "./function.js";
26
+ import { parseLambdaEdgeArn } from "./helpers/arn";
27
+ import { Size, toMBs } from "../size";
28
+ import { RETENTION } from "./logging";
29
+ import { minify } from "../../util/minify";
30
+
31
+ interface InlineUrlRouteArgs extends InlineBaseRouteArgs {
32
+ /**
33
+ * The destination URL.
34
+ *
35
+ * @example
36
+ *
37
+ * ```js
38
+ * {
39
+ * routes: {
40
+ * "/api/*": {
41
+ * url: "https://example.com"
42
+ * }
43
+ * }
44
+ * }
45
+ * ```
46
+ */
47
+ url: Input<string>;
48
+ /**
49
+ * Rewrite the request path.
50
+ *
51
+ * @example
52
+ *
53
+ * By default, if the route path is `/api/*` and a request comes in for `/api/users/profile`,
54
+ * the request path the destination sees is `/api/users/profile`.
55
+ *
56
+ * If you want to serve the route from the root, you can rewrite the request path to
57
+ * `/users/profile`.
58
+ *
59
+ * ```js
60
+ * {
61
+ * routes: {
62
+ * "/api/*": {
63
+ * url: "https://api.example.com",
64
+ * rewrite: {
65
+ * regex: "^/api/(.*)$",
66
+ * to: "/$1"
67
+ * }
68
+ * }
69
+ * }
70
+ * }
71
+ * ```
72
+ */
73
+ rewrite?: Input<{
74
+ /**
75
+ * The regex to match the request path.
76
+ */
77
+ regex: Input<string>;
78
+ /**
79
+ * The replacement for the matched path.
80
+ */
81
+ to: Input<string>;
82
+ }>;
83
+ }
84
+
85
+ interface InlineRouterBucketRouteArgs extends InlineBaseRouteArgs {
86
+ /**
87
+ * A bucket to route to.
88
+ *
89
+ * :::note
90
+ * You need to let CloudFront `access` the bucket.
91
+ * :::
92
+ *
93
+ * @example
94
+ *
95
+ * For example, let's say you have a bucket that gives CloudFront `access`.
96
+ *
97
+ * ```ts title="sst.config.ts" {2}
98
+ * const myBucket = new sst.aws.Bucket("MyBucket", {
99
+ * access: "cloudfront"
100
+ * });
101
+ * ```
102
+ *
103
+ * You can then this directly as the destination for the route.
104
+ *
105
+ * ```js
106
+ * {
107
+ * routes: {
108
+ * "/files/*": {
109
+ * bucket: myBucket
110
+ * }
111
+ * }
112
+ * }
113
+ * ```
114
+ *
115
+ * Or if you have an existing bucket, you can pass in its regional domain.
116
+ *
117
+ * ```js
118
+ * {
119
+ * routes: {
120
+ * "/files/*": {
121
+ * bucket: "my-bucket.s3.us-east-1.amazonaws.com"
122
+ * }
123
+ * }
124
+ * }
125
+ * ```
126
+ */
127
+ bucket?: Input<Bucket | string>;
128
+ /**
129
+ * Rewrite the request path.
130
+ *
131
+ * @example
132
+ *
133
+ * By default, if the route path is `/files/*` and a request comes in for `/files/logo.png`,
134
+ * the request path the destination sees is `/files/logo.png`. In the case of a bucket route,
135
+ * the file `logo.png` is served from the `files` directory in the bucket.
136
+ *
137
+ * If you want to serve the file from the root of the bucket, you can rewrite
138
+ * the request path to `/logo.png`.
139
+ *
140
+ * ```js
141
+ * {
142
+ * routes: {
143
+ * "/files/*": {
144
+ * bucket: myBucket,
145
+ * rewrite: {
146
+ * regex: "^/files/(.*)$",
147
+ * to: "/$1"
148
+ * }
149
+ * }
150
+ * }
151
+ * }
152
+ * ```
153
+ */
154
+ rewrite?: Input<{
155
+ /**
156
+ * The regex to match the request path.
157
+ */
158
+ regex: Input<string>;
159
+ /**
160
+ * The replacement for the matched path.
161
+ */
162
+ to: Input<string>;
163
+ }>;
164
+ }
165
+
166
+ interface InlineBaseRouteArgs {
167
+ /**
168
+ * The cache policy to use for the route.
169
+ *
170
+ * @default CloudFront's managed CachingOptimized policy
171
+ * @example
172
+ * ```js
173
+ * {
174
+ * routes: {
175
+ * "/files/*": {
176
+ * url: "https://example.com"
177
+ * cachePolicy: "658327ea-f89d-4fab-a63d-7e88639e58f6"
178
+ * }
179
+ * }
180
+ * }
181
+ * ```
182
+ */
183
+ cachePolicy?: Input<string>;
184
+ /**
185
+ * Configure CloudFront Functions to customize the behavior of HTTP requests and responses at the edge.
186
+ */
187
+ edge?: {
188
+ /**
189
+ * Configure the viewer request function.
190
+ *
191
+ * The viewer request function can be used to modify incoming requests before they
192
+ * reach your origin server. For example, you can redirect users, rewrite URLs,
193
+ * or add headers.
194
+ */
195
+ viewerRequest?: Input<{
196
+ /**
197
+ * The code to inject into the viewer request function.
198
+ *
199
+ * By default, a viewer request function is created to add the `x-forwarded-host`
200
+ * header. The given code will be injected at the end of this function.
201
+ *
202
+ * ```js
203
+ * async function handler(event) {
204
+ * // Default behavior code
205
+ *
206
+ * // User injected code
207
+ *
208
+ * return event.request;
209
+ * }
210
+ * ```
211
+ *
212
+ * @example
213
+ * To add a custom header to all requests.
214
+ *
215
+ * ```js
216
+ * {
217
+ * routes: {
218
+ * "/api/*": {
219
+ * url: "https://example.com"
220
+ * edge: {
221
+ * viewerRequest: {
222
+ * injection: `event.request.headers["x-foo"] = { value: "bar" };`
223
+ * }
224
+ * }
225
+ * }
226
+ * }
227
+ * }
228
+ * ```
229
+ */
230
+ injection: Input<string>;
231
+ /**
232
+ * The KeyValueStore to associate with the viewer request function.
233
+ *
234
+ * @example
235
+ * ```js
236
+ * {
237
+ * routes: {
238
+ * "/api/*": {
239
+ * url: "https://example.com"
240
+ * edge: {
241
+ * viewerRequest: {
242
+ * kvStore: "arn:aws:cloudfront::123456789012:key-value-store/my-store"
243
+ * }
244
+ * }
245
+ * }
246
+ * }
247
+ * }
248
+ * ```
249
+ */
250
+ kvStore?: Input<string>;
251
+ /**
252
+ * @deprecated Use `kvStore` instead because CloudFront Functions only support one KeyValueStore.
253
+ */
254
+ kvStores?: Input<Input<string>[]>;
255
+ }>;
256
+ /**
257
+ * Configure the viewer response function.
258
+ *
259
+ * The viewer response function can be used to modify outgoing responses before
260
+ * they are sent to the client. For example, you can add security headers or change
261
+ * the response status code.
262
+ *
263
+ * By default, no viewer response function is set. A new function will be created
264
+ * with the provided code.
265
+ *
266
+ * @example
267
+ * Add a custom header to all responses
268
+ * ```js
269
+ * {
270
+ * routes: {
271
+ * "/api/*": {
272
+ * url: "https://example.com"
273
+ * edge: {
274
+ * viewerResponse: {
275
+ * injection: `event.response.headers["x-foo"] = { value: "bar" };`
276
+ * }
277
+ * }
278
+ * }
279
+ * }
280
+ * }
281
+ * ```
282
+ */
283
+ viewerResponse?: Input<{
284
+ /**
285
+ * The code to inject into the viewer response function.
286
+ *
287
+ * By default, no viewer response function is set. A new function will be created with
288
+ * the provided code.
289
+ *
290
+ * ```js
291
+ * async function handler(event) {
292
+ * // User injected code
293
+ *
294
+ * return event.response;
295
+ * }
296
+ * ```
297
+ *
298
+ * @example
299
+ * To add a custom header to all responses.
300
+ *
301
+ * ```js
302
+ * {
303
+ * routes: {
304
+ * "/api/*": {
305
+ * url: "https://example.com"
306
+ * edge: {
307
+ * viewerResponse: {
308
+ * injection: `event.response.headers["x-foo"] = { value: "bar" };`
309
+ * }
310
+ * }
311
+ * }
312
+ * }
313
+ * }
314
+ * ```
315
+ */
316
+ injection: Input<string>;
317
+ /**
318
+ * The KeyValueStore to associate with the viewer response function.
319
+ *
320
+ * @example
321
+ * ```js
322
+ * {
323
+ * routes: {
324
+ * "/api/*": {
325
+ * url: "https://example.com"
326
+ * edge: {
327
+ * viewerResponse: {
328
+ * kvStore: "arn:aws:cloudfront::123456789012:key-value-store/my-store"
329
+ * }
330
+ * }
331
+ * }
332
+ * }
333
+ * }
334
+ * ```
335
+ */
336
+ kvStore?: Input<string>;
337
+ /**
338
+ * @deprecated Use `kvStore` instead because CloudFront Functions only support one KeyValueStore.
339
+ */
340
+ kvStores?: Input<Input<string>[]>;
341
+ }>;
342
+ };
343
+ }
344
+
345
+ interface RouteArgs {
346
+ /**
347
+ * The number of times that CloudFront attempts to connect to the origin. Must be
348
+ * between 1 and 3.
349
+ * @default 3
350
+ * @example
351
+ * ```js
352
+ * {
353
+ * connectionAttempts: 1
354
+ * }
355
+ * ```
356
+ */
357
+ connectionAttempts?: Input<number>;
358
+ /**
359
+ * The number of seconds that CloudFront waits before timing out and closing the
360
+ * connection to the origin. Must be between 1 and 10 seconds.
361
+ * @default `"10 seconds"`
362
+ * @example
363
+ * ```js
364
+ * {
365
+ * connectionTimeout: "3 seconds"
366
+ * }
367
+ * ```
368
+ */
369
+ connectionTimeout?: Input<DurationSeconds>;
370
+ }
371
+
372
+ export interface RouterUrlRouteArgs extends RouteArgs {
373
+ /**
374
+ * Rewrite the request path.
375
+ *
376
+ * @example
377
+ *
378
+ * If the route path is `/api/*` and a request comes in for `/api/users/profile`,
379
+ * the request path the destination sees is `/api/users/profile`.
380
+ *
381
+ * If you want to serve the route from the root, you can rewrite the request
382
+ * path to `/users/profile`.
383
+ *
384
+ * ```js
385
+ * {
386
+ * rewrite: {
387
+ * regex: "^/api/(.*)$",
388
+ * to: "/$1"
389
+ * }
390
+ * }
391
+ * ```
392
+ */
393
+ rewrite?: Input<{
394
+ /**
395
+ * The regex to match the request path.
396
+ */
397
+ regex: Input<string>;
398
+ /**
399
+ * The replacement for the matched path.
400
+ */
401
+ to: Input<string>;
402
+ }>;
403
+ /**
404
+ * The number of seconds that CloudFront waits for a response after routing a
405
+ * request to the destination. Must be between 1 and 60 seconds.
406
+ *
407
+ * When compared to the `connectionTimeout`, this is the total time for the
408
+ * request.
409
+ *
410
+ * @default `"20 seconds"`
411
+ * @example
412
+ * ```js
413
+ * {
414
+ * readTimeout: "60 seconds"
415
+ * }
416
+ * ```
417
+ */
418
+ readTimeout?: Input<DurationSeconds>;
419
+ /**
420
+ * The number of seconds that CloudFront should try to maintain the connection
421
+ * to the destination after receiving the last packet of the response. Must be
422
+ * between 1 and 60 seconds
423
+ * @default `"5 seconds"`
424
+ * @example
425
+ * ```js
426
+ * {
427
+ * keepAliveTimeout: "10 seconds"
428
+ * }
429
+ * ```
430
+ */
431
+ keepAliveTimeout?: Input<DurationSeconds>;
432
+ }
433
+
434
+ export interface RouterBucketRouteArgs extends RouteArgs {
435
+ /**
436
+ * Rewrite the request path.
437
+ *
438
+ * @example
439
+ *
440
+ * If the route path is `/files/*` and a request comes in for `/files/logo.png`,
441
+ * the request path the destination sees is `/files/logo.png`.
442
+ *
443
+ * If you want to serve the file from the root of the bucket, you can rewrite
444
+ * the request path to `/logo.png`.
445
+ *
446
+ * ```js
447
+ * {
448
+ * rewrite: {
449
+ * regex: "^/files/(.*)$",
450
+ * to: "/$1"
451
+ * }
452
+ * }
453
+ * ```
454
+ */
455
+ rewrite?: Input<{
456
+ /**
457
+ * The regex to match the request path.
458
+ */
459
+ regex: Input<string>;
460
+ /**
461
+ * The replacement for the matched path.
462
+ */
463
+ to: Input<string>;
464
+ }>;
465
+ }
466
+
467
+ export interface WafLoggingArgs {
468
+ /**
469
+ * Filter which requests are logged.
470
+ *
471
+ * - `"all"` logs every request evaluated by the WAF.
472
+ * - `"blocked"` only logs requests that were blocked.
473
+ *
474
+ * @default `"all"`
475
+ * @example
476
+ * ```js
477
+ * {
478
+ * waf: {
479
+ * logging: {
480
+ * include: "blocked"
481
+ * }
482
+ * }
483
+ * }
484
+ * ```
485
+ */
486
+ include?: Input<"all" | "blocked">;
487
+ /**
488
+ * The duration the WAF logs are kept in CloudWatch.
489
+ *
490
+ * @default `"1 month"`
491
+ * @example
492
+ * ```js
493
+ * {
494
+ * waf: {
495
+ * logging: {
496
+ * retention: "3 months"
497
+ * }
498
+ * }
499
+ * }
500
+ * ```
501
+ */
502
+ retention?: Input<keyof typeof RETENTION>;
503
+ /**
504
+ * Configure which parts of the request are redacted from the logs. Redacted
505
+ * fields are replaced with `REDACTED` in the log output.
506
+ *
507
+ * By default, the query string and the `cookie` and `authorization` headers
508
+ * are redacted since they commonly contain PII or credentials.
509
+ *
510
+ * Set to `false` to disable all redaction.
511
+ *
512
+ * @default `{ queryString: true, headers: ["cookie", "authorization"] }`
513
+ * @example
514
+ *
515
+ * Disable all redaction.
516
+ *
517
+ * ```js
518
+ * {
519
+ * waf: {
520
+ * logging: {
521
+ * redact: false
522
+ * }
523
+ * }
524
+ * }
525
+ * ```
526
+ *
527
+ * Redact everything.
528
+ *
529
+ * ```js
530
+ * {
531
+ * waf: {
532
+ * logging: {
533
+ * redact: {
534
+ * queryString: true,
535
+ * uriPath: true,
536
+ * method: true,
537
+ * headers: ["cookie", "authorization"]
538
+ * }
539
+ * }
540
+ * }
541
+ * }
542
+ * ```
543
+ */
544
+ redact?: Input<
545
+ | false
546
+ | {
547
+ /**
548
+ * Redact the query string from the logs. The query string is the
549
+ * part of a URL after the `?` and can contain tokens, user IDs,
550
+ * or other sensitive parameters.
551
+ * @default `true`
552
+ */
553
+ queryString?: Input<boolean>;
554
+ /**
555
+ * Redact the URI path from the logs. The URI path identifies the
556
+ * resource being accessed, like `/users/123/profile`.
557
+ * @default `false`
558
+ */
559
+ uriPath?: Input<boolean>;
560
+ /**
561
+ * Redact the HTTP method from the logs (GET, POST, etc.).
562
+ * @default `false`
563
+ */
564
+ method?: Input<boolean>;
565
+ /**
566
+ * A list of header names to redact from the logs. Must be lowercase.
567
+ * @default `["cookie", "authorization"]`
568
+ * @example
569
+ * ```js
570
+ * {
571
+ * headers: ["cookie", "authorization", "x-api-key"]
572
+ * }
573
+ * ```
574
+ */
575
+ headers?: Input<string[]>;
576
+ }
577
+ >;
578
+ }
579
+
580
+ export interface WafArgs {
581
+ /**
582
+ * The rate limit per IP address. Requests from an IP that exceed this limit
583
+ * within a 5-minute window will be blocked.
584
+ *
585
+ * @default `2000`
586
+ * @example
587
+ * ```js
588
+ * {
589
+ * waf: {
590
+ * rateLimitPerIp: 1000
591
+ * }
592
+ * }
593
+ * ```
594
+ */
595
+ rateLimitPerIp?: Input<number>;
596
+ /**
597
+ * Configure which AWS managed rule groups to enable.
598
+ *
599
+ * @default All managed rules enabled
600
+ * @example
601
+ * ```js
602
+ * {
603
+ * waf: {
604
+ * managedRules: {
605
+ * coreRuleSet: true,
606
+ * knownBadInputs: true,
607
+ * sqlInjection: false
608
+ * }
609
+ * }
610
+ * }
611
+ * ```
612
+ */
613
+ managedRules?: Input<{
614
+ /**
615
+ * Enable the AWS Core Rule Set (CRS) which provides protection against common
616
+ * web vulnerabilities.
617
+ * @default `true`
618
+ */
619
+ coreRuleSet?: Input<boolean>;
620
+ /**
621
+ * Enable protection against known bad inputs, including Log4j vulnerabilities.
622
+ * @default `true`
623
+ */
624
+ knownBadInputs?: Input<boolean>;
625
+ /**
626
+ * Enable SQL injection protection.
627
+ * @default `true`
628
+ */
629
+ sqlInjection?: Input<boolean>;
630
+ }>;
631
+ /**
632
+ * Configure WAF logging to CloudWatch. When set to `true`, all WAF-evaluated
633
+ * requests are logged with a 1-month retention. Or pass in an object to
634
+ * customize what is logged, how long logs are retained, and which fields
635
+ * are redacted.
636
+ *
637
+ * :::tip
638
+ * WAF logging is off by default. Enabling it will incur additional
639
+ * [CloudWatch costs](https://aws.amazon.com/cloudwatch/pricing/) depending
640
+ * on log volume.
641
+ * :::
642
+ *
643
+ * @default Logging is disabled
644
+ * @example
645
+ *
646
+ * Enable with defaults.
647
+ *
648
+ * ```js
649
+ * {
650
+ * waf: {
651
+ * logging: true
652
+ * }
653
+ * }
654
+ * ```
655
+ *
656
+ * Only log blocked requests.
657
+ *
658
+ * ```js
659
+ * {
660
+ * waf: {
661
+ * logging: {
662
+ * include: "blocked",
663
+ * retention: "3 months"
664
+ * }
665
+ * }
666
+ * }
667
+ * ```
668
+ *
669
+ * Redact sensitive fields.
670
+ *
671
+ * ```js
672
+ * {
673
+ * waf: {
674
+ * logging: {
675
+ * redact: {
676
+ * queryString: true,
677
+ * headers: ["cookie"]
678
+ * }
679
+ * }
680
+ * }
681
+ * }
682
+ * ```
683
+ */
684
+ logging?: Input<boolean | WafLoggingArgs>;
685
+ }
686
+
687
+ export interface RouterArgs {
688
+ /**
689
+ * Set a custom domain for your Router.
690
+ *
691
+ * Automatically manages domains hosted on AWS Route 53, Cloudflare, and Vercel. For other
692
+ * providers, you'll need to pass in a `cert` that validates domain ownership and add the
693
+ * DNS records.
694
+ *
695
+ * :::tip
696
+ * Built-in support for AWS Route 53, Cloudflare, and Vercel. And manual setup for other
697
+ * providers.
698
+ * :::
699
+ *
700
+ * @example
701
+ *
702
+ * By default this assumes the domain is hosted on Route 53.
703
+ *
704
+ * ```js
705
+ * {
706
+ * domain: "example.com"
707
+ * }
708
+ * ```
709
+ *
710
+ * For domains hosted on Cloudflare.
711
+ *
712
+ * ```js
713
+ * {
714
+ * domain: {
715
+ * name: "example.com",
716
+ * dns: sst.cloudflare.dns()
717
+ * }
718
+ * }
719
+ * ```
720
+ *
721
+ * Specify a `www.` version of the custom domain.
722
+ *
723
+ * ```js
724
+ * {
725
+ * domain: {
726
+ * name: "domain.com",
727
+ * redirects: ["www.domain.com"]
728
+ * }
729
+ * }
730
+ * ```
731
+ */
732
+ domain?: CdnArgs["domain"];
733
+ /**
734
+ * A map of routes to their destinations.
735
+ *
736
+ * @deprecated Use the `route` and `routeBucket` functions instead. These
737
+ * functions provide a more flexible API for routing to URLs and buckets. They
738
+ * also allow routing based on both domain and path patterns.
739
+ *
740
+ * The _key_ is the route path and the _value_ can be:
741
+ *
742
+ * - The destination URL as a string
743
+ * - Or, an object with
744
+ * - Args for a URL route
745
+ * - Args for a bucket route
746
+ *
747
+ * :::note
748
+ * All routes need to start with `/`.
749
+ * :::
750
+ *
751
+ * For example, you can set the destination as a URL.
752
+ *
753
+ * ```ts
754
+ * {
755
+ * routes: {
756
+ * "/*": "https://example.com"
757
+ * }
758
+ * }
759
+ * ```
760
+ *
761
+ * Or, you can route to a bucket.
762
+ *
763
+ * ```ts
764
+ * {
765
+ * routes: {
766
+ * "/files/*": {
767
+ * bucket: myBucket
768
+ * }
769
+ * }
770
+ * }
771
+ * ```
772
+ *
773
+ * When router receives a request, the requested path is compared with path patterns
774
+ * in the order they are listed. The first match determines which URL the
775
+ * request is routed to.
776
+ *
777
+ * :::tip[Default Route]
778
+ * The `/*` route is a default or catch-all route.
779
+ * :::
780
+ *
781
+ * The `/*` route is a _default_ route, meaning that if no routes match, the `/*` route will be used. It does not matter where the `/*` route is listed in the routes object.
782
+ *
783
+ * :::note
784
+ * If you don't have a `/*` route, you'll get a 404 error for any requests that don't match a route.
785
+ * :::
786
+ *
787
+ * Suppose you have the following three routes.
788
+ *
789
+ * ```js
790
+ * {
791
+ * routes: {
792
+ * "/api/*.json": "https://example1.com",
793
+ * "/api/*": "https://example2.com",
794
+ * "/*.xml": "https://example3.com",
795
+ * }
796
+ * }
797
+ * ```
798
+ *
799
+ * A request to `/api/sample.xml` will match `/api/*` first and route to it; even though it matches `/*.xml`.
800
+ *
801
+ * However for this case, a request to `/api/users` will route to `/api/*` even though it comes after `/*`. This is because the `/*` route is the default route.
802
+ *
803
+ * ```js
804
+ * {
805
+ * routes: {
806
+ * "/*": "myapp.com",
807
+ * "/api/*": myFunction.url
808
+ * }
809
+ * }
810
+ * ```
811
+ *
812
+ * You can also customize the route behavior with injecting some code into the CloudFront
813
+ * Functions. To do so, pass in an object, with the destination as the `url`.
814
+ *
815
+ * ```ts
816
+ * {
817
+ * routes: {
818
+ * "/*": {
819
+ * url: "https://example.com",
820
+ * edge: {
821
+ * viewerRequest: {
822
+ * injection: `event.request.headers["x-foo"] = { value: "bar" };`
823
+ * }
824
+ * }
825
+ * }
826
+ * }
827
+ * }
828
+ * ```
829
+ *
830
+ * You can also `rewrite` the request path.
831
+ *
832
+ * ```ts
833
+ * {
834
+ * routes: {
835
+ * "/files/*": {
836
+ * bucket: myBucket,
837
+ * rewrite: {
838
+ * regex: "^/files/(.*)$",
839
+ * to: "/$1"
840
+ * }
841
+ * }
842
+ * }
843
+ * }
844
+ * ```
845
+ */
846
+ routes?: Input<
847
+ Record<
848
+ string,
849
+ Input<string | InlineUrlRouteArgs | InlineRouterBucketRouteArgs>
850
+ >
851
+ >;
852
+ /**
853
+ * Configure CloudFront Functions to customize the behavior of HTTP requests and responses at the edge.
854
+ */
855
+ edge?: {
856
+ /**
857
+ * Configure the viewer request function.
858
+ *
859
+ * The viewer request function can be used to modify incoming requests before they
860
+ * reach your origin server. For example, you can redirect users, rewrite URLs,
861
+ * or add headers.
862
+ */
863
+ viewerRequest?: Input<{
864
+ /**
865
+ * The code to inject into the viewer request function.
866
+ *
867
+ * By default, a viewer request function is created to:
868
+ * - Disable CloudFront default URL if custom domain is set.
869
+ * - Add the `x-forwarded-host` header.
870
+ * - Route requests to the corresponding target based on the domain and request path.
871
+ *
872
+ * The given code will be injected at the beginning of this function.
873
+ *
874
+ * ```js
875
+ * async function handler(event) {
876
+ * // User injected code
877
+ *
878
+ * // Default behavior code
879
+ *
880
+ * return event.request;
881
+ * }
882
+ * ```
883
+ *
884
+ * @example
885
+ * To add a custom header to all requests.
886
+ *
887
+ * ```js
888
+ * {
889
+ * edge: {
890
+ * viewerRequest: {
891
+ * injection: `event.request.headers["x-foo"] = { value: "bar" };`
892
+ * }
893
+ * }
894
+ * }
895
+ * ```
896
+ */
897
+ injection: Input<string>;
898
+ /**
899
+ * The KeyValueStore to associate with the viewer request function.
900
+ *
901
+ * @example
902
+ * ```js
903
+ * {
904
+ * edge: {
905
+ * viewerRequest: {
906
+ * kvStore: "arn:aws:cloudfront::123456789012:key-value-store/my-store"
907
+ * }
908
+ * }
909
+ * }
910
+ * ```
911
+ */
912
+ kvStore?: Input<string>;
913
+ }>;
914
+ /**
915
+ * Configure the viewer response function.
916
+ *
917
+ * The viewer response function can be used to modify outgoing responses before
918
+ * they are sent to the client. For example, you can add security headers or change
919
+ * the response status code.
920
+ *
921
+ * By default, no viewer response function is set. A new function will be created
922
+ * with the provided code.
923
+ */
924
+ viewerResponse?: Input<{
925
+ /**
926
+ * The code to inject into the viewer response function.
927
+ *
928
+ * ```js
929
+ * async function handler(event) {
930
+ * // User injected code
931
+ *
932
+ * return event.response;
933
+ * }
934
+ * ```
935
+ *
936
+ * @example
937
+ * To add a custom header to all responses.
938
+ *
939
+ * ```js
940
+ * {
941
+ * edge: {
942
+ * viewerResponse: {
943
+ * injection: `event.response.headers["x-foo"] = { value: "bar" };`
944
+ * }
945
+ * }
946
+ * }
947
+ * ```
948
+ */
949
+ injection: Input<string>;
950
+ /**
951
+ * The KeyValueStore to associate with the viewer response function.
952
+ *
953
+ * @example
954
+ * ```js
955
+ * {
956
+ * edge: {
957
+ * viewerResponse: {
958
+ * kvStore: "arn:aws:cloudfront::123456789012:key-value-store/my-store"
959
+ * }
960
+ * }
961
+ * }
962
+ * ```
963
+ */
964
+ kvStore?: Input<string>;
965
+ }>;
966
+ };
967
+ /**
968
+ * Configure how the CloudFront cache invalidations are handled.
969
+ * :::tip
970
+ * You get 1000 free invalidations per month. After that you pay $0.005 per invalidation path. [Read more here](https://aws.amazon.com/cloudfront/pricing/).
971
+ * :::
972
+ * @default Invalidation is turned off
973
+ * @example
974
+ * Setting this to `true` will invalidate all paths. It's equivalent
975
+ * to passing in `{ paths: ["/*"] }`.
976
+ *
977
+ * ```js
978
+ * {
979
+ * invalidation: true
980
+ * }
981
+ * ```
982
+ */
983
+ invalidation?: Input<
984
+ | boolean
985
+ | {
986
+ /**
987
+ * Configure if `sst deploy` should wait for the CloudFront cache invalidation to finish.
988
+ *
989
+ * :::tip
990
+ * For non-prod environments it might make sense to pass in `false`.
991
+ * :::
992
+ *
993
+ * Waiting for this process to finish ensures that new content will be available after the deploy finishes. However, this process can sometimes take more than 5 mins.
994
+ * @default `false`
995
+ * @example
996
+ * ```js
997
+ * {
998
+ * invalidation: {
999
+ * wait: true
1000
+ * }
1001
+ * }
1002
+ * ```
1003
+ */
1004
+ wait?: Input<boolean>;
1005
+ /**
1006
+ * A token used to determine if the cache should be invalidated. If the
1007
+ * token is the same as the previous deployment, the cache will not be invalidated.
1008
+ *
1009
+ * You can set this to a hash that's computed on every deploy. So if the hash
1010
+ * changes, the cache will be invalidated.
1011
+ *
1012
+ * @default A unique value is auto-generated on each deploy
1013
+ * @example
1014
+ * ```js
1015
+ * {
1016
+ * invalidation: {
1017
+ * token: "foo123"
1018
+ * }
1019
+ * }
1020
+ * ```
1021
+ */
1022
+ token?: Input<string>;
1023
+ /**
1024
+ * Specify an array of glob pattern of paths to invalidate.
1025
+ *
1026
+ * :::note
1027
+ * Each glob pattern counts as a single invalidation. Whereas, invalidating
1028
+ * `/*` counts as a single invalidation.
1029
+ * :::
1030
+ * @default `["/*"]`
1031
+ * @example
1032
+ * Invalidate the `index.html` and all files under the `products/` route.
1033
+ * ```js
1034
+ * {
1035
+ * invalidation: {
1036
+ * paths: ["/index.html", "/products/*"]
1037
+ * }
1038
+ * }
1039
+ * ```
1040
+ * This counts as two invalidations.
1041
+ */
1042
+ paths?: Input<Input<string>[]>;
1043
+ }
1044
+ >;
1045
+
1046
+ /**
1047
+ * Configure Lambda function URL protection through CloudFront Origin Access Control.
1048
+ *
1049
+ * When set, all Functions and SSR sites routing through this Router automatically
1050
+ * inherit the protection mode.
1051
+ *
1052
+ * @default `"none"`
1053
+ *
1054
+ * The available options are:
1055
+ * - `"none"`: Lambda URLs are publicly accessible.
1056
+ * - `"oac"`: Lambda URLs protected by CloudFront Origin Access Control. Requires
1057
+ * manual `x-amz-content-sha256` header for POST requests.
1058
+ * - `"oac-with-edge-signing"`: Full protection with automatic header signing via
1059
+ * Lambda@Edge. Works with external webhooks and callbacks. Higher cost and latency
1060
+ * but works out of the box.
1061
+ *
1062
+ * :::note
1063
+ * Switching from `"none"` to `"oac"` or `"oac-with-edge-signing"` may cause brief
1064
+ * 403 errors (~10-60s) during deployment while CloudFront edge nodes pick up the new
1065
+ * signing configuration. For zero-disruption upgrades, set `protection` when first
1066
+ * creating the Router.
1067
+ * :::
1068
+ *
1069
+ * :::note
1070
+ * When using `"oac-with-edge-signing"`, request bodies are limited to 1MB due to
1071
+ * Lambda@Edge payload limits. For file uploads larger than 1MB, consider using
1072
+ * presigned S3 URLs or the `"oac"` mode with manual header signing.
1073
+ * :::
1074
+ *
1075
+ * :::note
1076
+ * When removing a stage that uses `"oac-with-edge-signing"`, deletion may take
1077
+ * 5-10 minutes while AWS removes the Lambda@Edge replicated functions from all
1078
+ * edge locations.
1079
+ * :::
1080
+ *
1081
+ * @example
1082
+ * ```js
1083
+ * {
1084
+ * protection: "oac"
1085
+ * }
1086
+ * ```
1087
+ *
1088
+ * @example
1089
+ * ```js
1090
+ * {
1091
+ * protection: "oac-with-edge-signing"
1092
+ * }
1093
+ * ```
1094
+ *
1095
+ * @example
1096
+ * ```js
1097
+ * // Custom Lambda@Edge configuration
1098
+ * {
1099
+ * protection: {
1100
+ * mode: "oac-with-edge-signing",
1101
+ * edgeFunction: {
1102
+ * memory: "256 MB",
1103
+ * timeout: "10 seconds"
1104
+ * }
1105
+ * }
1106
+ * }
1107
+ * ```
1108
+ */
1109
+ protection?: Input<
1110
+ | "none"
1111
+ | "oac"
1112
+ | "oac-with-edge-signing"
1113
+ | {
1114
+ mode: "oac-with-edge-signing";
1115
+ edgeFunction?: {
1116
+ /**
1117
+ * Custom Lambda@Edge function ARN to use for request signing.
1118
+ * If provided, this function will be used instead of creating a new one.
1119
+ * Must be a qualified ARN (with version) and deployed in us-east-1.
1120
+ */
1121
+ arn?: Input<FunctionArn>;
1122
+ /**
1123
+ * Memory size for the auto-created Lambda@Edge function.
1124
+ * Only used when arn is not provided.
1125
+ * @default `"128 MB"`
1126
+ */
1127
+ memory?: Input<Size>;
1128
+ /**
1129
+ * Timeout for the auto-created Lambda@Edge function.
1130
+ * Only used when arn is not provided.
1131
+ * @default `"5 seconds"`
1132
+ */
1133
+ timeout?: Input<DurationSeconds>;
1134
+ };
1135
+ }
1136
+ >;
1137
+ /**
1138
+ * Enable AWS WAF (Web Application Firewall) to protect your Router from common
1139
+ * web exploits and bots.
1140
+ *
1141
+ * :::tip
1142
+ * WAF provides protection against SQL injection, cross-site scripting (XSS),
1143
+ * and other common attacks.
1144
+ * :::
1145
+ *
1146
+ * @default WAF is disabled
1147
+ * @example
1148
+ *
1149
+ * Enable with sensible defaults.
1150
+ *
1151
+ * ```js
1152
+ * {
1153
+ * waf: true
1154
+ * }
1155
+ * ```
1156
+ *
1157
+ * Or customize the configuration.
1158
+ *
1159
+ * ```js
1160
+ * {
1161
+ * waf: {
1162
+ * rateLimitPerIp: 1000,
1163
+ * managedRules: {
1164
+ * coreRuleSet: true,
1165
+ * knownBadInputs: true,
1166
+ * sqlInjection: true
1167
+ * }
1168
+ * }
1169
+ * }
1170
+ * ```
1171
+ */
1172
+ waf?: Input<boolean | WafArgs>;
1173
+ /**
1174
+ * [Transform](/docs/components#transform) how this component creates its underlying
1175
+ * resources.
1176
+ */
1177
+ transform?: {
1178
+ /**
1179
+ * Transform the Cache Policy that's attached to each CloudFront behavior.
1180
+ */
1181
+ cachePolicy?: Transform<cloudfront.CachePolicyArgs>;
1182
+ /**
1183
+ * Transform the CloudFront CDN resource.
1184
+ */
1185
+ cdn?: Transform<CdnArgs>;
1186
+ /**
1187
+ * Transform the WAF WebACL resource.
1188
+ */
1189
+ waf?: Transform<wafv2.WebAclArgs>;
1190
+ /**
1191
+ * Transform the CloudWatch LogGroup resource used for WAF logs.
1192
+ */
1193
+ wafLogGroup?: Transform<cloudwatch.LogGroupArgs>;
1194
+ /**
1195
+ * Transform the WAF WebACL logging configuration resource.
1196
+ */
1197
+ wafLogging?: Transform<wafv2.WebAclLoggingConfigurationArgs>;
1198
+ };
1199
+ /**
1200
+ * @internal
1201
+ */
1202
+ _skipHint?: boolean;
1203
+ }
1204
+
1205
+ interface RouterRef {
1206
+ ref: boolean;
1207
+ distributionID: Input<string>;
1208
+ }
1209
+
1210
+ /**
1211
+ * The `Router` component lets you use a CloudFront distribution to direct
1212
+ * requests to various parts of your application like:
1213
+ *
1214
+ * - A URL
1215
+ * - A function
1216
+ * - A frontend
1217
+ * - An S3 bucket
1218
+ *
1219
+ * @example
1220
+ *
1221
+ * #### Minimal example
1222
+ *
1223
+ * ```ts title="sst.config.ts"
1224
+ * new sst.aws.Router("MyRouter");
1225
+ * ```
1226
+ *
1227
+ * #### Add a custom domain
1228
+ *
1229
+ * ```ts {2} title="sst.config.ts"
1230
+ * new sst.aws.Router("MyRouter", {
1231
+ * domain: "myapp.com"
1232
+ * });
1233
+ * ```
1234
+ *
1235
+ * #### Sharing the router across stages
1236
+ *
1237
+ * ```ts title="sst.config.ts"
1238
+ * const router = $app.stage === "production"
1239
+ * ? new sst.aws.Router("MyRouter", {
1240
+ * domain: {
1241
+ * name: "example.com",
1242
+ * aliases: ["*.example.com"]
1243
+ * }
1244
+ * })
1245
+ * : sst.aws.Router.get("MyRouter", "E1XWRGCYGTFB7Z");
1246
+ * ```
1247
+ *
1248
+ * #### Route to a URL
1249
+ *
1250
+ * ```ts title="sst.config.ts" {3}
1251
+ * const router = new sst.aws.Router("MyRouter");
1252
+ *
1253
+ * router.route("/", "https://some-external-service.com");
1254
+ * ```
1255
+ *
1256
+ * #### Route to an S3 bucket
1257
+ *
1258
+ * ```ts title="sst.config.ts" {2,6}
1259
+ * const myBucket = new sst.aws.Bucket("MyBucket", {
1260
+ * access: "cloudfront"
1261
+ * });
1262
+ *
1263
+ * const router = new sst.aws.Router("MyRouter");
1264
+ * router.routeBucket("/files", myBucket);
1265
+ * ```
1266
+ *
1267
+ * You need to allow CloudFront to access the bucket by setting the `access` prop
1268
+ * on the bucket.
1269
+ *
1270
+ * #### Route to a function
1271
+ *
1272
+ * ```ts title="sst.config.ts" {8-11}
1273
+ * const router = new sst.aws.Router("MyRouter", {
1274
+ * domain: "example.com"
1275
+ * });
1276
+ *
1277
+ * const myFunction = new sst.aws.Function("MyFunction", {
1278
+ * handler: "src/api.handler",
1279
+ * url: {
1280
+ * router: {
1281
+ * instance: router,
1282
+ * path: "/api"
1283
+ * }
1284
+ * }
1285
+ * });
1286
+ * ```
1287
+ *
1288
+ * Setting the route through the function, instead of `router.route()` makes
1289
+ * it so that `myFunction.url` gives you the URL based on the Router domain.
1290
+ *
1291
+ * #### Route to a frontend
1292
+ *
1293
+ * ```ts title="sst.config.ts" {4-6}
1294
+ * const router = new sst.aws.Router("MyRouter");
1295
+ *
1296
+ * const mySite = new sst.aws.Nextjs("MyWeb", {
1297
+ * router: {
1298
+ * instance: router
1299
+ * }
1300
+ * });
1301
+ * ```
1302
+ *
1303
+ * Setting the route through the site, instead of `router.route()` makes
1304
+ * it so that `mySite.url` gives you the URL based on the Router domain.
1305
+ *
1306
+ * #### Route to a frontend on a path
1307
+ *
1308
+ * ```ts title="sst.config.ts" {4-7}
1309
+ * const router = new sst.aws.Router("MyRouter");
1310
+ *
1311
+ * new sst.aws.Nextjs("MyWeb", {
1312
+ * router: {
1313
+ * instance: router,
1314
+ * path: "/docs"
1315
+ * }
1316
+ * });
1317
+ * ```
1318
+ *
1319
+ * If you are routing to a path, you'll need to configure the base path in your
1320
+ * frontend app as well. [Learn more](/docs/component/aws/nextjs/#router).
1321
+ *
1322
+ * #### Route to a frontend on a subdomain
1323
+ *
1324
+ * ```ts title="sst.config.ts" {4,9-12}
1325
+ * const router = new sst.aws.Router("MyRouter", {
1326
+ * domain: {
1327
+ * name: "example.com",
1328
+ * aliases: ["*.example.com"]
1329
+ * }
1330
+ * });
1331
+ *
1332
+ * new sst.aws.Nextjs("MyWeb", {
1333
+ * router: {
1334
+ * instance: router,
1335
+ * domain: "docs.example.com"
1336
+ * }
1337
+ * });
1338
+ * ```
1339
+ *
1340
+ * We configure `*.example.com` as an alias so that we can route to a subdomain.
1341
+ *
1342
+ * #### How it works
1343
+ *
1344
+ * This uses a CloudFront KeyValueStore to store the routing data and a CloudFront
1345
+ * function to route the request. As routes are added, the store is updated.
1346
+ *
1347
+ * So when a request comes in, it does a lookup in the store and dynamically sets
1348
+ * the origin based on the routing data. For frontends, that have their server
1349
+ * functions deployed to multiple `regions`, it routes to the closest region based
1350
+ * on the user's location.
1351
+ *
1352
+ * You might notice a _placeholder.sst.dev_ behavior in CloudFront. This is not
1353
+ * used and is only there because CloudFront requires a default behavior.
1354
+ *
1355
+ * #### Limits
1356
+ *
1357
+ * There are some limits on this setup but it's managed by SST.
1358
+ *
1359
+ * - The CloudFront function can be a maximum of 10KB in size. But because all
1360
+ * the route data is stored in the KeyValueStore, the function can be kept small.
1361
+ * - Each value in the KeyValueStore needs to be less than 1KB. This component
1362
+ * splits the routes into multiple values to keep it under the limit.
1363
+ * - The KeyValueStore can be a maximum of 5MB. This is fairly large. But to
1364
+ * handle sites that have a lot of files, only top-level assets get individual
1365
+ * entries. Folders with prerendered routes are the exception: their files get
1366
+ * entries too, up to 1MB per site, so they don't hide server routes.
1367
+ */
1368
+ export class Router extends Component implements Link.Linkable {
1369
+ private constructorName: string;
1370
+ private constructorOpts: ComponentResourceOptions;
1371
+ private cdn: Output<Cdn>;
1372
+ private kvStoreArn?: Output<string>;
1373
+ private kvNamespace?: Output<string>;
1374
+ private hasInlineRoutes: Output<boolean>;
1375
+ private _protectionMode: Output<ProtectionConfig>;
1376
+
1377
+ constructor(
1378
+ name: string,
1379
+ args: RouterArgs = {},
1380
+ opts: ComponentResourceOptions = {},
1381
+ ) {
1382
+ super(__pulumiType, name, args, opts);
1383
+ const _refVersion = 2;
1384
+ const self = this;
1385
+ this.constructorName = name;
1386
+ this.constructorOpts = opts;
1387
+
1388
+ if (args && "ref" in args) {
1389
+ const ref = reference();
1390
+ this.cdn = output(ref.cdn);
1391
+ this.kvStoreArn = ref.kvStoreArn;
1392
+ this.kvNamespace = ref.kvNamespace;
1393
+ this.hasInlineRoutes = ref.hasInlineRoutes;
1394
+ this._protectionMode = ref.protection;
1395
+ registerOutputs();
1396
+ return;
1397
+ }
1398
+
1399
+ const hasInlineRoutes = args.routes !== undefined;
1400
+ const protection = normalizeProtection();
1401
+
1402
+ if (hasInlineRoutes) {
1403
+ protection.apply((p) => {
1404
+ if (p.mode !== "none")
1405
+ throw new VisibleError(
1406
+ `Cannot set "protection" on a Router with inline routes. Use lazy routes instead.`,
1407
+ );
1408
+ });
1409
+ }
1410
+
1411
+ const waf = createWaf();
1412
+ const wafArn = waf?.arn;
1413
+ const wafLogging = normalizeWafLogging();
1414
+ createWafLogging();
1415
+
1416
+ let cdn, kvStoreArn, kvNamespace;
1417
+ if (hasInlineRoutes) {
1418
+ cdn = handleInlineRoutes();
1419
+ } else {
1420
+ const r = handleLazyRoutes();
1421
+ cdn = output(r.distribution);
1422
+ kvStoreArn = r.kvStoreArn;
1423
+ kvNamespace = output(r.kvNamespace);
1424
+ }
1425
+
1426
+ this.cdn = cdn;
1427
+ this.kvStoreArn = kvStoreArn;
1428
+ this.kvNamespace = kvNamespace;
1429
+ this.hasInlineRoutes = output(hasInlineRoutes);
1430
+ this._protectionMode = protection;
1431
+ registerOutputs();
1432
+
1433
+ function reference() {
1434
+ const ref = args as unknown as RouterRef;
1435
+ const cdn = Cdn.get(`${name}Cdn`, ref.distributionID, { parent: self });
1436
+ const tags = cdn.nodes.distribution.tagsAll.apply((tags) => {
1437
+ if (tags?.["sst:ref:version"] !== _refVersion.toString()) {
1438
+ throw new VisibleError(
1439
+ [
1440
+ `There have been some minor changes to the "Router" component that's being referenced by "${name}".\n`,
1441
+ `To update, you'll need to redeploy the stage where the Router was created. And then redeploy this stage.`,
1442
+ ].join("\n"),
1443
+ );
1444
+ }
1445
+
1446
+ return {
1447
+ kvStoreArn: tags?.["sst:ref:kv"],
1448
+ kvNamespace: tags?.["sst:ref:kv-namespace"],
1449
+ hasInlineRoutes: tags?.["sst:ref:kv"] === undefined,
1450
+ protection: tags?.["sst:ref:protection"] ?? "none",
1451
+ };
1452
+ });
1453
+
1454
+ return {
1455
+ cdn,
1456
+ kvStoreArn: tags.kvStoreArn,
1457
+ kvNamespace: tags.kvNamespace,
1458
+ hasInlineRoutes: tags.hasInlineRoutes,
1459
+ protection: tags.protection.apply((p) => ({
1460
+ mode: p as ProtectionConfig["mode"],
1461
+ })),
1462
+ };
1463
+ }
1464
+
1465
+ function createWaf(): wafv2.WebAcl | undefined {
1466
+ if (!args.waf) return undefined;
1467
+
1468
+ const wafInput = output(args.waf);
1469
+ const config = wafInput.apply((waf) =>
1470
+ typeof waf === "boolean" || !waf ? {} : waf,
1471
+ );
1472
+ const rateLimitPerIp = config.apply((c) => c.rateLimitPerIp ?? 2000);
1473
+ const managedRules = config.apply((c) => c.managedRules ?? {});
1474
+ const enableCoreRuleSet = managedRules.apply(
1475
+ (m) => m.coreRuleSet !== false,
1476
+ );
1477
+ const enableKnownBadInputs = managedRules.apply(
1478
+ (m) => m.knownBadInputs !== false,
1479
+ );
1480
+ const enableSqlInjection = managedRules.apply(
1481
+ (m) => m.sqlInjection !== false,
1482
+ );
1483
+
1484
+ // Build rules array dynamically based on config
1485
+ const rules = all([
1486
+ rateLimitPerIp,
1487
+ enableCoreRuleSet,
1488
+ enableKnownBadInputs,
1489
+ enableSqlInjection,
1490
+ ]).apply(([rateLimit, coreRuleSet, knownBadInputs, sqlInjection]) => {
1491
+ const r: wafv2.WebAclArgs["rules"] = [];
1492
+ let priority = 0;
1493
+
1494
+ r.push({
1495
+ name: "RateLimitPerIP",
1496
+ priority: priority++,
1497
+ action: { block: {} },
1498
+ statement: {
1499
+ rateBasedStatement: {
1500
+ limit: rateLimit,
1501
+ aggregateKeyType: "IP",
1502
+ },
1503
+ },
1504
+ visibilityConfig: {
1505
+ cloudwatchMetricsEnabled: true,
1506
+ metricName: `${name}RateLimitPerIP`,
1507
+ sampledRequestsEnabled: true,
1508
+ },
1509
+ });
1510
+
1511
+ if (coreRuleSet) {
1512
+ r.push({
1513
+ name: "AWSManagedRulesCommonRuleSet",
1514
+ priority: priority++,
1515
+ overrideAction: { none: {} },
1516
+ statement: {
1517
+ managedRuleGroupStatement: {
1518
+ vendorName: "AWS",
1519
+ name: "AWSManagedRulesCommonRuleSet",
1520
+ // Set SizeRestrictions_BODY to COUNT to avoid blocking large request bodies
1521
+ ruleActionOverrides: [
1522
+ {
1523
+ name: "SizeRestrictions_BODY",
1524
+ actionToUse: { count: {} },
1525
+ },
1526
+ ],
1527
+ },
1528
+ },
1529
+ visibilityConfig: {
1530
+ cloudwatchMetricsEnabled: true,
1531
+ metricName: `${name}AWSManagedRulesCommonRuleSet`,
1532
+ sampledRequestsEnabled: true,
1533
+ },
1534
+ });
1535
+ }
1536
+
1537
+ if (knownBadInputs) {
1538
+ r.push({
1539
+ name: "AWSManagedRulesKnownBadInputsRuleSet",
1540
+ priority: priority++,
1541
+ overrideAction: { none: {} },
1542
+ statement: {
1543
+ managedRuleGroupStatement: {
1544
+ vendorName: "AWS",
1545
+ name: "AWSManagedRulesKnownBadInputsRuleSet",
1546
+ },
1547
+ },
1548
+ visibilityConfig: {
1549
+ cloudwatchMetricsEnabled: true,
1550
+ metricName: `${name}AWSManagedRulesKnownBadInputsRuleSet`,
1551
+ sampledRequestsEnabled: true,
1552
+ },
1553
+ });
1554
+ }
1555
+
1556
+ if (sqlInjection) {
1557
+ r.push({
1558
+ name: "AWSManagedRulesSQLiRuleSet",
1559
+ priority: priority++,
1560
+ overrideAction: { none: {} },
1561
+ statement: {
1562
+ managedRuleGroupStatement: {
1563
+ vendorName: "AWS",
1564
+ name: "AWSManagedRulesSQLiRuleSet",
1565
+ },
1566
+ },
1567
+ visibilityConfig: {
1568
+ cloudwatchMetricsEnabled: true,
1569
+ metricName: `${name}AWSManagedRulesSQLiRuleSet`,
1570
+ sampledRequestsEnabled: true,
1571
+ },
1572
+ });
1573
+ }
1574
+
1575
+ return r;
1576
+ });
1577
+
1578
+ // WAF must be created in us-east-1 for CloudFront
1579
+ return new wafv2.WebAcl(
1580
+ ...transform(
1581
+ args.transform?.waf,
1582
+ `${name}Waf`,
1583
+ {
1584
+ scope: "CLOUDFRONT",
1585
+ defaultAction: { allow: {} },
1586
+ rules,
1587
+ visibilityConfig: {
1588
+ cloudwatchMetricsEnabled: true,
1589
+ metricName: `${name}Waf`,
1590
+ sampledRequestsEnabled: true,
1591
+ },
1592
+ },
1593
+ { parent: self, provider: useProvider("us-east-1") },
1594
+ ),
1595
+ );
1596
+ }
1597
+
1598
+ function normalizeWafLogging() {
1599
+ return output(args.waf)
1600
+ .apply((waf) => {
1601
+ if (!waf || typeof waf === "boolean") return undefined;
1602
+ return output(waf.logging);
1603
+ })
1604
+ .apply((logging) => {
1605
+ if (!logging) return undefined;
1606
+ const l = (
1607
+ typeof logging === "boolean" ? {} : logging
1608
+ ) as WafLoggingArgs;
1609
+ const defaultRedact = {
1610
+ queryString: true as boolean,
1611
+ headers: ["cookie", "authorization"] as string[],
1612
+ };
1613
+ const redact = l.redact;
1614
+ return {
1615
+ include: (l.include ?? "all") as "all" | "blocked",
1616
+ retention: (l.retention ?? "1 month") as keyof typeof RETENTION,
1617
+ redact:
1618
+ redact === false
1619
+ ? undefined
1620
+ : redact ?? defaultRedact,
1621
+ };
1622
+ });
1623
+ }
1624
+
1625
+ function createWafLogging() {
1626
+ if (!waf) return;
1627
+
1628
+ wafLogging.apply((logging) => {
1629
+ if (!logging) return;
1630
+
1631
+ // CloudWatch Log Group name MUST start with "aws-waf-logs-"
1632
+ const logGroup = new cloudwatch.LogGroup(
1633
+ ...transform(
1634
+ args.transform?.wafLogGroup,
1635
+ `${name}WafLogGroup`,
1636
+ {
1637
+ name: `aws-waf-logs-${physicalName(64, name)}`,
1638
+ retentionInDays: RETENTION[logging.retention],
1639
+ },
1640
+ {
1641
+ parent: self,
1642
+ provider: useProvider("us-east-1"),
1643
+ ignoreChanges: ["name"],
1644
+ },
1645
+ ),
1646
+ );
1647
+
1648
+ const redactedFields = logging.redact
1649
+ ? output(logging.redact).apply((redact) => {
1650
+ if (!redact || typeof redact === "boolean") return [];
1651
+ const fields: wafv2.WebAclLoggingConfigurationArgs["redactedFields"] &
1652
+ {}[] = [];
1653
+ if (redact.method) fields.push({ method: {} });
1654
+ if (redact.queryString) fields.push({ queryString: {} });
1655
+ if (redact.uriPath) fields.push({ uriPath: {} });
1656
+ if (redact.headers) {
1657
+ for (const header of redact.headers) {
1658
+ fields.push({
1659
+ singleHeader: { name: header.toLowerCase() },
1660
+ });
1661
+ }
1662
+ }
1663
+ return fields;
1664
+ })
1665
+ : undefined;
1666
+
1667
+ const loggingFilter =
1668
+ logging.include === "blocked"
1669
+ ? {
1670
+ defaultBehavior: "DROP",
1671
+ filters: [
1672
+ {
1673
+ behavior: "KEEP" as const,
1674
+ requirement: "MEETS_ANY" as const,
1675
+ conditions: [
1676
+ {
1677
+ actionCondition: {
1678
+ action: "BLOCK",
1679
+ },
1680
+ },
1681
+ ],
1682
+ },
1683
+ ],
1684
+ }
1685
+ : undefined;
1686
+
1687
+ new wafv2.WebAclLoggingConfiguration(
1688
+ ...transform(
1689
+ args.transform?.wafLogging,
1690
+ `${name}WafLogging`,
1691
+ {
1692
+ resourceArn: waf!.arn,
1693
+ logDestinationConfigs: [logGroup.arn],
1694
+ ...(redactedFields ? { redactedFields } : {}),
1695
+ ...(loggingFilter ? { loggingFilter } : {}),
1696
+ },
1697
+ {
1698
+ parent: self,
1699
+ provider: useProvider("us-east-1"),
1700
+ },
1701
+ ),
1702
+ );
1703
+ });
1704
+ }
1705
+
1706
+ function registerOutputs() {
1707
+ self.registerOutputs({
1708
+ _hint: args._skipHint ? undefined : self.url,
1709
+ });
1710
+ }
1711
+
1712
+ function normalizeProtection(): Output<ProtectionConfig> {
1713
+ return output(args.protection).apply((protection) => {
1714
+ if (!protection) return { mode: "none" as const };
1715
+
1716
+ if (typeof protection === "string") {
1717
+ return { mode: protection };
1718
+ }
1719
+
1720
+ if (
1721
+ protection.mode === "oac-with-edge-signing" &&
1722
+ protection.edgeFunction?.arn
1723
+ ) {
1724
+ const arn = protection.edgeFunction.arn;
1725
+ if (typeof arn === "string") {
1726
+ parseLambdaEdgeArn(arn);
1727
+ }
1728
+ }
1729
+
1730
+ return protection;
1731
+ });
1732
+ }
1733
+
1734
+ function handleInlineRoutes() {
1735
+ let defaultCachePolicy: cloudfront.CachePolicy;
1736
+ let defaultCfFunction: cloudfront.Function;
1737
+ let defaultOac: OriginAccessControl;
1738
+ const routes = normalizeRoutes();
1739
+ const cdn = createCdn();
1740
+ return cdn;
1741
+
1742
+ function normalizeRoutes() {
1743
+ return output(args.routes!).apply((routes) => {
1744
+ const normalizedRoutes = Object.fromEntries(
1745
+ Object.entries(routes).map(([path, route]) => {
1746
+ // Route path must start with "/"
1747
+ if (!path.startsWith("/"))
1748
+ throw new Error(
1749
+ `In "${name}" Router, the route path "${path}" must start with a "/"`,
1750
+ );
1751
+
1752
+ route = typeof route === "string" ? { url: route } : route;
1753
+
1754
+ const hasUrl = "url" in route ? 1 : 0;
1755
+ const hasBucket = "bucket" in route ? 1 : 0;
1756
+ if (hasUrl + hasBucket !== 1)
1757
+ throw new Error(
1758
+ `In "${name}" Router, the route path "${path}" can only have one of url or bucket`,
1759
+ );
1760
+
1761
+ return [path, route];
1762
+ }),
1763
+ );
1764
+
1765
+ normalizedRoutes["/*"] = normalizedRoutes["/*"] ?? {
1766
+ url: "https://do-not-exist.sst.dev",
1767
+ };
1768
+
1769
+ return normalizedRoutes;
1770
+ });
1771
+ }
1772
+
1773
+ function createCfRequestDefaultFunction() {
1774
+ defaultCfFunction =
1775
+ defaultCfFunction ??
1776
+ new cloudfront.Function(
1777
+ `${name}CloudfrontFunction`,
1778
+ {
1779
+ runtime: "cloudfront-js-2.0",
1780
+ code: [
1781
+ `async function handler(event) {`,
1782
+ ` event.request.headers["x-forwarded-host"] = event.request.headers.host;`,
1783
+ ` return event.request;`,
1784
+ `}`,
1785
+ ].join("\n"),
1786
+ },
1787
+ { parent: self },
1788
+ );
1789
+ return defaultCfFunction;
1790
+ }
1791
+
1792
+ function createCfRequestFunction(
1793
+ path: string,
1794
+ config:
1795
+ | {
1796
+ injection: string;
1797
+ kvStore?: string;
1798
+ kvStores?: string[];
1799
+ }
1800
+ | undefined,
1801
+ rewrite:
1802
+ | {
1803
+ regex: string;
1804
+ to: string;
1805
+ }
1806
+ | undefined,
1807
+ injectHostHeader: boolean,
1808
+ ) {
1809
+ return new cloudfront.Function(
1810
+ `${name}CloudfrontFunction${hashStringToPrettyString(path, 8)}`,
1811
+ {
1812
+ runtime: "cloudfront-js-2.0",
1813
+ keyValueStoreAssociations: config?.kvStore
1814
+ ? [config.kvStore]
1815
+ : config?.kvStores ?? [],
1816
+ code: `
1817
+ async function handler(event) {
1818
+ ${
1819
+ injectHostHeader
1820
+ ? `event.request.headers["x-forwarded-host"] = event.request.headers.host;`
1821
+ : ""
1822
+ }
1823
+ ${
1824
+ rewrite
1825
+ ? `
1826
+ const re = new RegExp("${rewrite.regex}");
1827
+ event.request.uri = event.request.uri.replace(re, "${rewrite.to}");`
1828
+ : ""
1829
+ }
1830
+ ${config?.injection ?? ""}
1831
+ return event.request;
1832
+ }`,
1833
+ },
1834
+ { parent: self },
1835
+ );
1836
+ }
1837
+
1838
+ function createCfResponseFunction(
1839
+ path: string,
1840
+ config: {
1841
+ injection: string;
1842
+ kvStore?: string;
1843
+ kvStores?: string[];
1844
+ },
1845
+ ) {
1846
+ return new cloudfront.Function(
1847
+ `${name}CloudfrontFunctionResponse${hashStringToPrettyString(
1848
+ path,
1849
+ 8,
1850
+ )}`,
1851
+ {
1852
+ runtime: "cloudfront-js-2.0",
1853
+ keyValueStoreAssociations: config.kvStore
1854
+ ? [config.kvStore]
1855
+ : config.kvStores ?? [],
1856
+ code: `
1857
+ async function handler(event) {
1858
+ ${config.injection ?? ""}
1859
+ return event.response;
1860
+ }`,
1861
+ },
1862
+ { parent: self },
1863
+ );
1864
+ }
1865
+
1866
+ function createOriginAccessControl() {
1867
+ defaultOac =
1868
+ defaultOac ??
1869
+ new OriginAccessControl(
1870
+ `${name}S3AccessControl`,
1871
+ { name: physicalName(64, name) },
1872
+ { parent: self, ignoreChanges: ["name"] },
1873
+ );
1874
+ return defaultOac;
1875
+ }
1876
+
1877
+ function createCachePolicy() {
1878
+ defaultCachePolicy =
1879
+ defaultCachePolicy ??
1880
+ new cloudfront.CachePolicy(
1881
+ ...transform(
1882
+ args.transform?.cachePolicy,
1883
+ `${name}CachePolicy`,
1884
+ {
1885
+ comment: `${name} router cache policy`,
1886
+ defaultTtl: 0,
1887
+ maxTtl: 31536000, // 1 year
1888
+ minTtl: 0,
1889
+ parametersInCacheKeyAndForwardedToOrigin: {
1890
+ cookiesConfig: {
1891
+ cookieBehavior: "none",
1892
+ },
1893
+ headersConfig: {
1894
+ headerBehavior: "none",
1895
+ },
1896
+ queryStringsConfig: {
1897
+ queryStringBehavior: "all",
1898
+ },
1899
+ enableAcceptEncodingBrotli: true,
1900
+ enableAcceptEncodingGzip: true,
1901
+ },
1902
+ },
1903
+ { parent: self },
1904
+ ),
1905
+ );
1906
+
1907
+ return defaultCachePolicy;
1908
+ }
1909
+
1910
+ function createCdn() {
1911
+ return routes.apply((routes) => {
1912
+ const distributionData = Object.entries(routes).map(
1913
+ ([path, route]) => {
1914
+ if ("url" in route) {
1915
+ return {
1916
+ origin: {
1917
+ originId: path,
1918
+ domainName: new URL(route.url).host,
1919
+ customOriginConfig: {
1920
+ httpPort: 80,
1921
+ httpsPort: 443,
1922
+ originProtocolPolicy: "https-only",
1923
+ originReadTimeout: 20,
1924
+ originSslProtocols: ["TLSv1.2"],
1925
+ },
1926
+ },
1927
+ behavior: {
1928
+ pathPattern: path,
1929
+ targetOriginId: path,
1930
+ functionAssociations: [
1931
+ {
1932
+ eventType: "viewer-request",
1933
+ functionArn:
1934
+ route.edge?.viewerRequest || route.rewrite
1935
+ ? createCfRequestFunction(
1936
+ path,
1937
+ route.edge?.viewerRequest,
1938
+ route.rewrite,
1939
+ true,
1940
+ ).arn
1941
+ : createCfRequestDefaultFunction().arn,
1942
+ },
1943
+ ...(route.edge?.viewerResponse
1944
+ ? [
1945
+ {
1946
+ eventType: "viewer-response",
1947
+ functionArn: createCfResponseFunction(
1948
+ path,
1949
+ route.edge.viewerResponse,
1950
+ ).arn,
1951
+ },
1952
+ ]
1953
+ : []),
1954
+ ],
1955
+ viewerProtocolPolicy: "redirect-to-https",
1956
+ allowedMethods: [
1957
+ "DELETE",
1958
+ "GET",
1959
+ "HEAD",
1960
+ "OPTIONS",
1961
+ "PATCH",
1962
+ "POST",
1963
+ "PUT",
1964
+ ],
1965
+ cachedMethods: ["GET", "HEAD"],
1966
+ defaultTtl: 0,
1967
+ compress: true,
1968
+ cachePolicyId: route.cachePolicy ?? createCachePolicy().id,
1969
+ // CloudFront's Managed-AllViewerExceptHostHeader policy
1970
+ originRequestPolicyId:
1971
+ "b689b0a8-53d0-40ab-baf2-68738e2966ac",
1972
+ },
1973
+ };
1974
+ } else if ("bucket" in route) {
1975
+ return {
1976
+ origin: {
1977
+ originId: path,
1978
+ domainName:
1979
+ route.bucket instanceof Bucket
1980
+ ? route.bucket.nodes.bucket.bucketRegionalDomainName
1981
+ : route.bucket!,
1982
+ originPath: "",
1983
+ originAccessControlId: createOriginAccessControl().id,
1984
+ },
1985
+ behavior: {
1986
+ pathPattern: path,
1987
+ targetOriginId: path,
1988
+ functionAssociations: [
1989
+ ...(route.edge?.viewerRequest || route.rewrite
1990
+ ? [
1991
+ {
1992
+ eventType: "viewer-request",
1993
+ functionArn:
1994
+ route.edge?.viewerRequest || route.rewrite
1995
+ ? createCfRequestFunction(
1996
+ path,
1997
+ route.edge?.viewerRequest,
1998
+ route.rewrite,
1999
+ false,
2000
+ ).arn
2001
+ : createCfRequestDefaultFunction().arn,
2002
+ },
2003
+ ]
2004
+ : []),
2005
+ ...(route.edge?.viewerResponse
2006
+ ? [
2007
+ {
2008
+ eventType: "viewer-response",
2009
+ functionArn: createCfResponseFunction(
2010
+ path,
2011
+ route.edge.viewerResponse,
2012
+ ).arn,
2013
+ },
2014
+ ]
2015
+ : []),
2016
+ ],
2017
+ viewerProtocolPolicy: "redirect-to-https",
2018
+ allowedMethods: ["GET", "HEAD", "OPTIONS"],
2019
+ cachedMethods: ["GET", "HEAD"],
2020
+ compress: true,
2021
+ // CloudFront's managed CachingOptimized policy
2022
+ cachePolicyId:
2023
+ route.cachePolicy ??
2024
+ "658327ea-f89d-4fab-a63d-7e88639e58f6",
2025
+ },
2026
+ };
2027
+ }
2028
+ throw new Error("Invalid route type");
2029
+ },
2030
+ );
2031
+
2032
+ return new Cdn(
2033
+ ...transform(
2034
+ args.transform?.cdn,
2035
+ `${name}Cdn`,
2036
+ {
2037
+ comment: `${name} router`,
2038
+ origins: distributionData.map((d) => d.origin),
2039
+ defaultCacheBehavior: {
2040
+ ...distributionData.find(
2041
+ (d) => d.behavior.pathPattern === "/*",
2042
+ )!.behavior,
2043
+ // @ts-expect-error
2044
+ pathPattern: undefined,
2045
+ },
2046
+ orderedCacheBehaviors: distributionData
2047
+ .filter((d) => d.behavior.pathPattern !== "/*")
2048
+ .map((d) => d.behavior),
2049
+ domain: args.domain,
2050
+ wait: true,
2051
+ webAclArn: wafArn,
2052
+ },
2053
+ { parent: self },
2054
+ ),
2055
+ );
2056
+ });
2057
+ }
2058
+ }
2059
+
2060
+ function handleLazyRoutes() {
2061
+ const kvNamespace = buildRequestKvNamespace();
2062
+ const kvStoreArn = createRequestKvStore();
2063
+ const requestFunction = createRequestFunction();
2064
+ const responseFunction = createResponseFunction();
2065
+ const cachePolicyId = createCachePolicy().id;
2066
+ const edgeFunction = createLambdaEdgeFunction();
2067
+ const distribution = createDistribution();
2068
+
2069
+ return { kvNamespace, kvStoreArn, distribution };
2070
+
2071
+ function buildRequestKvNamespace() {
2072
+ // In the case multiple routers use the same kv store, we need to namespace the keys
2073
+ return crypto
2074
+ .createHash("md5")
2075
+ .update(`${$app.name}-${$app.stage}-${name}`)
2076
+ .digest("hex")
2077
+ .substring(0, 4);
2078
+ }
2079
+
2080
+ function createRequestKvStore() {
2081
+ return output(args.edge).apply((edge) => {
2082
+ const viewerRequest = edge?.viewerRequest;
2083
+ const userKvStore = viewerRequest?.kvStore;
2084
+ if (userKvStore) return output(userKvStore);
2085
+
2086
+ return new cloudfront.KeyValueStore(
2087
+ `${name}KvStore`,
2088
+ {},
2089
+ { parent: self },
2090
+ ).arn;
2091
+ });
2092
+ }
2093
+
2094
+ function createCachePolicy() {
2095
+ return new cloudfront.CachePolicy(
2096
+ ...transform(
2097
+ args.transform?.cachePolicy,
2098
+ `${name}ServerCachePolicy`,
2099
+ {
2100
+ comment: "SST server response cache policy",
2101
+ defaultTtl: 0,
2102
+ maxTtl: 31536000, // 1 year
2103
+ minTtl: 0,
2104
+ parametersInCacheKeyAndForwardedToOrigin: {
2105
+ cookiesConfig: {
2106
+ cookieBehavior: "none",
2107
+ },
2108
+ headersConfig: {
2109
+ headerBehavior: "whitelist",
2110
+ headers: {
2111
+ items: ["x-open-next-cache-key", "x-forwarded-host"],
2112
+ },
2113
+ },
2114
+ queryStringsConfig: {
2115
+ queryStringBehavior: "all",
2116
+ },
2117
+ enableAcceptEncodingBrotli: true,
2118
+ enableAcceptEncodingGzip: true,
2119
+ },
2120
+ },
2121
+ { parent: self },
2122
+ ),
2123
+ );
2124
+ }
2125
+
2126
+ function createRequestFunction() {
2127
+ return output(args.edge).apply((edge) => {
2128
+ const userInjection = edge?.viewerRequest?.injection ?? "";
2129
+ const blockCloudfrontUrlInjection = args.domain
2130
+ ? CF_BLOCK_CLOUDFRONT_URL_INJECTION
2131
+ : "";
2132
+ return new cloudfront.Function(
2133
+ `${name}CloudfrontFunctionRequest`,
2134
+ {
2135
+ runtime: "cloudfront-js-2.0",
2136
+ keyValueStoreAssociations: kvStoreArn ? [kvStoreArn] : [],
2137
+ code: interpolate`
2138
+ import cf from "cloudfront";
2139
+ async function handler(event) {
2140
+ ${userInjection}
2141
+ ${blockCloudfrontUrlInjection}
2142
+ ${CF_ROUTER_INJECTION}
2143
+
2144
+ async function getRoutes() {
2145
+ const routerNS = "${kvNamespace}";
2146
+ let routes = [];
2147
+ try {
2148
+ const v = await cf.kvs().get(routerNS + ":routes");
2149
+ routes = JSON.parse(v);
2150
+
2151
+ // handle chunked routes
2152
+ if (routes.parts) {
2153
+ const chunkPromises = [];
2154
+ for (let i = 0; i < routes.parts; i++) {
2155
+ chunkPromises.push(cf.kvs().get(routerNS + ":routes:" + i));
2156
+ }
2157
+ const chunks = await Promise.all(chunkPromises);
2158
+ routes = JSON.parse(chunks.join(""));
2159
+ }
2160
+ } catch (e) {}
2161
+ return routes;
2162
+ }
2163
+
2164
+ async function matchRoute(routes) {
2165
+ const requestHost = event.request.headers.host.value;
2166
+ const requestHostWithEscapedDots = requestHost.replace(/\\./g, "\\\\.");
2167
+ const requestHostRegexPattern = "^" + requestHost + "$";
2168
+ let match;
2169
+ routes.forEach(r => {
2170
+ ${
2171
+ /*
2172
+ Route format: [type, routeNamespace, hostRegex, pathPrefix]
2173
+ - First sort by host pattern (longest first)
2174
+ - Then sort by path prefix (longest first)
2175
+ */ ""
2176
+ }
2177
+ var parts = r.split(",");
2178
+ const type = parts[0];
2179
+ const routeNs = parts[1];
2180
+ const host = parts[2];
2181
+ const hostLength = host.length;
2182
+ const path = parts[3];
2183
+ const pathLength = path.length;
2184
+
2185
+ // Do not consider if the current match is a better winner
2186
+ if (match && (
2187
+ hostLength < match.hostLength
2188
+ || (hostLength === match.hostLength && pathLength < match.pathLength)
2189
+ )) return;
2190
+
2191
+ const hostMatches = host === ""
2192
+ || host === requestHostWithEscapedDots
2193
+ || (host.includes("*") && new RegExp(host).test(requestHostRegexPattern));
2194
+ if (!hostMatches) return;
2195
+
2196
+ const pathMatches = event.request.uri.startsWith(path) && (event.request.uri === path || path.endsWith('/') || event.request.uri[path.length] === '/' || path === '/');
2197
+ if (!pathMatches) return;
2198
+
2199
+ match = {
2200
+ type,
2201
+ routeNs,
2202
+ host,
2203
+ hostLength,
2204
+ path,
2205
+ pathLength,
2206
+ };
2207
+ });
2208
+
2209
+ // Load metadata
2210
+ if (match) {
2211
+ try {
2212
+ const type = match.type;
2213
+ const routeNs = match.routeNs;
2214
+ const v = await cf.kvs().get(routeNs + ":metadata");
2215
+ return { type, routeNs, metadata: JSON.parse(v) };
2216
+ } catch (e) {}
2217
+ }
2218
+ }
2219
+
2220
+ // Look up the route
2221
+ const routes = await getRoutes();
2222
+ const route = await matchRoute(routes);
2223
+ if (!route) return event.request;
2224
+ if (route.metadata.rewrite) {
2225
+ const rw = route.metadata.rewrite;
2226
+ event.request.uri = event.request.uri.replace(new RegExp(rw.regex), rw.to);
2227
+ }
2228
+ if (route.type === "url") setUrlOrigin(route.metadata.host, route.metadata.origin);
2229
+ if (route.type === "bucket") setS3Origin(route.metadata.domain, route.metadata.origin);
2230
+ if (route.type === "site") {
2231
+ const response = await routeSite(route.routeNs, route.metadata);
2232
+ return response || event.request;
2233
+ }
2234
+ return event.request;
2235
+ }`,
2236
+ },
2237
+ { parent: self },
2238
+ );
2239
+ });
2240
+ }
2241
+
2242
+ function createResponseFunction() {
2243
+ return output(args.edge).apply((edge) => {
2244
+ const userConfig = edge?.viewerResponse;
2245
+ const userInjection = userConfig?.injection;
2246
+ const kvStoreArn = userConfig?.kvStore;
2247
+
2248
+ if (!userInjection) return;
2249
+
2250
+ return new cloudfront.Function(
2251
+ `${name}CloudfrontFunctionResponse`,
2252
+ {
2253
+ runtime: "cloudfront-js-2.0",
2254
+ keyValueStoreAssociations: kvStoreArn ? [kvStoreArn] : [],
2255
+ code: `
2256
+ import cf from "cloudfront";
2257
+ async function handler(event) {
2258
+ ${userInjection}
2259
+ return event.response;
2260
+ }`,
2261
+ },
2262
+ { parent: self },
2263
+ );
2264
+ });
2265
+ }
2266
+
2267
+ function createLambdaEdgeFunction() {
2268
+ return protection.apply((protectionConfig) => {
2269
+ if (
2270
+ protectionConfig.mode !== "oac-with-edge-signing" ||
2271
+ protectionConfig.edgeFunction?.arn
2272
+ ) {
2273
+ return undefined;
2274
+ }
2275
+
2276
+ const edgeConfig = protectionConfig.edgeFunction;
2277
+ const memory = edgeConfig?.memory ? toMBs(edgeConfig.memory) : 128;
2278
+ const timeout = edgeConfig?.timeout
2279
+ ? toSeconds(edgeConfig.timeout)
2280
+ : 5;
2281
+
2282
+ const edgeRole = new iam.Role(
2283
+ ...transform(
2284
+ undefined,
2285
+ `${name}EdgeFunctionRole`,
2286
+ {
2287
+ name: physicalName(64, `${name}EdgeRole`),
2288
+ assumeRolePolicy: JSON.stringify({
2289
+ Version: "2012-10-17",
2290
+ Statement: [
2291
+ {
2292
+ Action: "sts:AssumeRole",
2293
+ Effect: "Allow",
2294
+ Principal: {
2295
+ Service: [
2296
+ "lambda.amazonaws.com",
2297
+ "edgelambda.amazonaws.com",
2298
+ ],
2299
+ },
2300
+ },
2301
+ ],
2302
+ }),
2303
+ managedPolicyArns: [
2304
+ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
2305
+ ],
2306
+ },
2307
+ { parent: self, ignoreChanges: ["name"] },
2308
+ ),
2309
+ );
2310
+
2311
+ const edgeFn = new lambda.Function(
2312
+ ...transform(
2313
+ undefined,
2314
+ `${name}EdgeFunction`,
2315
+ {
2316
+ name: physicalName(64, `${name}EdgeFn`),
2317
+ runtime: "nodejs24.x",
2318
+ handler: "index.handler",
2319
+ role: edgeRole.arn,
2320
+ code: new asset.FileArchive(
2321
+ path.join($cli.paths.platform, "dist", "oac-edge-signer"),
2322
+ ),
2323
+ publish: true,
2324
+ timeout: timeout,
2325
+ memorySize: memory,
2326
+ description: `${name} Lambda@Edge function for OAC request signing`,
2327
+ },
2328
+ {
2329
+ parent: self,
2330
+ provider: useProvider("us-east-1"),
2331
+ ignoreChanges: ["name"],
2332
+ },
2333
+ ),
2334
+ );
2335
+
2336
+ return edgeFn;
2337
+ });
2338
+ }
2339
+
2340
+ function createDistribution() {
2341
+ return new Cdn(
2342
+ ...transform(
2343
+ args.transform?.cdn,
2344
+ `${name}Cdn`,
2345
+ {
2346
+ comment: `${name} app`,
2347
+ domain: args.domain,
2348
+ origins: [
2349
+ {
2350
+ originId: "default",
2351
+ domainName: "placeholder.sst.dev",
2352
+ customOriginConfig: {
2353
+ httpPort: 80,
2354
+ httpsPort: 443,
2355
+ originProtocolPolicy: "http-only",
2356
+ originReadTimeout: 20,
2357
+ originSslProtocols: ["TLSv1.2"],
2358
+ },
2359
+ },
2360
+ ],
2361
+ defaultCacheBehavior: {
2362
+ targetOriginId: "default",
2363
+ viewerProtocolPolicy: "redirect-to-https",
2364
+ allowedMethods: [
2365
+ "DELETE",
2366
+ "GET",
2367
+ "HEAD",
2368
+ "OPTIONS",
2369
+ "PATCH",
2370
+ "POST",
2371
+ "PUT",
2372
+ ],
2373
+ cachedMethods: ["GET", "HEAD"],
2374
+ compress: true,
2375
+ cachePolicyId,
2376
+ // CloudFront's Managed-AllViewerExceptHostHeader policy
2377
+ originRequestPolicyId: "b689b0a8-53d0-40ab-baf2-68738e2966ac",
2378
+ functionAssociations: all([
2379
+ requestFunction,
2380
+ responseFunction,
2381
+ ]).apply(([reqFn, resFn]) => [
2382
+ { eventType: "viewer-request", functionArn: reqFn.arn },
2383
+ ...(resFn
2384
+ ? [{ eventType: "viewer-response", functionArn: resFn.arn }]
2385
+ : []),
2386
+ ]),
2387
+ lambdaFunctionAssociations: all([
2388
+ protection,
2389
+ edgeFunction,
2390
+ ]).apply(([protectionConfig, autoEdgeFunction]) => {
2391
+ if (protectionConfig.mode !== "oac-with-edge-signing") {
2392
+ return [];
2393
+ }
2394
+
2395
+ if (protectionConfig.edgeFunction?.arn) {
2396
+ return [
2397
+ {
2398
+ eventType: "origin-request",
2399
+ lambdaArn: protectionConfig.edgeFunction.arn,
2400
+ includeBody: true,
2401
+ },
2402
+ ];
2403
+ }
2404
+
2405
+ if (autoEdgeFunction) {
2406
+ return [
2407
+ {
2408
+ eventType: "origin-request",
2409
+ lambdaArn: autoEdgeFunction.qualifiedArn,
2410
+ includeBody: true,
2411
+ },
2412
+ ];
2413
+ }
2414
+
2415
+ return [];
2416
+ }),
2417
+ },
2418
+ tags: {
2419
+ "sst:ref:kv": kvStoreArn,
2420
+ "sst:ref:kv-namespace": kvNamespace,
2421
+ "sst:ref:version": _refVersion.toString(),
2422
+ "sst:ref:protection": protection.apply((p) => p.mode),
2423
+ },
2424
+ webAclArn: wafArn,
2425
+ },
2426
+ { parent: self },
2427
+ ),
2428
+ );
2429
+ }
2430
+ }
2431
+ }
2432
+
2433
+ /**
2434
+ * The ID of the Router distribution.
2435
+ */
2436
+ public get distributionID() {
2437
+ return this.cdn.nodes.distribution.id;
2438
+ }
2439
+
2440
+ /**
2441
+ * The URL of the Router.
2442
+ *
2443
+ * If the `domain` is set, this is the URL with the custom domain.
2444
+ * Otherwise, it's the auto-generated CloudFront URL.
2445
+ */
2446
+ public get url() {
2447
+ return all([this.cdn.domainUrl, this.cdn.url]).apply(
2448
+ ([domainUrl, url]) => domainUrl ?? url,
2449
+ );
2450
+ }
2451
+
2452
+ /** @internal */
2453
+ public get _kvStoreArn() {
2454
+ return this.kvStoreArn;
2455
+ }
2456
+
2457
+ /** @internal */
2458
+ public get _kvNamespace() {
2459
+ return this.kvNamespace;
2460
+ }
2461
+
2462
+ /** @internal */
2463
+ public get _hasInlineRoutes() {
2464
+ return this.hasInlineRoutes;
2465
+ }
2466
+
2467
+ /** @internal */
2468
+ public get _protection() {
2469
+ return this._protectionMode;
2470
+ }
2471
+
2472
+ /** @internal */
2473
+ public get _distributionArn() {
2474
+ return this.cdn.apply((cdn) => cdn.nodes.distribution.arn);
2475
+ }
2476
+
2477
+ /**
2478
+ * The underlying [resources](/docs/components/#nodes) this component creates.
2479
+ */
2480
+ public get nodes() {
2481
+ return {
2482
+ /**
2483
+ * The Amazon CloudFront CDN resource.
2484
+ */
2485
+ cdn: this.cdn,
2486
+ };
2487
+ }
2488
+
2489
+ /**
2490
+ * Add a route to a destination URL.
2491
+ *
2492
+ * @param pattern The path prefix to match for this route.
2493
+ * @param url The destination URL to route matching requests to.
2494
+ * @param args Configure the route.
2495
+ *
2496
+ * @example
2497
+ *
2498
+ * You can match a route based on:
2499
+ *
2500
+ * - A path prefix like `/api`
2501
+ * - A domain pattern like `api.example.com`
2502
+ * - A combined pattern like `dev.example.com/api`
2503
+ *
2504
+ * For example, to match a path prefix.
2505
+ *
2506
+ * ```ts title="sst.config.ts"
2507
+ * router.route("/api", "https://api.example.com");
2508
+ * ```
2509
+ *
2510
+ * Or match a domain.
2511
+ *
2512
+ * ```ts title="sst.config.ts"
2513
+ * router.route("api.myapp.com/", "https://api.example.com");
2514
+ * ```
2515
+ *
2516
+ * Or a combined pattern.
2517
+ *
2518
+ * ```ts title="sst.config.ts"
2519
+ * router.route("dev.myapp.com/api", "https://api.example.com");
2520
+ * ```
2521
+ *
2522
+ * You can also rewrite the request path.
2523
+ *
2524
+ * ```ts title="sst.config.ts"
2525
+ * router.route("/api", "https://api.example.com", {
2526
+ * rewrite: {
2527
+ * regex: "^/api/(.*)$",
2528
+ * to: "/$1"
2529
+ * }
2530
+ * });
2531
+ * ```
2532
+ *
2533
+ * Here something like `/api/users/profile` will be routed to
2534
+ * `https://api.example.com/users/profile`.
2535
+ */
2536
+ public route(
2537
+ pattern: Input<string>,
2538
+ url: Input<string>,
2539
+ args?: Input<RouterUrlRouteArgs>,
2540
+ ) {
2541
+ all([pattern, args, this.hasInlineRoutes]).apply(
2542
+ ([pattern, args, hasInlineRoutes]) => {
2543
+ if (hasInlineRoutes)
2544
+ throw new VisibleError(
2545
+ "Cannot use both `routes` and `.route()` function to add routes.",
2546
+ );
2547
+
2548
+ new RouterUrlRoute(
2549
+ `${this.constructorName}Route${pattern}`,
2550
+ {
2551
+ store: this.kvStoreArn!,
2552
+ routerNamespace: this.kvNamespace!,
2553
+ pattern,
2554
+ url,
2555
+ routeArgs: args,
2556
+ },
2557
+ { provider: this.constructorOpts.provider },
2558
+ );
2559
+ },
2560
+ );
2561
+ }
2562
+
2563
+ /**
2564
+ * Add a route to an S3 bucket.
2565
+ *
2566
+ * @param pattern The path prefix to match for this route.
2567
+ * @param bucket The S3 bucket to route matching requests to.
2568
+ * @param args Configure the route.
2569
+ *
2570
+ * @example
2571
+ *
2572
+ * Let's say you have an S3 bucket that gives CloudFront `access`.
2573
+ *
2574
+ * ```ts title="sst.config.ts" {2}
2575
+ * const bucket = new sst.aws.Bucket("MyBucket", {
2576
+ * access: "cloudfront"
2577
+ * });
2578
+ * ```
2579
+ *
2580
+ * You can match a pattern and route to it based on:
2581
+ *
2582
+ * - A path prefix like `/api`
2583
+ * - A domain pattern like `api.example.com`
2584
+ * - A combined pattern like `dev.example.com/api`
2585
+ *
2586
+ * For example, to match a path prefix.
2587
+ *
2588
+ * ```ts title="sst.config.ts"
2589
+ * router.routeBucket("/files", bucket);
2590
+ * ```
2591
+ *
2592
+ * Or match a domain.
2593
+ *
2594
+ * ```ts title="sst.config.ts"
2595
+ * router.routeBucket("files.example.com", bucket);
2596
+ * ```
2597
+ *
2598
+ * Or a combined pattern.
2599
+ *
2600
+ * ```ts title="sst.config.ts"
2601
+ * router.routeBucket("dev.example.com/files", bucket);
2602
+ * ```
2603
+ *
2604
+ * You can also rewrite the request path.
2605
+ *
2606
+ * ```ts title="sst.config.ts"
2607
+ * router.routeBucket("/files", bucket, {
2608
+ * rewrite: {
2609
+ * regex: "^/files/(.*)$",
2610
+ * to: "/$1"
2611
+ * }
2612
+ * });
2613
+ * ```
2614
+ *
2615
+ * Here something like `/files/logo.png` will be routed to
2616
+ * `/logo.png`.
2617
+ */
2618
+ public routeBucket(
2619
+ pattern: Input<string>,
2620
+ bucket: Input<Bucket>,
2621
+ args?: Input<RouterBucketRouteArgs>,
2622
+ ) {
2623
+ all([pattern, args, this.hasInlineRoutes]).apply(
2624
+ ([pattern, args, hasInlineRoutes]) => {
2625
+ if (hasInlineRoutes)
2626
+ throw new VisibleError(
2627
+ "Cannot use both `routes` and `.routeBucket()` function to add routes.",
2628
+ );
2629
+
2630
+ new RouterBucketRoute(
2631
+ `${this.constructorName}Route${pattern}`,
2632
+ {
2633
+ store: this.kvStoreArn!,
2634
+ routerNamespace: this.kvNamespace!,
2635
+ pattern,
2636
+ bucket,
2637
+ routeArgs: args,
2638
+ },
2639
+ { provider: this.constructorOpts.provider },
2640
+ );
2641
+ },
2642
+ );
2643
+ }
2644
+
2645
+ /**
2646
+ * Add a route to a frontend or static site.
2647
+ *
2648
+ * @param pattern The path prefix to match for this route.
2649
+ * @param site The frontend or static site to route matching requests to.
2650
+ *
2651
+ * @deprecated The `routeSite` function has been deprecated. Set the `route` on the
2652
+ * site components to route the site through this Router.
2653
+ */
2654
+ public routeSite(pattern: Input<string>, site: any) {
2655
+ throw new VisibleError(
2656
+ `The "routeSite" function has been deprecated. Configure the new "route" prop on the site component to route the site through this Router.`,
2657
+ );
2658
+ }
2659
+
2660
+ /** @internal */
2661
+ public getSSTLink() {
2662
+ return {
2663
+ properties: {
2664
+ url: this.url,
2665
+ },
2666
+ };
2667
+ }
2668
+
2669
+ /**
2670
+ * Reference an existing Router with the given Router distribution ID.
2671
+ *
2672
+ * @param name The name of the component.
2673
+ * @param distributionID The ID of the existing Router distribution.
2674
+ * @param opts Resource options.
2675
+ *
2676
+ * This is useful when you create a Router in one stage and want to share it in
2677
+ * another. It avoids having to create a new Router in the other stage.
2678
+ *
2679
+ * :::tip
2680
+ * You can use the `static get` method to share a Router across stages.
2681
+ * :::
2682
+ *
2683
+ * @example
2684
+ * Let's say you create a Router in the `dev` stage. And in your personal stage
2685
+ * `frank`, you want to share the same Router.
2686
+ *
2687
+ * ```ts title="sst.config.ts"
2688
+ * const router = $app.stage === "frank"
2689
+ * ? sst.aws.Router.get("MyRouter", "E2IDLMESRN6V62")
2690
+ * : new sst.aws.Router("MyRouter");
2691
+ * ```
2692
+ *
2693
+ * Here `E2IDLMESRN6V62` is the ID of the Router distribution created in the
2694
+ * `dev` stage. You can find this by outputting the distribution ID in the `dev`
2695
+ * stage.
2696
+ *
2697
+ * ```ts title="sst.config.ts"
2698
+ * return {
2699
+ * router: router.distributionID
2700
+ * };
2701
+ * ```
2702
+ *
2703
+ * Learn more about [how to configure a router for your app](/docs/configure-a-router).
2704
+ */
2705
+ public static get(
2706
+ name: string,
2707
+ distributionID: Input<string>,
2708
+ opts?: ComponentResourceOptions,
2709
+ ) {
2710
+ return new Router(
2711
+ name,
2712
+ {
2713
+ ref: true,
2714
+ distributionID: distributionID,
2715
+ } as unknown as RouterArgs,
2716
+ opts,
2717
+ );
2718
+ }
2719
+ }
2720
+
2721
+ const __pulumiType = "sst:aws:Router";
2722
+ // @ts-expect-error
2723
+ Router.__pulumiType = __pulumiType;
2724
+
2725
+ // CloudFront Functions have a 10KB limit on the forwarded request size.
2726
+ // We reserve 512 bytes for origin-request overhead CloudFront can still add after
2727
+ // this viewer-request function runs, so borderline requests fail with a clear 431.
2728
+ const CLOUDFRONT_FUNCTION_SAFE_HEADER_LIMIT = 10240 - 512;
2729
+
2730
+ export const CF_BLOCK_CLOUDFRONT_URL_INJECTION = `
2731
+ if (event.request.headers.host.value.includes('cloudfront.net')) {
2732
+ return {
2733
+ statusCode: 403,
2734
+ statusDescription: 'Forbidden',
2735
+ body: {
2736
+ encoding: "text",
2737
+ data: '<html><head><title>403 Forbidden</title></head><body><center><h1>403 Forbidden</h1></center></body></html>'
2738
+ }
2739
+ };
2740
+ }`;
2741
+
2742
+ // CloudFront Function handler code injected into site and router CF functions.
2743
+ // NOTE: This string is size-sensitive — CloudFront Functions have a 10KB limit.
2744
+ // NOTE: `s3Key` is the S3 key of a file: the folder, the path prefix the files were
2745
+ // uploaded under (`s3.prefix`), then the uri without the site's base path. Without
2746
+ // `s3.prefix` (metadata from an older version) it is the folder and the whole uri.
2747
+ // The base is only taken off the start of the uri, and only at a segment boundary
2748
+ // (`/admin` is not taken off `/administrator`), so don't go back to `replace`. The base
2749
+ // never has a trailing slash (the route's path prefix is normalized in this file, and an
2750
+ // SSR site's base in `ssr-site.ts`), so `base + "/"` is safe.
2751
+ // `s3Key` takes everything as arguments: reading `baselessUri` from `routeSite` fails with
2752
+ // "cannot access variable before initialization" in the CloudFront function runtime.
2753
+ // The custom 404 and the "unmatched" branches below still use the old key.
2754
+ export const CF_ROUTER_INJECTION = minify`
2755
+ async function routeSite(kvNamespace, metadata) {
2756
+ const baselessUri = metadata.base && (event.request.uri === metadata.base || event.request.uri.startsWith(metadata.base + "/"))
2757
+ ? event.request.uri.slice(metadata.base.length)
2758
+ : event.request.uri;
2759
+
2760
+ function s3Key(metadata, uri, baselessUri) {
2761
+ return metadata.s3.dir + (metadata.s3.prefix === undefined ? uri : metadata.s3.prefix + baselessUri);
2762
+ }
2763
+
2764
+ // Route to S3 files
2765
+ try {
2766
+ // check using baselessUri b/c files are stored in the root
2767
+ const u = decodeURIComponent(baselessUri);
2768
+ const postfixes = u.endsWith("/")
2769
+ ? ["index.html"]
2770
+ : ["", ".html", "/index.html"];
2771
+ const v = await Promise.any(postfixes.map(p => cf.kvs().get(kvNamespace + ":" + u + p).then(v => p)));
2772
+ // files are stored in a subdirectory, add it to the request uri
2773
+ event.request.uri = s3Key(metadata, event.request.uri, baselessUri) + v;
2774
+ setS3Origin(metadata.s3.domain);
2775
+ return;
2776
+ } catch (e) {}
2777
+
2778
+ // Route to S3 routes
2779
+ if (metadata.s3 && metadata.s3.routes) {
2780
+ for (var i=0, l=metadata.s3.routes.length; i<l; i++) {
2781
+ const route = metadata.s3.routes[i];
2782
+ if (baselessUri.startsWith(route)) {
2783
+ event.request.uri = s3Key(metadata, event.request.uri, baselessUri);
2784
+ // uri ends with /, ie. /usage/ -> /usage/index.html
2785
+ if (event.request.uri.endsWith("/")) {
2786
+ event.request.uri += "index.html";
2787
+ }
2788
+ // uri ends with non-file, ie. /usage -> /usage/index.html
2789
+ else if (!event.request.uri.split("/").pop().includes(".")) {
2790
+ event.request.uri += "/index.html";
2791
+ }
2792
+ setS3Origin(metadata.s3.domain);
2793
+ return;
2794
+ }
2795
+ }
2796
+ }
2797
+
2798
+ // Route to S3 custom 404 (SPA fallback, no servers)
2799
+ if (metadata.custom404 && !metadata.errorResponseCode) {
2800
+ event.request.uri = metadata.s3.dir + (metadata.base ? metadata.base : "") + metadata.custom404;
2801
+ setS3Origin(metadata.s3.domain);
2802
+ return;
2803
+ }
2804
+
2805
+ // Route unmatched to S3 (triggers customErrorResponses)
2806
+ if (metadata.s3 && !metadata.servers) {
2807
+ event.request.uri = metadata.s3.dir + event.request.uri;
2808
+ setS3Origin(metadata.s3.domain);
2809
+ return;
2810
+ }
2811
+
2812
+ // Route to image optimizer
2813
+ if (metadata.image && baselessUri.startsWith(metadata.image.route)) {
2814
+ setForwardedHost();
2815
+ setNextjsCacheKey();
2816
+ if (isRequestHeaderTooLarge()) return buildOversizedHeadersResponse();
2817
+ setUrlOrigin(metadata.image.host, metadata.image.originAccessControlConfig ? { originAccessControlConfig: metadata.image.originAccessControlConfig } : undefined);
2818
+ return;
2819
+ }
2820
+
2821
+ // Route to servers
2822
+ if (metadata.servers){
2823
+ setForwardedHost();
2824
+ // In SvelteKit, form action requests contain "/" in request query string
2825
+ // ie. POST request with query string "?/action"
2826
+ // CloudFront does not allow query string with "/". It needs to be encoded.
2827
+ for (var key in event.request.querystring) {
2828
+ if (key.includes("/")) {
2829
+ event.request.querystring[encodeURIComponent(key)] = event.request.querystring[key];
2830
+ delete event.request.querystring[key];
2831
+ }
2832
+ }
2833
+ setNextjsGeoHeaders();
2834
+ setNextjsCacheKey();
2835
+ if (isRequestHeaderTooLarge()) return buildOversizedHeadersResponse();
2836
+ setUrlOrigin(findNearestServer(metadata.servers), metadata.origin);
2837
+ }
2838
+
2839
+ // Inject the CloudFront viewer country, region, latitude, and longitude headers into
2840
+ // the request headers for OpenNext to use them
2841
+ function setNextjsGeoHeaders() {
2842
+ var keys = ["city","country","region","latitude","longitude"];
2843
+ for (var i=0; i<keys.length; i++) {
2844
+ if (event.request.headers["cloudfront-viewer-" + keys[i]])
2845
+ event.request.headers["x-open-next-" + keys[i]] = event.request.headers["cloudfront-viewer-" + keys[i]];
2846
+ }
2847
+ }
2848
+
2849
+ // This function is used to improve cache hit ratio by setting the cache key
2850
+ // based on the request headers and the path. next/image only needs the
2851
+ // accept header, and this header is not useful for the rest of the query
2852
+ function setNextjsCacheKey() {
2853
+ var cacheKey = "";
2854
+ if (event.request.uri.startsWith("/_next/image")) {
2855
+ cacheKey = getHeader("accept");
2856
+ } else {
2857
+ var headers = ["rsc","next-router-prefetch","next-router-state-tree","next-url","x-prerender-revalidate"];
2858
+ for (var i=0; i<headers.length; i++) cacheKey += getHeader(headers[i]);
2859
+ }
2860
+ if (event.request.cookies["__prerender_bypass"]) {
2861
+ cacheKey += event.request.cookies["__prerender_bypass"]
2862
+ ? event.request.cookies["__prerender_bypass"].value
2863
+ : "";
2864
+ }
2865
+ var crypto = require("crypto");
2866
+ var hashedKey = crypto.createHash("md5").update(cacheKey).digest("hex");
2867
+ event.request.headers["x-open-next-cache-key"] = { value: hashedKey };
2868
+ }
2869
+
2870
+ function getHeader(key) {
2871
+ var header = event.request.headers[key];
2872
+ if (header) {
2873
+ if (header.multiValue) {
2874
+ return header.multiValue.map((header) => header.value).join(",");
2875
+ }
2876
+ if (header.value) {
2877
+ return header.value;
2878
+ }
2879
+ }
2880
+ return "";
2881
+ }
2882
+
2883
+ function isRequestHeaderTooLarge() {
2884
+ return getRequestHeaderSize() > ${CLOUDFRONT_FUNCTION_SAFE_HEADER_LIMIT};
2885
+ }
2886
+
2887
+ function buildOversizedHeadersResponse() {
2888
+ return {
2889
+ statusCode: 431,
2890
+ statusDescription: "Request Header Fields Too Large",
2891
+ headers: {
2892
+ "cache-control": { value: "no-store" },
2893
+ "content-type": { value: "text/plain; charset=utf-8" },
2894
+ },
2895
+ body: {
2896
+ encoding: "text",
2897
+ data: "Request headers are too large. Reduce cookie size and try again.",
2898
+ },
2899
+ };
2900
+ }
2901
+
2902
+ function getRequestHeaderSize() {
2903
+ var size = 0;
2904
+
2905
+ for (var key in event.request.headers) {
2906
+ var header = event.request.headers[key];
2907
+ if (header.multiValue) {
2908
+ for (var i=0; i<header.multiValue.length; i++) {
2909
+ size += key.length + header.multiValue[i].value.length + 4;
2910
+ }
2911
+ } else if (header.value) {
2912
+ size += key.length + header.value.length + 4;
2913
+ }
2914
+ }
2915
+
2916
+ var cookies = [];
2917
+ for (var key in event.request.cookies) {
2918
+ var cookie = event.request.cookies[key];
2919
+ if (cookie.multiValue) {
2920
+ for (var i=0; i<cookie.multiValue.length; i++) {
2921
+ cookies.push(key + "=" + cookie.multiValue[i].value);
2922
+ }
2923
+ } else {
2924
+ cookies.push(key + "=" + cookie.value);
2925
+ }
2926
+ }
2927
+
2928
+ if (cookies.length) {
2929
+ size += 10 + cookies.join("; ").length;
2930
+ }
2931
+
2932
+ return size;
2933
+ }
2934
+
2935
+ function findNearestServer(servers) {
2936
+ if (servers.length === 1) return servers[0][0];
2937
+
2938
+ const h = event.request.headers;
2939
+ const lat = h["cloudfront-viewer-latitude"] && h["cloudfront-viewer-latitude"].value;
2940
+ const lon = h["cloudfront-viewer-longitude"] && h["cloudfront-viewer-longitude"].value;
2941
+ if (!lat || !lon) return servers[0][0];
2942
+
2943
+ return servers
2944
+ .map((s) => ({
2945
+ distance: haversineDistance(lat, lon, s[1], s[2]),
2946
+ host: s[0],
2947
+ }))
2948
+ .sort((a, b) => a.distance - b.distance)[0]
2949
+ .host;
2950
+ }
2951
+
2952
+ function haversineDistance(lat1, lon1, lat2, lon2) {
2953
+ const toRad = angle => angle * Math.PI / 180;
2954
+ const radLat1 = toRad(lat1);
2955
+ const radLat2 = toRad(lat2);
2956
+ const dLat = toRad(lat2 - lat1);
2957
+ const dLon = toRad(lon2 - lon1);
2958
+ const a = Math.sin(dLat / 2) ** 2 + Math.cos(radLat1) * Math.cos(radLat2) * Math.sin(dLon / 2) ** 2;
2959
+ return 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
2960
+ }
2961
+ }
2962
+
2963
+ function setForwardedHost() {
2964
+ // Lambda URLs expect the original viewer host in x-forwarded-host.
2965
+ event.request.headers["x-forwarded-host"] = event.request.headers.host;
2966
+ }
2967
+
2968
+ function setUrlOrigin(urlHost, override) {
2969
+ setForwardedHost();
2970
+ const origin = {
2971
+ domainName: urlHost,
2972
+ customOriginConfig: {
2973
+ port: 443,
2974
+ protocol: "https",
2975
+ sslProtocols: ["TLSv1.2"],
2976
+ },
2977
+ originAccessControlConfig: {
2978
+ enabled: false,
2979
+ }
2980
+ };
2981
+ override = override ?? {};
2982
+ if (override.protocol === "http") {
2983
+ delete origin.customOriginConfig;
2984
+ }
2985
+ if (override.connectionAttempts) {
2986
+ origin.connectionAttempts = override.connectionAttempts;
2987
+ }
2988
+ if (override.timeouts) {
2989
+ origin.timeouts = override.timeouts;
2990
+ }
2991
+ if (override.originAccessControlConfig) {
2992
+ origin.originAccessControlConfig = override.originAccessControlConfig;
2993
+ }
2994
+ cf.updateRequestOrigin(origin);
2995
+ }
2996
+
2997
+ function setS3Origin(s3Domain, override) {
2998
+ delete event.request.headers["Cookies"];
2999
+ delete event.request.headers["cookies"];
3000
+ delete event.request.cookies;
3001
+
3002
+ const origin = {
3003
+ domainName: s3Domain,
3004
+ originAccessControlConfig: {
3005
+ enabled: true,
3006
+ signingBehavior: "always",
3007
+ signingProtocol: "sigv4",
3008
+ originType: "s3",
3009
+ }
3010
+ };
3011
+ override = override ?? {};
3012
+ if (override.connectionAttempts) {
3013
+ origin.connectionAttempts = override.connectionAttempts;
3014
+ }
3015
+ if (override.timeouts) {
3016
+ origin.timeouts = override.timeouts;
3017
+ }
3018
+ cf.updateRequestOrigin(origin);
3019
+ }`;
3020
+
3021
+ export type KV_SITE_METADATA = {
3022
+ base?: string; // Undefined or "" if no base path. Otherwise starts with "/" and never ends with one (so never "/"): the router strips it with `base + "/"`.
3023
+ custom404?: string;
3024
+ errorResponseCode?: number;
3025
+ s3: {
3026
+ domain: string;
3027
+ dir: string; // Should be "" if no dir
3028
+ prefix?: string; // The path prefix the files are stored under, "" if none. Missing in metadata from older versions.
3029
+ routes: string[];
3030
+ };
3031
+ image?: {
3032
+ host: string;
3033
+ route: string;
3034
+ originAccessControlConfig?: {
3035
+ enabled: boolean;
3036
+ signingBehavior: string;
3037
+ signingProtocol: string;
3038
+ originType: string;
3039
+ };
3040
+ };
3041
+ servers?: [string, number, number][];
3042
+ origin?: {
3043
+ timeouts: {
3044
+ readTimeout: number;
3045
+ };
3046
+ originAccessControlConfig?: {
3047
+ enabled: boolean;
3048
+ signingBehavior: string;
3049
+ signingProtocol: string;
3050
+ originType: string;
3051
+ };
3052
+ };
3053
+ };
3054
+
3055
+ export type ProtectionConfig = {
3056
+ mode: "none" | "oac" | "oac-with-edge-signing";
3057
+ edgeFunction?: {
3058
+ arn?: string;
3059
+ memory?: Size;
3060
+ timeout?: DurationSeconds;
3061
+ };
3062
+ };
3063
+
3064
+ export type RouterRouteArgs = {
3065
+ /**
3066
+ * The `Router` component to use for routing requests.
3067
+ *
3068
+ * @example
3069
+ *
3070
+ * Let's say you have a Router component.
3071
+ *
3072
+ * ```ts title="sst.config.ts"
3073
+ * const router = new sst.aws.Router("MyRouter", {
3074
+ * domain: "example.com"
3075
+ * });
3076
+ * ```
3077
+ *
3078
+ * You can attach it to the Router, instead of creating a standalone CloudFront
3079
+ * distribution.
3080
+ *
3081
+ * ```ts
3082
+ * router: {
3083
+ * instance: router
3084
+ * }
3085
+ * ```
3086
+ */
3087
+ instance: Input<Router>;
3088
+ /**
3089
+ * Route requests matching a specific domain pattern.
3090
+ *
3091
+ * @example
3092
+ *
3093
+ * You can serve your resource from a subdomain. For example, if you want to make
3094
+ * it available at `https://dev.example.com`, set the `Router` to match the
3095
+ * domain or a wildcard.
3096
+ *
3097
+ * ```ts {2} title="sst.config.ts"
3098
+ * const router = new sst.aws.Router("MyRouter", {
3099
+ * domain: "*.example.com"
3100
+ * });
3101
+ * ```
3102
+ *
3103
+ * Then set the domain pattern.
3104
+ *
3105
+ * ```ts {3}
3106
+ * router: {
3107
+ * instance: router,
3108
+ * domain: "dev.example.com"
3109
+ * }
3110
+ * ```
3111
+ *
3112
+ * While `dev.example.com` matches `*.example.com`. Something like
3113
+ * `docs.dev.example.com` will not match `*.example.com`.
3114
+ *
3115
+ * :::tip
3116
+ * Nested wildcards domain patterns are not supported.
3117
+ * :::
3118
+ *
3119
+ * You'll need to add `*.dev.example.com` as an alias.
3120
+ */
3121
+ domain?: Input<string>;
3122
+ /**
3123
+ * Route requests matching a specific path prefix.
3124
+ *
3125
+ * @default `"/"`
3126
+ *
3127
+ * @example
3128
+ *
3129
+ * ```ts {3}
3130
+ * router: {
3131
+ * instance: router,
3132
+ * path: "/docs"
3133
+ * }
3134
+ * ```
3135
+ */
3136
+ path?: Input<string>;
3137
+ /**
3138
+ * Rewrite the request path.
3139
+ *
3140
+ * @example
3141
+ *
3142
+ * If the route path is `/api/*` and a request comes in for `/api/users/profile`,
3143
+ * the request path the destination sees is `/api/users/profile`.
3144
+ *
3145
+ * If you want to serve the route from the root, you can rewrite the request
3146
+ * path to `/users/profile`.
3147
+ *
3148
+ * ```js
3149
+ * router: {
3150
+ * instance: router,
3151
+ * path: "/api",
3152
+ * rewrite: {
3153
+ * regex: "^/api/(.*)$",
3154
+ * to: "/$1"
3155
+ * }
3156
+ * }
3157
+ * ```
3158
+ */
3159
+ rewrite?: Input<{
3160
+ /**
3161
+ * The regex to match the request path.
3162
+ */
3163
+ regex: Input<string>;
3164
+ /**
3165
+ * The replacement for the matched path.
3166
+ */
3167
+ to: Input<string>;
3168
+ }>;
3169
+ /**
3170
+ * The number of seconds that CloudFront waits for a response after routing a
3171
+ * request to the destination. Must be between 1 and 60 seconds.
3172
+ *
3173
+ * When compared to the `connectionTimeout`, this is the total time for the
3174
+ * request.
3175
+ *
3176
+ * @default `"20 seconds"`
3177
+ * @example
3178
+ * ```js
3179
+ * router: {
3180
+ * instance: router,
3181
+ * readTimeout: "60 seconds"
3182
+ * }
3183
+ * ```
3184
+ */
3185
+ readTimeout?: Input<DurationSeconds>;
3186
+ /**
3187
+ * The number of seconds that CloudFront should try to maintain the connection
3188
+ * to the destination after receiving the last packet of the response. Must be
3189
+ * between 1 and 60 seconds.
3190
+ *
3191
+ * @default `"5 seconds"`
3192
+ * @example
3193
+ * ```js
3194
+ * router: {
3195
+ * instance: router,
3196
+ * keepAliveTimeout: "10 seconds"
3197
+ * }
3198
+ * ```
3199
+ */
3200
+ keepAliveTimeout?: Input<DurationSeconds>;
3201
+ /**
3202
+ * The number of seconds that CloudFront waits before timing out and closing the
3203
+ * connection to the origin. Must be between 1 and 10 seconds.
3204
+ *
3205
+ * @default `"10 seconds"`
3206
+ * @example
3207
+ * ```js
3208
+ * router: {
3209
+ * instance: router,
3210
+ * connectionTimeout: "3 seconds"
3211
+ * }
3212
+ * ```
3213
+ */
3214
+ connectionTimeout?: Input<DurationSeconds>;
3215
+ /**
3216
+ * The number of times that CloudFront attempts to connect to the origin. Must be
3217
+ * between 1 and 3.
3218
+ *
3219
+ * @default `3`
3220
+ * @example
3221
+ * ```js
3222
+ * router: {
3223
+ * instance: router,
3224
+ * connectionAttempts: 1
3225
+ * }
3226
+ * ```
3227
+ */
3228
+ connectionAttempts?: Input<number>;
3229
+ };
3230
+
3231
+ export type RouterRouteArgsDeprecated = {
3232
+ router: Input<Router>;
3233
+ domain?: Input<string>;
3234
+ path?: Input<string>;
3235
+ };
3236
+
3237
+ export function normalizeRouteArgs(
3238
+ route?: Input<RouterRouteArgs>,
3239
+ routeDeprecated?: Input<RouterRouteArgsDeprecated>,
3240
+ ) {
3241
+ if (!route && !routeDeprecated) return undefined;
3242
+
3243
+ return all([route, routeDeprecated]).apply(([route, routeDeprecated]) => {
3244
+ const v = route
3245
+ ? route
3246
+ : { ...routeDeprecated, instance: routeDeprecated!.router };
3247
+
3248
+ return v.instance._hasInlineRoutes.apply((hasInlineRoutes) => {
3249
+ if (hasInlineRoutes)
3250
+ throw new VisibleError(
3251
+ "Cannot route the site using the provided router. The Router component uses inline routes which has been deprecated.",
3252
+ );
3253
+
3254
+ const pathPrefix = v.path
3255
+ ? "/" + v.path.replace(/^\//, "").replace(/\/$/, "")
3256
+ : undefined;
3257
+ return {
3258
+ hostPattern: v.domain
3259
+ ? v.domain
3260
+ .replace(/[.+?^${}()|[\]\\]/g, "\\$&") // Escape special regex chars
3261
+ .replace(/\*/g, ".*") // Replace * with .*
3262
+ : undefined,
3263
+ pathPrefix,
3264
+ routerDistributionId: v.instance.nodes.cdn.nodes.distribution.id,
3265
+ routerUrl: v.instance.url.apply(
3266
+ (url) =>
3267
+ (v.domain ? `https://${v.domain}` : url) + (pathPrefix ?? ""),
3268
+ ),
3269
+ routerKvNamespace: v.instance._kvNamespace!,
3270
+ routerKvStoreArn: v.instance._kvStoreArn!,
3271
+ routerProtection: v.instance._protection,
3272
+ routerDistributionArn: v.instance._distributionArn,
3273
+ rewrite: v.rewrite,
3274
+ readTimeout: v.readTimeout,
3275
+ keepAliveTimeout: v.keepAliveTimeout,
3276
+ connectionTimeout: v.connectionTimeout,
3277
+ connectionAttempts: v.connectionAttempts,
3278
+ };
3279
+ });
3280
+ });
3281
+ }