cloudcommerce 0.20.2 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/.gitmodules +3 -0
  2. package/.nvmrc +1 -0
  3. package/.vscode/settings.json +2 -1
  4. package/CHANGELOG.md +44 -0
  5. package/action.yml +37 -13
  6. package/ecomplus-stores/iluminim/.devcontainer/devcontainer.json +30 -0
  7. package/ecomplus-stores/iluminim/.eslintrc.cjs +3 -0
  8. package/ecomplus-stores/iluminim/.firebaserc +5 -0
  9. package/ecomplus-stores/iluminim/.github/renovate.json +5 -0
  10. package/ecomplus-stores/iluminim/.github/workflows/build-and-deploy.yml +36 -0
  11. package/ecomplus-stores/iluminim/.github/workflows/calibreapp-image-actions.yml +23 -0
  12. package/ecomplus-stores/iluminim/.gitpod.yml +12 -0
  13. package/ecomplus-stores/iluminim/.nvmrc +1 -0
  14. package/ecomplus-stores/iluminim/.vscode/extensions.json +8 -0
  15. package/ecomplus-stores/iluminim/.vscode/launch.json +11 -0
  16. package/ecomplus-stores/iluminim/.vscode/settings.json +10 -0
  17. package/ecomplus-stores/iluminim/README.md +113 -0
  18. package/ecomplus-stores/iluminim/README.pt-BR.md +113 -0
  19. package/ecomplus-stores/iluminim/functions/config.json +3 -0
  20. package/ecomplus-stores/iluminim/functions/example.env +10 -0
  21. package/ecomplus-stores/iluminim/functions/many/index.js +14 -0
  22. package/ecomplus-stores/iluminim/functions/many/package.json +22 -0
  23. package/ecomplus-stores/iluminim/functions/ssr/.eslintrc.cjs +6 -0
  24. package/ecomplus-stores/iluminim/functions/ssr/astro.config.mjs +4 -0
  25. package/ecomplus-stores/iluminim/functions/ssr/content/blog/.gitkeep +0 -0
  26. package/ecomplus-stores/iluminim/functions/ssr/content/extra-pages/.gitkeep +0 -0
  27. package/ecomplus-stores/iluminim/functions/ssr/content/layout.json +33 -0
  28. package/ecomplus-stores/iluminim/functions/ssr/content/pages/home.json +70 -0
  29. package/ecomplus-stores/iluminim/functions/ssr/content/settings.json +49 -0
  30. package/ecomplus-stores/iluminim/functions/ssr/index.js +18 -0
  31. package/ecomplus-stores/iluminim/functions/ssr/package.json +31 -0
  32. package/ecomplus-stores/iluminim/functions/ssr/public/admin/.gitkeep +2 -0
  33. package/ecomplus-stores/iluminim/functions/ssr/public/assets/cms-preview.css +274 -0
  34. package/ecomplus-stores/iluminim/functions/ssr/public/assets/cms.css +114 -0
  35. package/ecomplus-stores/iluminim/functions/ssr/public/assets/cvv.png +0 -0
  36. package/ecomplus-stores/iluminim/functions/ssr/public/assets/img-placeholder.png +0 -0
  37. package/ecomplus-stores/iluminim/functions/ssr/public/assets/payments.png +0 -0
  38. package/ecomplus-stores/iluminim/functions/ssr/public/assets/ssl-safe.png +0 -0
  39. package/ecomplus-stores/iluminim/functions/ssr/public/img/icon.png +0 -0
  40. package/ecomplus-stores/iluminim/functions/ssr/public/img/large-icon.png +0 -0
  41. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/banner-chamada-desktop-9x81zmd91q.webp +0 -0
  42. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/banner2.webp +0 -0
  43. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/chamada-mobile-q1c6om6jx4.webp +0 -0
  44. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/ecom-icon.png +0 -0
  45. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/headphone.webp +0 -0
  46. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/logo.webp +0 -0
  47. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/og-image.png +0 -0
  48. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/passion.webp +0 -0
  49. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/rect8589.png +0 -0
  50. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/rect859.png +0 -0
  51. package/ecomplus-stores/iluminim/functions/ssr/public/img/uploads/rect89.webp +0 -0
  52. package/ecomplus-stores/iluminim/functions/ssr/public/robots.txt +8 -0
  53. package/ecomplus-stores/iluminim/functions/ssr/scripts/build.sh +14 -0
  54. package/ecomplus-stores/iluminim/functions/ssr/src/assets/style.css +65 -0
  55. package/ecomplus-stores/iluminim/functions/ssr/src/components/AccountMenu.vue +104 -0
  56. package/ecomplus-stores/iluminim/functions/ssr/src/components/Banner.vue +59 -0
  57. package/ecomplus-stores/iluminim/functions/ssr/src/components/BannersGrid.astro +25 -0
  58. package/ecomplus-stores/iluminim/functions/ssr/src/components/CartSidebar.vue +35 -0
  59. package/ecomplus-stores/iluminim/functions/ssr/src/components/Countdown.vue +79 -0
  60. package/ecomplus-stores/iluminim/functions/ssr/src/components/HeroSlider.vue +52 -0
  61. package/ecomplus-stores/iluminim/functions/ssr/src/components/PitchBar.vue +57 -0
  62. package/ecomplus-stores/iluminim/functions/ssr/src/components/Prices.vue +96 -0
  63. package/ecomplus-stores/iluminim/functions/ssr/src/components/ProductCard.vue +118 -0
  64. package/ecomplus-stores/iluminim/functions/ssr/src/components/ProductShelf.vue +60 -0
  65. package/ecomplus-stores/iluminim/functions/ssr/src/components/ProductsCountdown.vue +20 -0
  66. package/ecomplus-stores/iluminim/functions/ssr/src/components/SearchModal.vue +6 -0
  67. package/ecomplus-stores/iluminim/functions/ssr/src/components/ShopHeader.vue +137 -0
  68. package/ecomplus-stores/iluminim/functions/ssr/src/components/ShopHeaderMenu.vue +58 -0
  69. package/ecomplus-stores/iluminim/functions/ssr/src/components/ShopHeaderSubmenu.vue +88 -0
  70. package/ecomplus-stores/iluminim/functions/ssr/src/components/ShopSidenav.vue +61 -0
  71. package/ecomplus-stores/iluminim/functions/ssr/src/components/ShopSidenavCategory.vue +78 -0
  72. package/ecomplus-stores/iluminim/functions/ssr/src/env.d.ts +13 -0
  73. package/ecomplus-stores/iluminim/functions/ssr/src/layouts/Base.astro +16 -0
  74. package/ecomplus-stores/iluminim/functions/ssr/src/layouts/Checkout.astro +0 -0
  75. package/ecomplus-stores/iluminim/functions/ssr/src/layouts/PageHeader.astro +33 -0
  76. package/ecomplus-stores/iluminim/functions/ssr/src/main/Fallback.astro +10 -0
  77. package/ecomplus-stores/iluminim/functions/ssr/src/main/Home.astro +49 -0
  78. package/ecomplus-stores/iluminim/functions/ssr/src/main/Sections.astro +42 -0
  79. package/ecomplus-stores/iluminim/functions/ssr/src/main/Wildcard.astro +18 -0
  80. package/ecomplus-stores/iluminim/functions/ssr/src/pages/[...slug].astro +40 -0
  81. package/ecomplus-stores/iluminim/functions/ssr/src/pages/_vue.ts +3 -0
  82. package/ecomplus-stores/iluminim/functions/ssr/src/pages/app/account.astro +0 -0
  83. package/ecomplus-stores/iluminim/functions/ssr/src/pages/app/index.astro +0 -0
  84. package/ecomplus-stores/iluminim/functions/ssr/src/pages/fallback.astro +25 -0
  85. package/ecomplus-stores/iluminim/functions/ssr/src/pages/index.astro +35 -0
  86. package/ecomplus-stores/iluminim/functions/ssr/src/scripts/InlineScripts.astro +10 -0
  87. package/ecomplus-stores/iluminim/functions/ssr/tailwind.config.cjs +13 -0
  88. package/ecomplus-stores/iluminim/functions/ssr/tsconfig.json +12 -0
  89. package/ecomplus-stores/iluminim/functions/ssr/uno.config.cjs +5 -0
  90. package/ecomplus-stores/iluminim/functions/with-apps/index.js +12 -0
  91. package/ecomplus-stores/iluminim/functions/with-apps/package.json +22 -0
  92. package/ecomplus-stores/iluminim/package.json +28 -0
  93. package/ecomplus-stores/iluminim/scripts/install.sh +14 -0
  94. package/ecomplus-stores/monocard/.eslintrc.cjs +3 -0
  95. package/ecomplus-stores/monocard/.nvmrc +1 -0
  96. package/ecomplus-stores/tia-sonia/.eslintrc.cjs +3 -0
  97. package/ecomplus-stores/tia-sonia/.nvmrc +1 -0
  98. package/package.json +4 -4
  99. package/packages/api/package.json +1 -1
  100. package/packages/api/types.d.ts +1 -1
  101. package/packages/apps/affilate-program/package.json +1 -1
  102. package/packages/apps/correios/package.json +1 -1
  103. package/packages/apps/custom-payment/package.json +1 -1
  104. package/packages/apps/custom-shipping/package.json +1 -1
  105. package/packages/apps/datafrete/package.json +1 -1
  106. package/packages/apps/discounts/package.json +1 -1
  107. package/packages/apps/emails/package.json +1 -1
  108. package/packages/apps/fb-conversions/package.json +1 -1
  109. package/packages/apps/flash-courier/package.json +1 -1
  110. package/packages/apps/frenet/package.json +1 -1
  111. package/packages/apps/galaxpay/package.json +1 -1
  112. package/packages/apps/google-analytics/package.json +1 -1
  113. package/packages/apps/jadlog/package.json +1 -1
  114. package/packages/apps/loyalty-points/package.json +1 -1
  115. package/packages/apps/melhor-envio/package.json +1 -1
  116. package/packages/apps/mercadopago/package.json +1 -1
  117. package/packages/apps/pagarme/package.json +1 -1
  118. package/packages/apps/paghiper/package.json +1 -1
  119. package/packages/apps/pix/package.json +1 -1
  120. package/packages/apps/tiny-erp/package.json +1 -1
  121. package/packages/apps/webhooks/package.json +1 -1
  122. package/packages/cli/config/firebase.json +10 -0
  123. package/packages/cli/package.json +1 -1
  124. package/packages/config/package.json +1 -1
  125. package/packages/emails/package.json +2 -2
  126. package/packages/events/package.json +1 -1
  127. package/packages/feeds/package.json +1 -1
  128. package/packages/firebase/package.json +1 -1
  129. package/packages/i18n/lib/en_us/i19hour.txt +1 -0
  130. package/packages/i18n/lib/en_us/i19hours.txt +1 -0
  131. package/packages/i18n/lib/en_us/i19milliseconds.txt +1 -0
  132. package/packages/i18n/lib/en_us/i19minute.txt +1 -0
  133. package/packages/i18n/lib/en_us/i19minutes.txt +1 -0
  134. package/packages/i18n/lib/en_us/i19second.txt +1 -0
  135. package/packages/i18n/lib/en_us/i19seconds.txt +1 -0
  136. package/packages/i18n/lib/en_us.d.ts +7 -0
  137. package/packages/i18n/lib/en_us.js +7 -0
  138. package/packages/i18n/lib/en_us.js.map +1 -1
  139. package/packages/i18n/lib/pt_br/i19home.txt +1 -1
  140. package/packages/i18n/lib/pt_br/i19hour.txt +1 -0
  141. package/packages/i18n/lib/pt_br/i19hours.txt +1 -0
  142. package/packages/i18n/lib/pt_br/i19milliseconds.txt +1 -0
  143. package/packages/i18n/lib/pt_br/i19minute.txt +1 -0
  144. package/packages/i18n/lib/pt_br/i19minutes.txt +1 -0
  145. package/packages/i18n/lib/pt_br/i19second.txt +1 -0
  146. package/packages/i18n/lib/pt_br/i19seconds.txt +1 -0
  147. package/packages/i18n/lib/pt_br.d.ts +8 -1
  148. package/packages/i18n/lib/pt_br.js +8 -1
  149. package/packages/i18n/lib/pt_br.js.map +1 -1
  150. package/packages/i18n/package.json +1 -1
  151. package/packages/i18n/src/en_us.ts +7 -0
  152. package/packages/i18n/src/pt_br.ts +8 -1
  153. package/packages/modules/package.json +1 -1
  154. package/packages/passport/package.json +1 -1
  155. package/packages/ssr/lib/firebase/serve-storefront.js +24 -18
  156. package/packages/ssr/lib/firebase/serve-storefront.js.map +1 -1
  157. package/packages/ssr/package.json +2 -2
  158. package/packages/ssr/src/firebase/serve-storefront.ts +25 -18
  159. package/packages/storefront/.eslintrc.cjs +8 -1
  160. package/packages/storefront/client.d.ts +1 -19
  161. package/packages/storefront/dist/client/_astro/HeroSlider.0890631f.js +1 -0
  162. package/packages/storefront/dist/client/_astro/{ShopHeader.0c884bbe.js → ShopHeader.82ae97a5.js} +1 -1
  163. package/packages/storefront/dist/client/_astro/_...slug_.c85b8978.css +1 -0
  164. package/packages/storefront/dist/client/_astro/{client.8035a95a.js → client.0fb6b44e.js} +1 -1
  165. package/packages/storefront/dist/client/_astro/{hoisted.9d9d7ac4.js → hoisted.572313d6.js} +1 -1
  166. package/packages/storefront/dist/client/sw.js +1 -1
  167. package/packages/storefront/dist/server/chunks/_...7e1df40a.mjs +34 -0
  168. package/packages/storefront/dist/server/chunks/{account@_@astro.89e4cf60.mjs → account@_@astro.5f1dba7a.mjs} +7 -8
  169. package/packages/storefront/dist/server/chunks/{astro.45d3047f.mjs → astro.2d3ebf0f.mjs} +560 -511
  170. package/packages/storefront/dist/server/chunks/{endpoint@_@js.f880a152.mjs → endpoint@_@js.80de0568.mjs} +7 -8
  171. package/packages/storefront/dist/server/chunks/{fallback@_@astro.89538855.mjs → fallback@_@astro.02a45b47.mjs} +7 -8
  172. package/packages/storefront/dist/server/chunks/{index@_@astro.56fdd6da.mjs → index@_@astro.23b50301.mjs} +7 -8
  173. package/packages/storefront/dist/server/chunks/{index@_@astro.548cf7ad.mjs → index@_@astro.7cb07e52.mjs} +7 -8
  174. package/packages/storefront/dist/server/chunks/pages/{_...slug_.astro.bde9380b.mjs → _...slug_.astro.4358f614.mjs} +92 -104
  175. package/packages/storefront/dist/server/chunks/pages/{account.astro.f07cf19e.mjs → account.astro.afae5a12.mjs} +6 -6
  176. package/packages/storefront/dist/server/chunks/pages/{endpoint.js.d4e37801.mjs → endpoint.js.60fd21aa.mjs} +1 -1
  177. package/packages/storefront/dist/server/chunks/pages/{fallback.astro.e2e8a0e4.mjs → fallback.astro.e5566925.mjs} +10 -10
  178. package/packages/storefront/dist/server/chunks/pages/{index.astro.3760ebe3.mjs → index.astro.5bc6b9d8.mjs} +34 -32
  179. package/packages/storefront/dist/server/entry.mjs +13 -12
  180. package/packages/storefront/dist/server/renderers.mjs +7 -8
  181. package/packages/storefront/package.json +2 -2
  182. package/packages/storefront/server.d.ts +3 -27
  183. package/packages/storefront/src/lib/$storefront.d.ts +28 -0
  184. package/packages/storefront/src/lib/assets/base.css +2 -0
  185. package/packages/storefront/src/lib/layouts/Base.astro +1 -9
  186. package/packages/storefront/src/lib/layouts/BaseHead.astro +73 -2
  187. package/packages/storefront/src/lib/layouts/use-page-main.ts +18 -5
  188. package/packages/storefront/src/lib/pages/_vue.ts +1 -1
  189. package/packages/storefront/src/lib/server-data.ts +1 -1
  190. package/packages/storefront/src/lib/ssr-context.ts +46 -36
  191. package/packages/storefront/src/vue-globals.d.ts +3 -3
  192. package/packages/types/package.json +1 -1
  193. package/pnpm-workspace.yaml +2 -2
  194. package/packages/storefront/dist/client/_astro/HeroSlider.eb156f18.js +0 -1
  195. package/packages/storefront/dist/client/_astro/_...slug_.c2da43fb.css +0 -1
  196. package/packages/storefront/dist/server/chunks/_...9e22b578.mjs +0 -35
  197. package/packages/storefront/src/lib/composables/use-hero-slider.ts +0 -26
  198. package/packages/storefront/src/lib/layouts/BaseStateJson.astro +0 -68
@@ -1,13 +1,13 @@
1
1
  import { compile } from 'path-to-regexp';
2
2
  import { serialize, parse } from 'cookie';
3
3
  import { joinPaths, slash, prependForwardSlash, removeTrailingForwardSlash } from '@astrojs/internal-helpers/path';
4
- import { bold, yellow, dim, cyan, red, reset } from 'kleur/colors';
5
- import 'fs';
6
- import 'http';
7
- import { TLSSocket } from 'tls';
4
+ import { yellow, dim, bold, cyan, red, reset } from 'kleur/colors';
5
+ import 'node:fs';
6
+ import 'node:http';
7
+ import { TLSSocket } from 'node:tls';
8
8
  import mime from 'mime';
9
- import { escape } from 'html-escaper';
10
9
  import 'string-width';
10
+ import { escape } from 'html-escaper';
11
11
 
12
12
  const AstroErrorData = {
13
13
  /**
@@ -1115,7 +1115,7 @@ function validateArgs(args) {
1115
1115
  return false;
1116
1116
  return true;
1117
1117
  }
1118
- function baseCreateComponent(cb, moduleId) {
1118
+ function baseCreateComponent(cb, moduleId, propagation) {
1119
1119
  var _a;
1120
1120
  const name = ((_a = moduleId == null ? void 0 : moduleId.split("/").pop()) == null ? void 0 : _a.replace(".astro", "")) ?? "";
1121
1121
  const fn = (...args) => {
@@ -1130,22 +1130,22 @@ function baseCreateComponent(cb, moduleId) {
1130
1130
  Object.defineProperty(fn, "name", { value: name, writable: false });
1131
1131
  fn.isAstroComponentFactory = true;
1132
1132
  fn.moduleId = moduleId;
1133
+ fn.propagation = propagation;
1133
1134
  return fn;
1134
1135
  }
1135
1136
  function createComponentWithOptions(opts) {
1136
- const cb = baseCreateComponent(opts.factory, opts.moduleId);
1137
- cb.propagation = opts.propagation;
1137
+ const cb = baseCreateComponent(opts.factory, opts.moduleId, opts.propagation);
1138
1138
  return cb;
1139
1139
  }
1140
- function createComponent(arg1, moduleId) {
1140
+ function createComponent(arg1, moduleId, propagation) {
1141
1141
  if (typeof arg1 === "function") {
1142
- return baseCreateComponent(arg1, moduleId);
1142
+ return baseCreateComponent(arg1, moduleId, propagation);
1143
1143
  } else {
1144
1144
  return createComponentWithOptions(arg1);
1145
1145
  }
1146
1146
  }
1147
1147
 
1148
- const ASTRO_VERSION = "2.8.3";
1148
+ const ASTRO_VERSION = "2.9.0";
1149
1149
 
1150
1150
  function createAstroGlobFn() {
1151
1151
  const globHandler = (importMetaGlobResult) => {
@@ -3363,6 +3363,82 @@ if (typeof process !== "undefined") {
3363
3363
  }
3364
3364
  }
3365
3365
 
3366
+ let lastMessage;
3367
+ let lastMessageCount = 1;
3368
+ const consoleLogDestination = {
3369
+ write(event) {
3370
+ let dest = console.error;
3371
+ if (levels[event.level] < levels["error"]) {
3372
+ dest = console.log;
3373
+ }
3374
+ function getPrefix() {
3375
+ let prefix = "";
3376
+ let type = event.type;
3377
+ if (type) {
3378
+ prefix += dim(dateTimeFormat.format(/* @__PURE__ */ new Date()) + " ");
3379
+ if (event.level === "info") {
3380
+ type = bold(cyan(`[${type}]`));
3381
+ } else if (event.level === "warn") {
3382
+ type = bold(yellow(`[${type}]`));
3383
+ } else if (event.level === "error") {
3384
+ type = bold(red(`[${type}]`));
3385
+ }
3386
+ prefix += `${type} `;
3387
+ }
3388
+ return reset(prefix);
3389
+ }
3390
+ let message = event.message;
3391
+ if (message === lastMessage) {
3392
+ lastMessageCount++;
3393
+ message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
3394
+ } else {
3395
+ lastMessage = message;
3396
+ lastMessageCount = 1;
3397
+ }
3398
+ const outMessage = getPrefix() + message;
3399
+ dest(outMessage);
3400
+ return true;
3401
+ }
3402
+ };
3403
+
3404
+ const RedirectComponentInstance = {
3405
+ default() {
3406
+ return new Response(null, {
3407
+ status: 301
3408
+ });
3409
+ }
3410
+ };
3411
+ const RedirectSinglePageBuiltModule = {
3412
+ page: () => Promise.resolve(RedirectComponentInstance),
3413
+ onRequest: (ctx, next) => next(),
3414
+ renderers: []
3415
+ };
3416
+
3417
+ function routeIsRedirect(route) {
3418
+ return (route == null ? void 0 : route.type) === "redirect";
3419
+ }
3420
+ function redirectRouteGenerate(redirectRoute, data) {
3421
+ const routeData = redirectRoute.redirectRoute;
3422
+ const route = redirectRoute.redirect;
3423
+ if (typeof routeData !== "undefined") {
3424
+ return (routeData == null ? void 0 : routeData.generate(data)) || (routeData == null ? void 0 : routeData.pathname) || "/";
3425
+ } else if (typeof route === "string") {
3426
+ return route;
3427
+ } else if (typeof route === "undefined") {
3428
+ return "/";
3429
+ }
3430
+ return route.destination;
3431
+ }
3432
+ function redirectRouteStatus(redirectRoute, method = "GET") {
3433
+ const routeData = redirectRoute.redirectRoute;
3434
+ if (typeof (routeData == null ? void 0 : routeData.redirect) === "object") {
3435
+ return routeData.redirect.status;
3436
+ } else if (method !== "GET") {
3437
+ return 308;
3438
+ }
3439
+ return 301;
3440
+ }
3441
+
3366
3442
  async function callMiddleware(logging, onRequest, apiContext, responseFunction) {
3367
3443
  let nextCalled = false;
3368
3444
  let responseFunctionPromise = void 0;
@@ -3514,139 +3590,335 @@ async function callEndpoint(mod, env, ctx, onRequest) {
3514
3590
  };
3515
3591
  }
3516
3592
 
3517
- let lastMessage;
3518
- let lastMessageCount = 1;
3519
- const consoleLogDestination = {
3520
- write(event) {
3521
- let dest = console.error;
3522
- if (levels[event.level] < levels["error"]) {
3523
- dest = console.log;
3524
- }
3525
- function getPrefix() {
3526
- let prefix = "";
3527
- let type = event.type;
3528
- if (type) {
3529
- prefix += dim(dateTimeFormat.format(/* @__PURE__ */ new Date()) + " ");
3530
- if (event.level === "info") {
3531
- type = bold(cyan(`[${type}]`));
3532
- } else if (event.level === "warn") {
3533
- type = bold(yellow(`[${type}]`));
3534
- } else if (event.level === "error") {
3535
- type = bold(red(`[${type}]`));
3593
+ const clientAddressSymbol$1 = Symbol.for("astro.clientAddress");
3594
+ const responseSentSymbol$1 = Symbol.for("astro.responseSent");
3595
+ function getFunctionExpression(slot) {
3596
+ var _a;
3597
+ if (!slot)
3598
+ return;
3599
+ if (((_a = slot.expressions) == null ? void 0 : _a.length) !== 1)
3600
+ return;
3601
+ return slot.expressions[0];
3602
+ }
3603
+ class Slots {
3604
+ #result;
3605
+ #slots;
3606
+ #loggingOpts;
3607
+ constructor(result, slots, logging) {
3608
+ this.#result = result;
3609
+ this.#slots = slots;
3610
+ this.#loggingOpts = logging;
3611
+ if (slots) {
3612
+ for (const key of Object.keys(slots)) {
3613
+ if (this[key] !== void 0) {
3614
+ throw new AstroError({
3615
+ ...AstroErrorData.ReservedSlotName,
3616
+ message: AstroErrorData.ReservedSlotName.message(key)
3617
+ });
3536
3618
  }
3537
- prefix += `${type} `;
3619
+ Object.defineProperty(this, key, {
3620
+ get() {
3621
+ return true;
3622
+ },
3623
+ enumerable: true
3624
+ });
3538
3625
  }
3539
- return reset(prefix);
3540
- }
3541
- let message = event.message;
3542
- if (message === lastMessage) {
3543
- lastMessageCount++;
3544
- message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
3545
- } else {
3546
- lastMessage = message;
3547
- lastMessageCount = 1;
3548
3626
  }
3549
- const outMessage = getPrefix() + message;
3550
- dest(outMessage);
3551
- return true;
3552
- }
3553
- };
3554
-
3555
- const RedirectComponentInstance = {
3556
- default() {
3557
- return new Response(null, {
3558
- status: 301
3559
- });
3560
- }
3561
- };
3562
- const RedirectSinglePageBuiltModule = {
3563
- page: () => Promise.resolve(RedirectComponentInstance),
3564
- onRequest: (ctx, next) => next(),
3565
- renderers: []
3566
- };
3567
-
3568
- function routeIsRedirect(route) {
3569
- return (route == null ? void 0 : route.type) === "redirect";
3570
- }
3571
- function redirectRouteGenerate(redirectRoute, data) {
3572
- const routeData = redirectRoute.redirectRoute;
3573
- const route = redirectRoute.redirect;
3574
- if (typeof routeData !== "undefined") {
3575
- return (routeData == null ? void 0 : routeData.generate(data)) || (routeData == null ? void 0 : routeData.pathname) || "/";
3576
- } else if (typeof route === "string") {
3577
- return route;
3578
- } else if (typeof route === "undefined") {
3579
- return "/";
3580
3627
  }
3581
- return route.destination;
3582
- }
3583
- function redirectRouteStatus(redirectRoute, method = "GET") {
3584
- const routeData = redirectRoute.redirectRoute;
3585
- if (typeof (routeData == null ? void 0 : routeData.redirect) === "object") {
3586
- return routeData.redirect.status;
3587
- } else if (method !== "GET") {
3588
- return 308;
3628
+ has(name) {
3629
+ if (!this.#slots)
3630
+ return false;
3631
+ return Boolean(this.#slots[name]);
3589
3632
  }
3590
- return 301;
3591
- }
3592
-
3593
- const VALID_PARAM_TYPES = ["string", "number", "undefined"];
3594
- function validateGetStaticPathsParameter([key, value], route) {
3595
- if (!VALID_PARAM_TYPES.includes(typeof value)) {
3596
- throw new AstroError({
3597
- ...AstroErrorData.GetStaticPathsInvalidRouteParam,
3598
- message: AstroErrorData.GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
3599
- location: {
3600
- file: route
3633
+ async render(name, args = []) {
3634
+ if (!this.#slots || !this.has(name))
3635
+ return;
3636
+ const result = this.#result;
3637
+ if (!Array.isArray(args)) {
3638
+ warn(
3639
+ this.#loggingOpts,
3640
+ "Astro.slots.render",
3641
+ `Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
3642
+ );
3643
+ } else if (args.length > 0) {
3644
+ const slotValue = this.#slots[name];
3645
+ const component = typeof slotValue === "function" ? await slotValue(result) : await slotValue;
3646
+ const expression = getFunctionExpression(component);
3647
+ if (expression) {
3648
+ const slot = async () => isHTMLString(await expression) ? expression : expression(...args);
3649
+ return await renderSlotToString(result, slot).then((res) => {
3650
+ return res != null ? String(res) : res;
3651
+ });
3601
3652
  }
3602
- });
3603
- }
3604
- }
3605
- function validateDynamicRouteModule(mod, {
3606
- ssr,
3607
- logging,
3608
- route
3609
- }) {
3610
- if (ssr && mod.getStaticPaths && !route.prerender) {
3611
- warn(
3612
- logging,
3613
- "getStaticPaths",
3614
- `getStaticPaths() in ${bold(route.component)} is ignored when "output: server" is set.`
3615
- );
3616
- }
3617
- if ((!ssr || route.prerender) && !mod.getStaticPaths) {
3618
- throw new AstroError({
3619
- ...AstroErrorData.GetStaticPathsRequired,
3620
- location: { file: route.component }
3621
- });
3622
- }
3623
- }
3624
- function validateGetStaticPathsResult(result, logging, route) {
3625
- if (!Array.isArray(result)) {
3626
- throw new AstroError({
3627
- ...AstroErrorData.InvalidGetStaticPathsReturn,
3628
- message: AstroErrorData.InvalidGetStaticPathsReturn.message(typeof result),
3629
- location: {
3630
- file: route.component
3653
+ if (typeof component === "function") {
3654
+ return await renderJSX(result, component(...args)).then(
3655
+ (res) => res != null ? String(res) : res
3656
+ );
3631
3657
  }
3632
- });
3633
- }
3634
- result.forEach((pathObject) => {
3635
- if (pathObject.params === void 0 || pathObject.params === null || pathObject.params && Object.keys(pathObject.params).length === 0) {
3636
- throw new AstroError({
3637
- ...AstroErrorData.GetStaticPathsExpectedParams,
3638
- location: {
3639
- file: route.component
3640
- }
3641
- });
3642
3658
  }
3643
- if (typeof pathObject.params !== "object") {
3644
- throw new AstroError({
3645
- ...AstroErrorData.InvalidGetStaticPathParam,
3646
- message: AstroErrorData.InvalidGetStaticPathParam.message(typeof pathObject.params),
3647
- location: {
3648
- file: route.component
3649
- }
3659
+ const content = await renderSlotToString(result, this.#slots[name]);
3660
+ const outHTML = stringifyChunk(result, content);
3661
+ return outHTML;
3662
+ }
3663
+ }
3664
+ let renderMarkdown = null;
3665
+ function createResult(args) {
3666
+ const { markdown, params, request, resolve, locals } = args;
3667
+ const url = new URL(request.url);
3668
+ const headers = new Headers();
3669
+ headers.set("Content-Type", "text/html");
3670
+ const response = {
3671
+ status: args.status,
3672
+ statusText: "OK",
3673
+ headers
3674
+ };
3675
+ Object.defineProperty(response, "headers", {
3676
+ value: response.headers,
3677
+ enumerable: true,
3678
+ writable: false
3679
+ });
3680
+ let cookies = args.cookies;
3681
+ const result = {
3682
+ styles: args.styles ?? /* @__PURE__ */ new Set(),
3683
+ scripts: args.scripts ?? /* @__PURE__ */ new Set(),
3684
+ links: args.links ?? /* @__PURE__ */ new Set(),
3685
+ componentMetadata: args.componentMetadata ?? /* @__PURE__ */ new Map(),
3686
+ renderers: args.renderers,
3687
+ clientDirectives: args.clientDirectives,
3688
+ compressHTML: args.compressHTML,
3689
+ pathname: args.pathname,
3690
+ cookies,
3691
+ /** This function returns the `Astro` faux-global */
3692
+ createAstro(astroGlobal, props, slots) {
3693
+ const astroSlots = new Slots(result, slots, args.logging);
3694
+ const Astro = {
3695
+ // @ts-expect-error
3696
+ __proto__: astroGlobal,
3697
+ get clientAddress() {
3698
+ if (!(clientAddressSymbol$1 in request)) {
3699
+ if (args.adapterName) {
3700
+ throw new AstroError({
3701
+ ...AstroErrorData.ClientAddressNotAvailable,
3702
+ message: AstroErrorData.ClientAddressNotAvailable.message(args.adapterName)
3703
+ });
3704
+ } else {
3705
+ throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
3706
+ }
3707
+ }
3708
+ return Reflect.get(request, clientAddressSymbol$1);
3709
+ },
3710
+ get cookies() {
3711
+ if (cookies) {
3712
+ return cookies;
3713
+ }
3714
+ cookies = new AstroCookies(request);
3715
+ result.cookies = cookies;
3716
+ return cookies;
3717
+ },
3718
+ params,
3719
+ props,
3720
+ locals,
3721
+ request,
3722
+ url,
3723
+ redirect(path, status) {
3724
+ if (request[responseSentSymbol$1]) {
3725
+ throw new AstroError({
3726
+ ...AstroErrorData.ResponseSentError
3727
+ });
3728
+ }
3729
+ return new Response(null, {
3730
+ status: status || 302,
3731
+ headers: {
3732
+ Location: path
3733
+ }
3734
+ });
3735
+ },
3736
+ response,
3737
+ slots: astroSlots
3738
+ };
3739
+ Object.defineProperty(Astro, "__renderMarkdown", {
3740
+ // Ensure this API is not exposed to users
3741
+ enumerable: false,
3742
+ writable: false,
3743
+ // TODO: Remove this hole "Deno" logic once our plugin gets Deno support
3744
+ value: async function(content, opts) {
3745
+ if (typeof Deno !== "undefined") {
3746
+ throw new Error("Markdown is not supported in Deno SSR");
3747
+ }
3748
+ if (!renderMarkdown) {
3749
+ let astroRemark = "@astrojs/";
3750
+ astroRemark += "markdown-remark";
3751
+ renderMarkdown = (await import(astroRemark)).renderMarkdown;
3752
+ }
3753
+ const { code } = await renderMarkdown(content, { ...markdown, ...opts ?? {} });
3754
+ return code;
3755
+ }
3756
+ });
3757
+ return Astro;
3758
+ },
3759
+ resolve,
3760
+ response,
3761
+ _metadata: {
3762
+ hasHydrationScript: false,
3763
+ hasRenderedHead: false,
3764
+ hasDirectives: /* @__PURE__ */ new Set(),
3765
+ headInTree: false,
3766
+ extraHead: [],
3767
+ propagators: /* @__PURE__ */ new Map()
3768
+ }
3769
+ };
3770
+ return result;
3771
+ }
3772
+
3773
+ async function renderPage({ mod, renderContext, env, cookies }) {
3774
+ if (routeIsRedirect(renderContext.route)) {
3775
+ return new Response(null, {
3776
+ status: redirectRouteStatus(renderContext.route, renderContext.request.method),
3777
+ headers: {
3778
+ location: redirectRouteGenerate(renderContext.route, renderContext.params)
3779
+ }
3780
+ });
3781
+ }
3782
+ const Component = mod.default;
3783
+ if (!Component)
3784
+ throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
3785
+ const result = createResult({
3786
+ adapterName: env.adapterName,
3787
+ links: renderContext.links,
3788
+ styles: renderContext.styles,
3789
+ logging: env.logging,
3790
+ markdown: env.markdown,
3791
+ params: renderContext.params,
3792
+ pathname: renderContext.pathname,
3793
+ componentMetadata: renderContext.componentMetadata,
3794
+ resolve: env.resolve,
3795
+ renderers: env.renderers,
3796
+ clientDirectives: env.clientDirectives,
3797
+ compressHTML: env.compressHTML,
3798
+ request: renderContext.request,
3799
+ site: env.site,
3800
+ scripts: renderContext.scripts,
3801
+ ssr: env.ssr,
3802
+ status: renderContext.status ?? 200,
3803
+ cookies,
3804
+ locals: renderContext.locals ?? {}
3805
+ });
3806
+ if (typeof mod.components === "object") {
3807
+ Object.assign(renderContext.props, { components: mod.components });
3808
+ }
3809
+ let response = await renderPage$1(
3810
+ result,
3811
+ Component,
3812
+ renderContext.props,
3813
+ null,
3814
+ env.streaming,
3815
+ renderContext.route
3816
+ );
3817
+ if (result.cookies) {
3818
+ attachToResponse(response, result.cookies);
3819
+ }
3820
+ return response;
3821
+ }
3822
+ async function tryRenderRoute(routeType, renderContext, env, mod, onRequest) {
3823
+ const apiContext = createAPIContext({
3824
+ request: renderContext.request,
3825
+ params: renderContext.params,
3826
+ props: renderContext.props,
3827
+ site: env.site,
3828
+ adapterName: env.adapterName
3829
+ });
3830
+ switch (routeType) {
3831
+ case "page":
3832
+ case "redirect": {
3833
+ if (onRequest) {
3834
+ return await callMiddleware(
3835
+ env.logging,
3836
+ onRequest,
3837
+ apiContext,
3838
+ () => {
3839
+ return renderPage({
3840
+ mod,
3841
+ renderContext,
3842
+ env,
3843
+ cookies: apiContext.cookies
3844
+ });
3845
+ }
3846
+ );
3847
+ } else {
3848
+ return await renderPage({
3849
+ mod,
3850
+ renderContext,
3851
+ env,
3852
+ cookies: apiContext.cookies
3853
+ });
3854
+ }
3855
+ }
3856
+ case "endpoint": {
3857
+ const result = await callEndpoint(
3858
+ mod,
3859
+ env,
3860
+ renderContext,
3861
+ onRequest
3862
+ );
3863
+ return result;
3864
+ }
3865
+ default:
3866
+ throw new Error(`Couldn't find route of type [${routeType}]`);
3867
+ }
3868
+ }
3869
+ function isResponse(result, routeType) {
3870
+ return result instanceof Response && (routeType === "page" || routeType === "redirect");
3871
+ }
3872
+
3873
+ const VALID_PARAM_TYPES = ["string", "number", "undefined"];
3874
+ function validateGetStaticPathsParameter([key, value], route) {
3875
+ if (!VALID_PARAM_TYPES.includes(typeof value)) {
3876
+ throw new AstroError({
3877
+ ...AstroErrorData.GetStaticPathsInvalidRouteParam,
3878
+ message: AstroErrorData.GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
3879
+ location: {
3880
+ file: route
3881
+ }
3882
+ });
3883
+ }
3884
+ }
3885
+ function validateDynamicRouteModule(mod, {
3886
+ ssr,
3887
+ route
3888
+ }) {
3889
+ if ((!ssr || route.prerender) && !mod.getStaticPaths) {
3890
+ throw new AstroError({
3891
+ ...AstroErrorData.GetStaticPathsRequired,
3892
+ location: { file: route.component }
3893
+ });
3894
+ }
3895
+ }
3896
+ function validateGetStaticPathsResult(result, logging, route) {
3897
+ if (!Array.isArray(result)) {
3898
+ throw new AstroError({
3899
+ ...AstroErrorData.InvalidGetStaticPathsReturn,
3900
+ message: AstroErrorData.InvalidGetStaticPathsReturn.message(typeof result),
3901
+ location: {
3902
+ file: route.component
3903
+ }
3904
+ });
3905
+ }
3906
+ result.forEach((pathObject) => {
3907
+ if (pathObject.params === void 0 || pathObject.params === null || pathObject.params && Object.keys(pathObject.params).length === 0) {
3908
+ throw new AstroError({
3909
+ ...AstroErrorData.GetStaticPathsExpectedParams,
3910
+ location: {
3911
+ file: route.component
3912
+ }
3913
+ });
3914
+ }
3915
+ if (typeof pathObject.params !== "object") {
3916
+ throw new AstroError({
3917
+ ...AstroErrorData.InvalidGetStaticPathParam,
3918
+ message: AstroErrorData.InvalidGetStaticPathParam.message(typeof pathObject.params),
3919
+ location: {
3920
+ file: route.component
3921
+ }
3650
3922
  });
3651
3923
  }
3652
3924
  for (const [key, val] of Object.entries(pathObject.params)) {
@@ -3684,14 +3956,14 @@ function getParams(array) {
3684
3956
  };
3685
3957
  return fn;
3686
3958
  }
3687
- function stringifyParams(params, routeComponent) {
3959
+ function stringifyParams(params, route) {
3688
3960
  const validatedParams = Object.entries(params).reduce((acc, next) => {
3689
- validateGetStaticPathsParameter(next, routeComponent);
3961
+ validateGetStaticPathsParameter(next, route.component);
3690
3962
  const [key, value] = next;
3691
3963
  acc[key] = value == null ? void 0 : value.toString();
3692
3964
  return acc;
3693
3965
  }, {});
3694
- return JSON.stringify(validatedParams, Object.keys(params).sort());
3966
+ return JSON.stringify(route.generate(validatedParams));
3695
3967
  }
3696
3968
 
3697
3969
  function generatePaginateFunction(routeMatch) {
@@ -3767,7 +4039,7 @@ async function callGetStaticPaths({
3767
4039
  const cached = routeCache.get(route);
3768
4040
  if (cached == null ? void 0 : cached.staticPaths)
3769
4041
  return cached.staticPaths;
3770
- validateDynamicRouteModule(mod, { ssr, logging, route });
4042
+ validateDynamicRouteModule(mod, { ssr, route });
3771
4043
  if (ssr && !route.prerender) {
3772
4044
  const entry = Object.assign([], { keyed: /* @__PURE__ */ new Map() });
3773
4045
  routeCache.set(route, { ...cached, staticPaths: entry });
@@ -3792,7 +4064,7 @@ async function callGetStaticPaths({
3792
4064
  const keyedStaticPaths = staticPaths;
3793
4065
  keyedStaticPaths.keyed = /* @__PURE__ */ new Map();
3794
4066
  for (const sp of keyedStaticPaths) {
3795
- const paramsKey = stringifyParams(sp.params, route.component);
4067
+ const paramsKey = stringifyParams(sp.params, route);
3796
4068
  keyedStaticPaths.keyed.set(paramsKey, sp);
3797
4069
  }
3798
4070
  routeCache.set(route, { ...cached, staticPaths: keyedStaticPaths });
@@ -3824,7 +4096,7 @@ class RouteCache {
3824
4096
  }
3825
4097
  }
3826
4098
  function findPathItemByKey(staticPaths, params, route) {
3827
- const paramsKey = stringifyParams(params, route.component);
4099
+ const paramsKey = stringifyParams(params, route);
3828
4100
  const matchedStaticPath = staticPaths.keyed.get(paramsKey);
3829
4101
  if (matchedStaticPath) {
3830
4102
  return matchedStaticPath;
@@ -3918,238 +4190,8 @@ async function createRenderContext(options) {
3918
4190
  return context;
3919
4191
  }
3920
4192
 
3921
- const clientAddressSymbol$1 = Symbol.for("astro.clientAddress");
3922
- const responseSentSymbol$1 = Symbol.for("astro.responseSent");
3923
- function getFunctionExpression(slot) {
3924
- var _a;
3925
- if (!slot)
3926
- return;
3927
- if (((_a = slot.expressions) == null ? void 0 : _a.length) !== 1)
3928
- return;
3929
- return slot.expressions[0];
3930
- }
3931
- class Slots {
3932
- #result;
3933
- #slots;
3934
- #loggingOpts;
3935
- constructor(result, slots, logging) {
3936
- this.#result = result;
3937
- this.#slots = slots;
3938
- this.#loggingOpts = logging;
3939
- if (slots) {
3940
- for (const key of Object.keys(slots)) {
3941
- if (this[key] !== void 0) {
3942
- throw new AstroError({
3943
- ...AstroErrorData.ReservedSlotName,
3944
- message: AstroErrorData.ReservedSlotName.message(key)
3945
- });
3946
- }
3947
- Object.defineProperty(this, key, {
3948
- get() {
3949
- return true;
3950
- },
3951
- enumerable: true
3952
- });
3953
- }
3954
- }
3955
- }
3956
- has(name) {
3957
- if (!this.#slots)
3958
- return false;
3959
- return Boolean(this.#slots[name]);
3960
- }
3961
- async render(name, args = []) {
3962
- if (!this.#slots || !this.has(name))
3963
- return;
3964
- const result = this.#result;
3965
- if (!Array.isArray(args)) {
3966
- warn(
3967
- this.#loggingOpts,
3968
- "Astro.slots.render",
3969
- `Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
3970
- );
3971
- } else if (args.length > 0) {
3972
- const slotValue = this.#slots[name];
3973
- const component = typeof slotValue === "function" ? await slotValue(result) : await slotValue;
3974
- const expression = getFunctionExpression(component);
3975
- if (expression) {
3976
- const slot = async () => isHTMLString(await expression) ? expression : expression(...args);
3977
- return await renderSlotToString(result, slot).then((res) => {
3978
- return res != null ? String(res) : res;
3979
- });
3980
- }
3981
- if (typeof component === "function") {
3982
- return await renderJSX(result, component(...args)).then(
3983
- (res) => res != null ? String(res) : res
3984
- );
3985
- }
3986
- }
3987
- const content = await renderSlotToString(result, this.#slots[name]);
3988
- const outHTML = stringifyChunk(result, content);
3989
- return outHTML;
3990
- }
3991
- }
3992
- let renderMarkdown = null;
3993
- function createResult(args) {
3994
- const { markdown, params, request, resolve, locals } = args;
3995
- const url = new URL(request.url);
3996
- const headers = new Headers();
3997
- headers.set("Content-Type", "text/html");
3998
- const response = {
3999
- status: args.status,
4000
- statusText: "OK",
4001
- headers
4002
- };
4003
- Object.defineProperty(response, "headers", {
4004
- value: response.headers,
4005
- enumerable: true,
4006
- writable: false
4007
- });
4008
- let cookies = args.cookies;
4009
- const result = {
4010
- styles: args.styles ?? /* @__PURE__ */ new Set(),
4011
- scripts: args.scripts ?? /* @__PURE__ */ new Set(),
4012
- links: args.links ?? /* @__PURE__ */ new Set(),
4013
- componentMetadata: args.componentMetadata ?? /* @__PURE__ */ new Map(),
4014
- renderers: args.renderers,
4015
- clientDirectives: args.clientDirectives,
4016
- compressHTML: args.compressHTML,
4017
- pathname: args.pathname,
4018
- cookies,
4019
- /** This function returns the `Astro` faux-global */
4020
- createAstro(astroGlobal, props, slots) {
4021
- const astroSlots = new Slots(result, slots, args.logging);
4022
- const Astro = {
4023
- // @ts-expect-error
4024
- __proto__: astroGlobal,
4025
- get clientAddress() {
4026
- if (!(clientAddressSymbol$1 in request)) {
4027
- if (args.adapterName) {
4028
- throw new AstroError({
4029
- ...AstroErrorData.ClientAddressNotAvailable,
4030
- message: AstroErrorData.ClientAddressNotAvailable.message(args.adapterName)
4031
- });
4032
- } else {
4033
- throw new AstroError(AstroErrorData.StaticClientAddressNotAvailable);
4034
- }
4035
- }
4036
- return Reflect.get(request, clientAddressSymbol$1);
4037
- },
4038
- get cookies() {
4039
- if (cookies) {
4040
- return cookies;
4041
- }
4042
- cookies = new AstroCookies(request);
4043
- result.cookies = cookies;
4044
- return cookies;
4045
- },
4046
- params,
4047
- props,
4048
- locals,
4049
- request,
4050
- url,
4051
- redirect(path, status) {
4052
- if (request[responseSentSymbol$1]) {
4053
- throw new AstroError({
4054
- ...AstroErrorData.ResponseSentError
4055
- });
4056
- }
4057
- return new Response(null, {
4058
- status: status || 302,
4059
- headers: {
4060
- Location: path
4061
- }
4062
- });
4063
- },
4064
- response,
4065
- slots: astroSlots
4066
- };
4067
- Object.defineProperty(Astro, "__renderMarkdown", {
4068
- // Ensure this API is not exposed to users
4069
- enumerable: false,
4070
- writable: false,
4071
- // TODO: Remove this hole "Deno" logic once our plugin gets Deno support
4072
- value: async function(content, opts) {
4073
- if (typeof Deno !== "undefined") {
4074
- throw new Error("Markdown is not supported in Deno SSR");
4075
- }
4076
- if (!renderMarkdown) {
4077
- let astroRemark = "@astrojs/";
4078
- astroRemark += "markdown-remark";
4079
- renderMarkdown = (await import(astroRemark)).renderMarkdown;
4080
- }
4081
- const { code } = await renderMarkdown(content, { ...markdown, ...opts ?? {} });
4082
- return code;
4083
- }
4084
- });
4085
- return Astro;
4086
- },
4087
- resolve,
4088
- response,
4089
- _metadata: {
4090
- hasHydrationScript: false,
4091
- hasRenderedHead: false,
4092
- hasDirectives: /* @__PURE__ */ new Set(),
4093
- headInTree: false,
4094
- extraHead: [],
4095
- propagators: /* @__PURE__ */ new Map()
4096
- }
4097
- };
4098
- return result;
4099
- }
4100
-
4101
- async function renderPage({ mod, renderContext, env, cookies }) {
4102
- if (routeIsRedirect(renderContext.route)) {
4103
- return new Response(null, {
4104
- status: redirectRouteStatus(renderContext.route, renderContext.request.method),
4105
- headers: {
4106
- location: redirectRouteGenerate(renderContext.route, renderContext.params)
4107
- }
4108
- });
4109
- }
4110
- const Component = mod.default;
4111
- if (!Component)
4112
- throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
4113
- const result = createResult({
4114
- adapterName: env.adapterName,
4115
- links: renderContext.links,
4116
- styles: renderContext.styles,
4117
- logging: env.logging,
4118
- markdown: env.markdown,
4119
- params: renderContext.params,
4120
- pathname: renderContext.pathname,
4121
- componentMetadata: renderContext.componentMetadata,
4122
- resolve: env.resolve,
4123
- renderers: env.renderers,
4124
- clientDirectives: env.clientDirectives,
4125
- compressHTML: env.compressHTML,
4126
- request: renderContext.request,
4127
- site: env.site,
4128
- scripts: renderContext.scripts,
4129
- ssr: env.ssr,
4130
- status: renderContext.status ?? 200,
4131
- cookies,
4132
- locals: renderContext.locals ?? {}
4133
- });
4134
- if (typeof mod.components === "object") {
4135
- Object.assign(renderContext.props, { components: mod.components });
4136
- }
4137
- let response = await renderPage$1(
4138
- result,
4139
- Component,
4140
- renderContext.props,
4141
- null,
4142
- env.streaming,
4143
- renderContext.route
4144
- );
4145
- if (result.cookies) {
4146
- attachToResponse(response, result.cookies);
4147
- }
4148
- return response;
4149
- }
4150
-
4151
- function createEnvironment(options) {
4152
- return options;
4193
+ function createEnvironment(options) {
4194
+ return options;
4153
4195
  }
4154
4196
 
4155
4197
  function createAssetLink(href, base, assetsPrefix) {
@@ -4211,6 +4253,9 @@ function matchRoute(pathname, manifest) {
4211
4253
  const clientLocalsSymbol = Symbol.for("astro.locals");
4212
4254
  const responseSentSymbol = Symbol.for("astro.responseSent");
4213
4255
  class App {
4256
+ /**
4257
+ * The current environment of the application
4258
+ */
4214
4259
  #env;
4215
4260
  #manifest;
4216
4261
  #manifestData;
@@ -4220,7 +4265,6 @@ class App {
4220
4265
  dest: consoleLogDestination,
4221
4266
  level: "info"
4222
4267
  };
4223
- #base;
4224
4268
  #baseWithoutTrailingSlash;
4225
4269
  constructor(manifest, streaming = true) {
4226
4270
  this.#manifest = manifest;
@@ -4228,26 +4272,39 @@ class App {
4228
4272
  routes: manifest.routes.map((route) => route.routeData)
4229
4273
  };
4230
4274
  this.#routeDataToRouteInfo = new Map(manifest.routes.map((route) => [route.routeData, route]));
4231
- this.#env = createEnvironment({
4232
- adapterName: manifest.adapterName,
4275
+ this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#manifest.base);
4276
+ this.#env = this.#createEnvironment(streaming);
4277
+ }
4278
+ set setManifest(newManifest) {
4279
+ this.#manifest = newManifest;
4280
+ }
4281
+ /**
4282
+ * Creates an environment by reading the stored manifest
4283
+ *
4284
+ * @param streaming
4285
+ * @private
4286
+ */
4287
+ #createEnvironment(streaming = false) {
4288
+ return createEnvironment({
4289
+ adapterName: this.#manifest.adapterName,
4233
4290
  logging: this.#logging,
4234
- markdown: manifest.markdown,
4291
+ markdown: this.#manifest.markdown,
4235
4292
  mode: "production",
4236
- compressHTML: manifest.compressHTML,
4237
- renderers: manifest.renderers,
4238
- clientDirectives: manifest.clientDirectives,
4239
- async resolve(specifier) {
4240
- if (!(specifier in manifest.entryModules)) {
4293
+ compressHTML: this.#manifest.compressHTML,
4294
+ renderers: this.#manifest.renderers,
4295
+ clientDirectives: this.#manifest.clientDirectives,
4296
+ resolve: async (specifier) => {
4297
+ if (!(specifier in this.#manifest.entryModules)) {
4241
4298
  throw new Error(`Unable to resolve [${specifier}]`);
4242
4299
  }
4243
- const bundlePath = manifest.entryModules[specifier];
4300
+ const bundlePath = this.#manifest.entryModules[specifier];
4244
4301
  switch (true) {
4245
4302
  case bundlePath.startsWith("data:"):
4246
4303
  case bundlePath.length === 0: {
4247
4304
  return bundlePath;
4248
4305
  }
4249
4306
  default: {
4250
- return createAssetLink(bundlePath, manifest.base, manifest.assetsPrefix);
4307
+ return createAssetLink(bundlePath, this.#manifest.base, this.#manifest.assetsPrefix);
4251
4308
  }
4252
4309
  }
4253
4310
  },
@@ -4256,11 +4313,12 @@ class App {
4256
4313
  ssr: true,
4257
4314
  streaming
4258
4315
  });
4259
- this.#base = this.#manifest.base || "/";
4260
- this.#baseWithoutTrailingSlash = removeTrailingForwardSlash(this.#base);
4316
+ }
4317
+ set setManifestData(newManifestData) {
4318
+ this.#manifestData = newManifestData;
4261
4319
  }
4262
4320
  removeBase(pathname) {
4263
- if (pathname.startsWith(this.#base)) {
4321
+ if (pathname.startsWith(this.#manifest.base)) {
4264
4322
  return pathname.slice(this.#baseWithoutTrailingSlash.length + 1);
4265
4323
  }
4266
4324
  return pathname;
@@ -4305,34 +4363,140 @@ class App {
4305
4363
  defaultStatus = 404;
4306
4364
  }
4307
4365
  let mod = await this.#getModuleForRoute(routeData);
4308
- if (routeData.type === "page" || routeData.type === "redirect") {
4309
- let response = await this.#renderPage(request, routeData, mod, defaultStatus);
4366
+ const pageModule = await mod.page();
4367
+ const url = new URL(request.url);
4368
+ const renderContext = await this.#createRenderContext(
4369
+ url,
4370
+ request,
4371
+ routeData,
4372
+ mod,
4373
+ defaultStatus
4374
+ );
4375
+ let response;
4376
+ try {
4377
+ response = await tryRenderRoute(
4378
+ routeData.type,
4379
+ renderContext,
4380
+ this.#env,
4381
+ pageModule,
4382
+ mod.onRequest
4383
+ );
4384
+ } catch (err) {
4385
+ error(this.#logging, "ssr", err.stack || err.message || String(err));
4386
+ response = new Response(null, {
4387
+ status: 500,
4388
+ statusText: "Internal server error"
4389
+ });
4390
+ }
4391
+ if (isResponse(response, routeData.type)) {
4310
4392
  if (response.status === 500 || response.status === 404) {
4311
4393
  const errorRouteData = matchRoute("/" + response.status, this.#manifestData);
4312
4394
  if (errorRouteData && errorRouteData.route !== routeData.route) {
4313
4395
  mod = await this.#getModuleForRoute(errorRouteData);
4314
4396
  try {
4315
- let errorResponse = await this.#renderPage(
4397
+ const newRenderContext = await this.#createRenderContext(
4398
+ url,
4316
4399
  request,
4317
- errorRouteData,
4400
+ routeData,
4318
4401
  mod,
4319
4402
  response.status
4320
4403
  );
4404
+ const page = await mod.page();
4405
+ const errorResponse = await tryRenderRoute(
4406
+ routeData.type,
4407
+ newRenderContext,
4408
+ this.#env,
4409
+ page
4410
+ );
4321
4411
  return errorResponse;
4322
4412
  } catch {
4323
4413
  }
4324
4414
  }
4325
4415
  }
4416
+ Reflect.set(response, responseSentSymbol, true);
4326
4417
  return response;
4327
- } else if (routeData.type === "endpoint") {
4328
- return this.#callEndpoint(request, routeData, mod, defaultStatus);
4329
4418
  } else {
4330
- throw new Error(`Unsupported route type [${routeData.type}].`);
4419
+ if (response.type === "response") {
4420
+ if (response.response.headers.get("X-Astro-Response") === "Not-Found") {
4421
+ const fourOhFourRequest = new Request(new URL("/404", request.url));
4422
+ const fourOhFourRouteData = this.match(fourOhFourRequest);
4423
+ if (fourOhFourRouteData) {
4424
+ return this.render(fourOhFourRequest, fourOhFourRouteData);
4425
+ }
4426
+ }
4427
+ return response.response;
4428
+ } else {
4429
+ const body = response.body;
4430
+ const headers = new Headers();
4431
+ const mimeType = mime.getType(url.pathname);
4432
+ if (mimeType) {
4433
+ headers.set("Content-Type", `${mimeType};charset=utf-8`);
4434
+ } else {
4435
+ headers.set("Content-Type", "text/plain;charset=utf-8");
4436
+ }
4437
+ const bytes = this.#encoder.encode(body);
4438
+ headers.set("Content-Length", bytes.byteLength.toString());
4439
+ const newResponse = new Response(bytes, {
4440
+ status: 200,
4441
+ headers
4442
+ });
4443
+ attachToResponse(newResponse, response.cookies);
4444
+ return newResponse;
4445
+ }
4331
4446
  }
4332
4447
  }
4333
4448
  setCookieHeaders(response) {
4334
4449
  return getSetCookiesFromResponse(response);
4335
4450
  }
4451
+ /**
4452
+ * Creates the render context of the current route
4453
+ */
4454
+ async #createRenderContext(url, request, routeData, page, status = 200) {
4455
+ if (routeData.type === "endpoint") {
4456
+ const pathname = "/" + this.removeBase(url.pathname);
4457
+ const mod = await page.page();
4458
+ const handler = mod;
4459
+ return await createRenderContext({
4460
+ request,
4461
+ pathname,
4462
+ route: routeData,
4463
+ status,
4464
+ env: this.#env,
4465
+ mod: handler
4466
+ });
4467
+ } else {
4468
+ const pathname = prependForwardSlash(this.removeBase(url.pathname));
4469
+ const info = this.#routeDataToRouteInfo.get(routeData);
4470
+ const links = /* @__PURE__ */ new Set();
4471
+ const styles = createStylesheetElementSet(info.styles);
4472
+ let scripts = /* @__PURE__ */ new Set();
4473
+ for (const script of info.scripts) {
4474
+ if ("stage" in script) {
4475
+ if (script.stage === "head-inline") {
4476
+ scripts.add({
4477
+ props: {},
4478
+ children: script.children
4479
+ });
4480
+ }
4481
+ } else {
4482
+ scripts.add(createModuleScriptElement(script));
4483
+ }
4484
+ }
4485
+ const mod = await page.page();
4486
+ return await createRenderContext({
4487
+ request,
4488
+ pathname,
4489
+ componentMetadata: this.#manifest.componentMetadata,
4490
+ scripts,
4491
+ styles,
4492
+ links,
4493
+ route: routeData,
4494
+ status,
4495
+ mod,
4496
+ env: this.#env
4497
+ });
4498
+ }
4499
+ }
4336
4500
  async #getModuleForRoute(route) {
4337
4501
  if (route.type === "redirect") {
4338
4502
  return RedirectSinglePageBuiltModule;
@@ -4356,121 +4520,6 @@ class App {
4356
4520
  }
4357
4521
  }
4358
4522
  }
4359
- async #renderPage(request, routeData, page, status = 200) {
4360
- const url = new URL(request.url);
4361
- const pathname = prependForwardSlash(this.removeBase(url.pathname));
4362
- const info = this.#routeDataToRouteInfo.get(routeData);
4363
- const links = /* @__PURE__ */ new Set();
4364
- const styles = createStylesheetElementSet(info.styles);
4365
- let scripts = /* @__PURE__ */ new Set();
4366
- for (const script of info.scripts) {
4367
- if ("stage" in script) {
4368
- if (script.stage === "head-inline") {
4369
- scripts.add({
4370
- props: {},
4371
- children: script.children
4372
- });
4373
- }
4374
- } else {
4375
- scripts.add(createModuleScriptElement(script));
4376
- }
4377
- }
4378
- try {
4379
- const mod = await page.page();
4380
- const renderContext = await createRenderContext({
4381
- request,
4382
- pathname,
4383
- componentMetadata: this.#manifest.componentMetadata,
4384
- scripts,
4385
- styles,
4386
- links,
4387
- route: routeData,
4388
- status,
4389
- mod,
4390
- env: this.#env
4391
- });
4392
- const apiContext = createAPIContext({
4393
- request: renderContext.request,
4394
- params: renderContext.params,
4395
- props: renderContext.props,
4396
- site: this.#env.site,
4397
- adapterName: this.#env.adapterName
4398
- });
4399
- let response;
4400
- if (page.onRequest) {
4401
- response = await callMiddleware(
4402
- this.#env.logging,
4403
- page.onRequest,
4404
- apiContext,
4405
- () => {
4406
- return renderPage({
4407
- mod,
4408
- renderContext,
4409
- env: this.#env,
4410
- cookies: apiContext.cookies
4411
- });
4412
- }
4413
- );
4414
- } else {
4415
- response = await renderPage({
4416
- mod,
4417
- renderContext,
4418
- env: this.#env,
4419
- cookies: apiContext.cookies
4420
- });
4421
- }
4422
- Reflect.set(request, responseSentSymbol, true);
4423
- return response;
4424
- } catch (err) {
4425
- error(this.#logging, "ssr", err.stack || err.message || String(err));
4426
- return new Response(null, {
4427
- status: 500,
4428
- statusText: "Internal server error"
4429
- });
4430
- }
4431
- }
4432
- async #callEndpoint(request, routeData, page, status = 200) {
4433
- const url = new URL(request.url);
4434
- const pathname = "/" + this.removeBase(url.pathname);
4435
- const mod = await page.page();
4436
- const handler = mod;
4437
- const ctx = await createRenderContext({
4438
- request,
4439
- pathname,
4440
- route: routeData,
4441
- status,
4442
- env: this.#env,
4443
- mod: handler
4444
- });
4445
- const result = await callEndpoint(handler, this.#env, ctx, page.onRequest);
4446
- if (result.type === "response") {
4447
- if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
4448
- const fourOhFourRequest = new Request(new URL("/404", request.url));
4449
- const fourOhFourRouteData = this.match(fourOhFourRequest);
4450
- if (fourOhFourRouteData) {
4451
- return this.render(fourOhFourRequest, fourOhFourRouteData);
4452
- }
4453
- }
4454
- return result.response;
4455
- } else {
4456
- const body = result.body;
4457
- const headers = new Headers();
4458
- const mimeType = mime.getType(url.pathname);
4459
- if (mimeType) {
4460
- headers.set("Content-Type", `${mimeType};charset=utf-8`);
4461
- } else {
4462
- headers.set("Content-Type", "text/plain;charset=utf-8");
4463
- }
4464
- const bytes = this.#encoder.encode(body);
4465
- headers.set("Content-Length", bytes.byteLength.toString());
4466
- const response = new Response(bytes, {
4467
- status: 200,
4468
- headers
4469
- });
4470
- attachToResponse(response, result.cookies);
4471
- return response;
4472
- }
4473
- }
4474
4523
  }
4475
4524
 
4476
4525
  const clientAddressSymbol = Symbol.for("astro.clientAddress");
@@ -4540,4 +4589,4 @@ class NodeApp extends App {
4540
4589
  }
4541
4590
  }
4542
4591
 
4543
- export { Fragment as F, NodeApp as N, createComponent as a, addAttribute as b, createAstro as c, renderComponent as d, renderSlot as e, renderHead as f, deserializeManifest as g, server_default as h, maybeRenderHead as m, renderTemplate as r, spreadAttributes as s, unescapeHTML as u };
4592
+ export { Fragment as F, NodeApp as N, createComponent as a, renderComponent as b, createAstro as c, addAttribute as d, renderSlot as e, renderHead as f, deserializeManifest as g, server_default as h, maybeRenderHead as m, renderTemplate as r, spreadAttributes as s, unescapeHTML as u };