@riverbankcms/sdk 0.176.0 → 0.178.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 (205) hide show
  1. package/README.md +12 -4
  2. package/dist/_dts/{BlocksIslandsHydrator-DvoTk7Py.d.ts → BlocksIslandsHydrator-CrKsXtpD.d.ts} +1 -1
  3. package/dist/_dts/{Page-D-l374tU.d.ts → Page-C9i27wZA.d.ts} +7 -7
  4. package/dist/_dts/{SdkPreviewMode-22DdQAj5.d.ts → SdkPreviewMode-DzGSR3jh.d.ts} +2 -2
  5. package/dist/_dts/{client-D4p0J1lK.d.ts → client-BnYN6XsH.d.ts} +31 -7
  6. package/dist/_dts/{content-types-0WWR6dC4.d.ts → content-types-CXj6lp3d.d.ts} +4 -8
  7. package/dist/_dts/{contracts-f_ZG_SwY.d.ts → contracts-BZLwkTwL.d.ts} +3 -3
  8. package/dist/_dts/{footerPageOutline-DSeZvOaj.d.ts → footerPageOutline-D_XbQW_o.d.ts} +6 -6
  9. package/dist/_dts/{generatePageMetadata-BlitPA2D.d.ts → generatePageMetadata-ByEWwe9j.d.ts} +2 -2
  10. package/dist/_dts/{index-ZKEDvLuN.d.ts → index-0HFgCnGz.d.ts} +1 -1
  11. package/dist/_dts/{index-tcPtGdag.d.ts → index-BE9dWIsr.d.ts} +3 -3
  12. package/dist/_dts/{index-D-ai8IQd.d.ts → index-CKDRr54L.d.ts} +4 -4
  13. package/dist/_dts/{index-CoLcwjqJ.d.ts → index-D9-N1d9v.d.ts} +1 -1
  14. package/dist/_dts/{index-CKkkCgb6.d.ts → index-DCa-8TEY.d.ts} +1 -1
  15. package/dist/_dts/{index-DDsfmM4d.d.ts → index-cTpvQg_Q.d.ts} +2 -2
  16. package/dist/_dts/{index-EJMo-KSo.d.ts → index-nnEdgc3Z.d.ts} +2 -15
  17. package/dist/_dts/{loadContent-Ci932ORy.d.ts → loadContent-DYkVV6w4.d.ts} +7 -7
  18. package/dist/_dts/{request-B8jVdvgI.d.ts → request-B20VRWHH.d.ts} +55384 -55036
  19. package/dist/_dts/{resolveBlockData-DrSMuD76.d.ts → resolveBlockData-C_aK5GIS.d.ts} +5 -5
  20. package/dist/_dts/{resolvePageContent-Be4iL6-F.d.ts → resolvePageContent-YT6ndha1.d.ts} +2 -2
  21. package/dist/_dts/sdk/src/bookings/index.d.ts +2 -2
  22. package/dist/_dts/sdk/src/client/types.d.ts +2 -2
  23. package/dist/_dts/sdk/src/client.d.ts +7 -7
  24. package/dist/_dts/sdk/src/config/index.d.ts +6 -6
  25. package/dist/_dts/sdk/src/config/template-validation.d.ts +1 -1
  26. package/dist/_dts/sdk/src/config/validation.d.ts +1 -1
  27. package/dist/_dts/sdk/src/data/dataLoaderContext.d.ts +2 -2
  28. package/dist/_dts/sdk/src/data/resolveBlockData.d.ts +1 -1
  29. package/dist/_dts/sdk/src/data/types.d.ts +2 -2
  30. package/dist/_dts/sdk/src/gifting/client.d.ts +1 -2
  31. package/dist/_dts/sdk/src/index.d.ts +8 -8
  32. package/dist/_dts/sdk/src/manifest/index.d.ts +3 -3
  33. package/dist/_dts/sdk/src/metadata/index.d.ts +1 -1
  34. package/dist/_dts/sdk/src/navigation/index.d.ts +3 -3
  35. package/dist/_dts/sdk/src/next/index.d.ts +24 -12
  36. package/dist/_dts/sdk/src/next/middleware.d.ts +2 -2
  37. package/dist/_dts/sdk/src/page-converter/index.d.ts +3 -3
  38. package/dist/_dts/sdk/src/portal/client.d.ts +56 -4
  39. package/dist/_dts/sdk/src/portal/index.d.ts +95 -13
  40. package/dist/_dts/sdk/src/prebuild/index.d.ts +1 -1
  41. package/dist/_dts/sdk/src/preview-next/before-render.d.ts +2 -2
  42. package/dist/_dts/sdk/src/preview-next/client/index.d.ts +2 -2
  43. package/dist/_dts/sdk/src/preview-next/client/runtime.d.ts +1 -1
  44. package/dist/_dts/sdk/src/rendering/client.d.ts +2 -2
  45. package/dist/_dts/sdk/src/rendering/components/pageShared.d.ts +1 -1
  46. package/dist/_dts/sdk/src/rendering/helpers/loadPage.d.ts +1 -1
  47. package/dist/_dts/sdk/src/rendering/helpers/pageRuntimeSupport.d.ts +4 -4
  48. package/dist/_dts/sdk/src/rendering/index.d.ts +6 -6
  49. package/dist/_dts/sdk/src/rendering/islands/client.d.ts +1 -1
  50. package/dist/_dts/sdk/src/rendering/server.d.ts +2 -2
  51. package/dist/_dts/sdk/src/rendering/themeAdmission.d.ts +1 -1
  52. package/dist/_dts/sdk/src/routing/index.d.ts +5 -5
  53. package/dist/_dts/sdk/src/server.d.ts +5 -5
  54. package/dist/_dts/sdk/src/spam-protection/index.d.ts +2 -2
  55. package/dist/_dts/sdk/src/theme/index.d.ts +1 -1
  56. package/dist/_dts/{types-lwSgCWZ4.d.ts → types-CMZ5mkpv.d.ts} +11 -3
  57. package/dist/_dts/{types-BXMX4z2j.d.ts → types-CYcd15BQ.d.ts} +7 -7
  58. package/dist/_dts/{types-DXY64Xh4.d.ts → types-rm2M4LGx.d.ts} +4 -4
  59. package/dist/_dts/{validation-C5xp--Fu.d.ts → validation-BSxnRhyy.d.ts} +4 -6
  60. package/dist/client/{BlocksIslandsHydrator-CeYQQQs7.mjs → BlocksIslandsHydrator-D1n09bu-.mjs} +17 -17
  61. package/dist/client/{BookingMailingListNote-CDDWrY_W.mjs → BookingMailingListNote-DSD4gS96.mjs} +6 -6
  62. package/dist/client/{BookingPanelArrangement-BShQSial.mjs → BookingPanelArrangement--EkA1ZQd.mjs} +1 -1
  63. package/dist/client/{BookingQuestionFields-MbvIo2jS.mjs → BookingQuestionFields-B57oGPcj.mjs} +2 -2
  64. package/dist/client/{CalendarNavigationChevron-C6CSVfEB.mjs → CalendarNavigationChevron-qXvsFYOg.mjs} +7 -7
  65. package/dist/client/{DemoBookingPortalAccess-C9Ggcfx3.mjs → DemoBookingPortalAccess-Olvrwi3Z.mjs} +3 -3
  66. package/dist/client/{EventCalendar.client-BSMuSqg0.mjs → EventCalendar.client-DwFNFb-0.mjs} +10 -10
  67. package/dist/client/{EventCombined.client-BTrmSyUB.mjs → EventCombined.client-Ffu-aVOb.mjs} +9 -9
  68. package/dist/client/{EventItem-B0WjGXsH.mjs → EventItem-b8tVkNHA.mjs} +4 -4
  69. package/dist/client/{EventListWeekNavigation-8Ij7vuxY.mjs → EventListWeekNavigation-BxnJW_Gf.mjs} +1 -1
  70. package/dist/client/{EventListing.client-CWk2NEwd.mjs → EventListing.client-ViCnrNg4.mjs} +3 -3
  71. package/dist/client/{EventListing.view-BEH4UbSL.mjs → EventListing.view-CdjiepMf.mjs} +7 -7
  72. package/dist/client/{EventRegistrationPayment-B2EikR3f.mjs → EventRegistrationPayment-BVd70XkH.mjs} +262 -24
  73. package/dist/client/{LocationMapActions-myIQIvQL.mjs → LocationMapActions-CiMtl1Ha.mjs} +1 -1
  74. package/dist/client/{MapDrawingSvg-BfsVyPvB.mjs → MapDrawingSvg-BCZa3dpf.mjs} +1 -1
  75. package/dist/client/{Page-F3lhDvw1.mjs → Page-DqETUt-U.mjs} +22 -13
  76. package/dist/client/{SiteTermsAgreementField-BYACYP0T.mjs → SiteTermsAgreementField-DkFnbzf_.mjs} +2 -2
  77. package/dist/client/{StepIndicator-Bb7rPtSq.mjs → StepIndicator-JO2PS03n.mjs} +79 -32
  78. package/dist/client/{accordion-BfsOiweL.mjs → accordion-XgNxl0Wg.mjs} +1 -1
  79. package/dist/client/{booking-form.client-B8ohIj13.mjs → booking-form.client-ljJoDwuI.mjs} +13 -13
  80. package/dist/client/{bookingForm-CXsck2oH.mjs → bookingForm-DtEHwY4W.mjs} +4 -4
  81. package/dist/client/bookings.mjs +5 -5
  82. package/dist/client/{boxStyleClassNames-B_hcuT06.mjs → boxStyleClassNames-BHoMAcun.mjs} +2 -2
  83. package/dist/client/{carousel-Cz5Ddbsx.mjs → carousel-B3UhbFu7.mjs} +1 -1
  84. package/dist/client/{cart-CTC2oS3p.mjs → cart-DzOJfYOR.mjs} +3 -3
  85. package/dist/client/{cart.client-c1YkTC-Q.mjs → cart.client-DBG77v-5.mjs} +1 -1
  86. package/dist/client/{checkout-BeW1ufaH.mjs → checkout-LmePoEgM.mjs} +3 -3
  87. package/dist/client/{checkout.client-BeU32khQ.mjs → checkout.client-DmgZuLBT.mjs} +1 -1
  88. package/dist/client/{checkoutUrls-DVfSUSKp.mjs → checkoutUrls-CMZI8o_V.mjs} +1 -1
  89. package/dist/client/client.mjs +93 -12
  90. package/dist/client/{context-R9p5c8IH.mjs → context-CJIz4FdL.mjs} +1 -1
  91. package/dist/client/{course-CUFVJEAc.mjs → course-DBEU9IA9.mjs} +11 -4
  92. package/dist/client/{dateFormatting-CF6FWCoo.mjs → dateFormatting-UoXqBh10.mjs} +1 -1
  93. package/dist/client/{demoPortalMagicLink-tZxIm3RL.mjs → demoPortalMagicLink-6CgFZNvu.mjs} +5 -4
  94. package/dist/client/{display-4HYOb-AK.mjs → display-D1oVR5Eh.mjs} +180 -15
  95. package/dist/client/{enhanceHeaderSection-DEYDI54E.mjs → enhanceHeaderSection-DaMo6len.mjs} +3 -3
  96. package/dist/client/{event-details.client-BwjBJP-f.mjs → event-details.client-BwASwKIq.mjs} +1 -1
  97. package/dist/client/{event-registration.client-DWvSODTI.mjs → event-registration.client-b6APrFQe.mjs} +118 -180
  98. package/dist/client/{eventCalendar-C9Pn9eeZ.mjs → eventCalendar-DJYz7yZf.mjs} +4 -4
  99. package/dist/client/{eventCombined-Bdhk0fp0.mjs → eventCombined-j9VCVgMW.mjs} +4 -4
  100. package/dist/client/{eventDetails-C2LfNW_o.mjs → eventDetails-BzGOVDI-.mjs} +2 -2
  101. package/dist/client/{eventListing-B-bJOQUk.mjs → eventListing-DWgpGuFM.mjs} +4 -4
  102. package/dist/client/{eventRegistration-CbdmUiDT.mjs → eventRegistration-DCinRot3.mjs} +4 -4
  103. package/dist/client/{form-BbUUt784.mjs → form-BBBtRwvy.mjs} +3 -3
  104. package/dist/client/{form.client-BVlz-9_t.mjs → form.client-CZeRQLGF.mjs} +4 -4
  105. package/dist/client/{form.parts-TB4UIrML.mjs → form.parts-DhGGv4_L.mjs} +1 -1
  106. package/dist/client/{formatDate-TDHhFjFN.mjs → formatDate-DVFVDcDW.mjs} +1 -1
  107. package/dist/client/gifting/client.mjs +6 -5
  108. package/dist/client/{gifting-CbNSrp7C.mjs → gifting-Di9-SpwW.mjs} +4 -4
  109. package/dist/client/{gifting.client-B__bGhFc.mjs → gifting.client-CjT5PrAZ.mjs} +4 -4
  110. package/dist/client/{gifting.parts-CTA1sDW6.mjs → gifting.parts-ffP6mjMd.mjs} +2 -2
  111. package/dist/client/{headerSection-5Wn9nUW_.mjs → headerSection-jjAvtSZk.mjs} +2 -2
  112. package/dist/client/{lookSurfaces-BwiNdgMU.mjs → lookSurfaces-C2VzJfyG.mjs} +1 -1
  113. package/dist/client/{newsletter-form.client-B17WYHxZ.mjs → newsletter-form.client-D45frHoa.mjs} +5 -5
  114. package/dist/client/{newsletter-form.parts-DN9wD1ZG.mjs → newsletter-form.parts-CHdg82ct.mjs} +1 -1
  115. package/dist/client/{newsletterForm-DLMlxInp.mjs → newsletterForm-tS465_vl.mjs} +3 -3
  116. package/dist/client/{noop-CaQxI-Js.mjs → noop-D11X-B6n.mjs} +123 -91
  117. package/dist/client/portal/client.mjs +384 -38
  118. package/dist/client/{product-detail.client-Di_anRGR.mjs → product-detail.client-DIWSeW7P.mjs} +1 -1
  119. package/dist/client/{product-list.client-Duhl6rtL.mjs → product-list.client-BRf14h_e.mjs} +1 -1
  120. package/dist/client/{productDetail-BgKmCwA8.mjs → productDetail-gxF5whea.mjs} +3 -3
  121. package/dist/client/{productList-C_wMKsYS.mjs → productList-B9t0XJrN.mjs} +3 -3
  122. package/dist/client/{propsDecoder-y3LvxaiG.mjs → propsDecoder-Db8wAmgr.mjs} +4 -4
  123. package/dist/client/{registry.server-CIWYKz1V.mjs → registry.server-Bn0gE0uP.mjs} +27 -27
  124. package/dist/client/rendering/client.mjs +23 -23
  125. package/dist/client/rendering/islands.mjs +1 -1
  126. package/dist/client/rendering.mjs +7 -7
  127. package/dist/client/{richText-coerce-DkPBFb_a.mjs → richText-coerce-COnKrLO7.mjs} +1 -1
  128. package/dist/client/{routeIslandApiConfig-BgO0rZce.mjs → routeIslandApiConfig-Bok1Oy50.mjs} +1 -1
  129. package/dist/client/{shop-CFbWlv_W.mjs → shop-D1oTPDxm.mjs} +3 -3
  130. package/dist/client/{shop-commerce-C-I29eaA.mjs → shop-commerce-DyMZLC0a.mjs} +12 -12
  131. package/dist/client/{shop-commerce-store-DGcc7twO.mjs → shop-commerce-store-FODNS63D.mjs} +1 -1
  132. package/dist/client/{shop-discount-apply.state-DOm7vx0X.mjs → shop-discount-apply.state-C4xcmFzZ.mjs} +2 -2
  133. package/dist/client/{shop.client-GHTWUKD6.mjs → shop.client-CRgRulfI.mjs} +12 -12
  134. package/dist/client/{shop.interactive-CxDJ8P2r.mjs → shop.interactive-D7wky1GL.mjs} +6 -33
  135. package/dist/client/{shopShared-Be9QJJpT.mjs → shopShared-Bd_hy9ZO.mjs} +2 -2
  136. package/dist/client/src-DqMbCjI1.mjs +3 -0
  137. package/dist/client/{src-xrjaKaCj.mjs → src-uwCpbHXG.mjs} +2 -1
  138. package/dist/client/{timetableModel--R0zVzZO.mjs → timetableModel-UlWfP1gh.mjs} +9 -9
  139. package/dist/client/{useAvailableSlots-BGu_2F50.mjs → useAvailableSlots-D-qoooLy.mjs} +2 -2
  140. package/dist/client/{useDiscountCodeUi-I_mXI9Yd.mjs → useDiscountCodeUi-B9DODAkj.mjs} +1 -1
  141. package/dist/client/{useEventPagination-DxIJ--JZ.mjs → useEventPagination-CQH2e9sQ.mjs} +7 -7
  142. package/dist/client/{view-BbzH5MQb.mjs → view-DNX59QwM.mjs} +10 -9
  143. package/dist/client/{view-3foOzGWR.mjs → view-bGU1ws-m.mjs} +3 -3
  144. package/dist/preview-next/client/{LocationPickerEnvironment-8iKKoYZr.mjs → LocationPickerEnvironment-BHAT81Wx.mjs} +1 -1
  145. package/dist/preview-next/client/{MapLibreEditMap-AIUPN1Zx.mjs → MapLibreEditMap-B52hkdIZ.mjs} +2 -2
  146. package/dist/preview-next/client/{PageSectionToolbar-0xyUPWUB.mjs → PageSectionToolbar-D-Le7O3o.mjs} +52 -8
  147. package/dist/preview-next/client/{PreviewEditorSidebar-D8vUzXtI.mjs → PreviewEditorSidebar-DNy5j_ce.mjs} +34 -39
  148. package/dist/preview-next/client/{PreviewEditorUI-CRjS4gAu.mjs → PreviewEditorUI-CzJvgbqt.mjs} +10 -10
  149. package/dist/preview-next/client/{PreviewShell-BvdBdeH_.mjs → PreviewShell-xhJ6ca1i.mjs} +9 -8
  150. package/dist/preview-next/client/{SdkPreviewModeRuntime-DWTyKbFj.mjs → SdkPreviewModeRuntime-BmYO1TdT.mjs} +16 -7
  151. package/dist/preview-next/client/{lucide-react-Dfgl3Vtq.mjs → lucide-react-McYZeSMb.mjs} +1 -1
  152. package/dist/preview-next/client/{previewAssistantSlot-BqY2TTcZ.mjs → previewAssistantSlot-BN93X9o1.mjs} +1211 -600
  153. package/dist/preview-next/client/{previewChromeRoot-BuRYe2iL.mjs → previewChromeRoot-C51RQseo.mjs} +1 -1
  154. package/dist/preview-next/client/runtime.mjs +3 -3
  155. package/dist/preview-next/client/{sdk-runtime-BnK5kH9f.mjs → sdk-runtime-oeGquJM-.mjs} +2 -2
  156. package/dist/preview-next/client/{siteStyleAccess-DbKozRSn.mjs → siteStyleAccess-BGTAcPud.mjs} +27 -17
  157. package/dist/preview-next/client/src-EO5QoRlU.mjs +3 -0
  158. package/dist/preview-next/client/{src-DzXUmsyK.mjs → src-lX6heoDA.mjs} +2 -1
  159. package/dist/preview-next/client/{useAutosaveStatus-D9s6dyMW.mjs → useAutosaveStatus-BMGXjGZq.mjs} +3 -30
  160. package/dist/preview-next/client/{useOpenBlockForSetup-Ce4WCxpT.mjs → useOpenBlockForSetup-CTDoR_gQ.mjs} +2 -2
  161. package/dist/preview-next/container-responsive.css +3 -0
  162. package/dist/preview-next/editor-chrome.css +4 -2
  163. package/dist/preview-next/keepAlive.mjs +1 -1
  164. package/dist/preview-next/middleware.mjs +1 -1
  165. package/dist/preview-next/{route-contract-BYezcMx5.mjs → route-contract-BtdzkSUg.mjs} +71 -4
  166. package/dist/server/{Block.shared-Cn7gg13_.mjs → Block.shared-Bp3OlOjj.mjs} +5 -5
  167. package/dist/server/{bindings-VGgS6UvF.mjs → bindings-DrbJuftt.mjs} +3 -3
  168. package/dist/server/{client-Bvag5OtW.mjs → client-Bf06n9oj.mjs} +90 -9
  169. package/dist/server/config-validation.mjs +1 -1
  170. package/dist/server/config.mjs +2 -2
  171. package/dist/server/constants-Cj7hfbrA.mjs +41 -0
  172. package/dist/server/data/resolveBlockData.mjs +1 -1
  173. package/dist/server/index.mjs +2 -2
  174. package/dist/server/{loadContent-CxASA3PE.mjs → loadContent-eaTY7RPg.mjs} +4 -4
  175. package/dist/server/{loadPage-CQgde5DN.mjs → loadPage-5iZefzDd.mjs} +2 -2
  176. package/dist/server/{navigation-iC_hXjJI.mjs → navigation-BcNfYYuu.mjs} +1 -1
  177. package/dist/server/navigation.mjs +1 -1
  178. package/dist/server/next/revalidate.mjs +15 -8
  179. package/dist/server/next.mjs +56 -13
  180. package/dist/server/{overrideResolution-BqVLO4gX.mjs → overrideResolution-CUHtm7tW.mjs} +1 -1
  181. package/dist/server/page-converter.mjs +1 -1
  182. package/dist/server/{pageRenderPlan-CfSnAkCO.mjs → pageRenderPlan-GmPXForc.mjs} +13 -6
  183. package/dist/server/{pageRuntimeSupport-uz4gzBOo.mjs → pageRuntimeSupport-Dd8LFzfa.mjs} +1 -1
  184. package/dist/server/{pageShared-D23o5QgC.mjs → pageShared-tz-GVWft.mjs} +96 -39
  185. package/dist/server/portal-B4JVkdjc.mjs +783 -0
  186. package/dist/server/portal.mjs +3 -3
  187. package/dist/server/{prebuild-BuoXWT9y.mjs → prebuild-JmsuYCIH.mjs} +1 -1
  188. package/dist/server/prebuild.mjs +1 -1
  189. package/dist/server/{prefetchBlockData-CCiYV8_s.mjs → prefetchBlockData-Ce9DDwON.mjs} +2 -2
  190. package/dist/server/{registry-CXRXsFSx.mjs → registry-D12XF_h1.mjs} +466 -311
  191. package/dist/server/rendering/components/pageShared.mjs +1 -1
  192. package/dist/server/rendering/helpers/loadPage.mjs +1 -1
  193. package/dist/server/rendering/helpers/pageRuntimeSupport.mjs +1 -1
  194. package/dist/server/rendering/server.mjs +3 -3
  195. package/dist/server/rendering.mjs +7 -7
  196. package/dist/server/{resolveBlockData-yfe8WLEA.mjs → resolveBlockData-D9yZIN3V.mjs} +1 -1
  197. package/dist/server/server.mjs +3 -3
  198. package/dist/server/{validation-CozQ7wE0.mjs → validation-CLq5cw6M.mjs} +3 -5
  199. package/dist/server/{version-CgCWRFEY.mjs → version-oPbhAx8E.mjs} +1 -1
  200. package/dist/styles/index.css +27 -1
  201. package/package.json +1 -1
  202. package/dist/client/src-BozhJ43Z.mjs +0 -3
  203. package/dist/preview-next/client/src-LUhVXBEQ.mjs +0 -3
  204. package/dist/server/constants-hl17xz6x.mjs +0 -22
  205. package/dist/server/portal-BjVHMAUC.mjs +0 -371
@@ -0,0 +1,783 @@
1
+ import { a as sanitizeSafeAppPath, i as safeAppPathOrFallback, n as assertSafeAppPath, r as buildSafeRedirectUrl } from "./src-DHK4JUlp.mjs";
2
+ import { _ as PORTAL_TOKEN_COOKIE, c as PORTAL_ENTRY_COOKIE, d as PORTAL_ENTRY_PATH, g as PORTAL_TAB_PARAM, l as PORTAL_ENTRY_COOKIE_MAX_AGE, m as PORTAL_LOGIN_SUCCESS_PARAM, o as PORTAL_CALLBACK_PATH, r as DEFAULT_PORTAL_REDIRECT, s as PORTAL_COOKIE_MAX_AGE, t as CUSTOMER_PORTAL_PATH, u as PORTAL_ENTRY_PARAM, v as REDIRECT_TO_PARAM } from "./constants-Cj7hfbrA.mjs";
3
+ //#region src/portal/redirects.ts
4
+ const DEPRECATED_REDIRECT_PATH_WARNING = "[SDK] handlePortalCallback/handlePortalLogout: \"redirectPath\" is deprecated, use \"defaultRedirectPath\"";
5
+ function resolveRedirectPathOption({ options, defaultValue, warn, nodeEnv }) {
6
+ if (options.defaultRedirectPath !== void 0) return options.defaultRedirectPath;
7
+ if (options.redirectPath !== void 0) {
8
+ if (nodeEnv !== "production") warn(DEPRECATED_REDIRECT_PATH_WARNING);
9
+ return options.redirectPath;
10
+ }
11
+ return defaultValue;
12
+ }
13
+ function resolveDefaultRedirect(options, defaultValue, warn = console.warn, nodeEnv = process.env.NODE_ENV) {
14
+ return assertSafeAppPath(resolveRedirectPathOption({
15
+ options,
16
+ defaultValue,
17
+ warn,
18
+ nodeEnv
19
+ }));
20
+ }
21
+ function resolveCallbackRedirect(redirectTo, defaultRedirect) {
22
+ return safeAppPathOrFallback(redirectTo, defaultRedirect);
23
+ }
24
+ function resolveLogoutRedirect({ defaultRedirect, formRedirect, queryRedirect }) {
25
+ if (typeof formRedirect === "string") {
26
+ const sanitized = sanitizeSafeAppPath(formRedirect);
27
+ if (sanitized) return sanitized;
28
+ }
29
+ return sanitizeSafeAppPath(queryRedirect) ?? defaultRedirect;
30
+ }
31
+ //#endregion
32
+ //#region src/portal/entry.ts
33
+ /**
34
+ * Emailed sign-in links on the site: the pure decisions behind the callback and the Continue page,
35
+ * and the server-to-server calls they make. Envelope typings stay local, as in callback.ts, to avoid
36
+ * pulling server-focused contract code into site bundles.
37
+ */
38
+ const TOKEN_SHAPE = /^[a-f0-9]{64}$/;
39
+ function isPortalEntryToken(value) {
40
+ return typeof value === "string" && TOKEN_SHAPE.test(value);
41
+ }
42
+ function encodePortalEntryCookie(entry) {
43
+ return JSON.stringify({
44
+ t: entry.token,
45
+ d: entry.destination
46
+ });
47
+ }
48
+ /** A cookie that doesn't parse reads as absent, and its destination is validated again on the way in. */
49
+ function parsePortalEntryCookie(value, defaultRedirect) {
50
+ if (!value) return null;
51
+ try {
52
+ const parsed = JSON.parse(value);
53
+ const token = typeof parsed?.t === "string" ? parsed.t : null;
54
+ return isPortalEntryToken(token) ? {
55
+ token,
56
+ destination: safeAppPathOrFallback(parsed?.d, defaultRedirect)
57
+ } : null;
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+ /** For the page, which reads through Next's cookie store. */
63
+ function decodePortalEntryCookieValue(value) {
64
+ return parsePortalEntryCookie(value, assertSafeAppPath(CUSTOMER_PORTAL_PATH));
65
+ }
66
+ /**
67
+ * A non-secret fingerprint of the pending link, carried by the form. A Continue on Alice's page after
68
+ * Bob's link opened in another tab is refused rather than signing in as Bob. The destination counts
69
+ * too, because every link in one email shares a token: Continue on its ticket link, after its account
70
+ * link opened in another tab, is refused rather than landing on the account page.
71
+ */
72
+ async function portalEntryFingerprint(entry) {
73
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${entry.token}\n${entry.destination}`));
74
+ return Array.from(new Uint8Array(digest).slice(0, 8), (byte) => byte.toString(16).padStart(2, "0")).join("");
75
+ }
76
+ function firstValue(value) {
77
+ return value?.split(",")[0]?.trim() || null;
78
+ }
79
+ const LOOPBACK_HOST = /^(localhost|127\.|0\.0\.0\.0|\[::1\])/i;
80
+ /**
81
+ * The host the visitor sees: the first X-Forwarded-Host, then Host. Only a loopback forwarded host,
82
+ * which local dev servers add for themselves, gives way to a Host header that names the real site.
83
+ */
84
+ function resolveExternalHost(headers) {
85
+ const forwarded = firstValue(headers.get("x-forwarded-host"));
86
+ const host = firstValue(headers.get("host"));
87
+ if (!forwarded) return host;
88
+ return host && LOOPBACK_HOST.test(forwarded) && !LOOPBACK_HOST.test(host) ? host : forwarded;
89
+ }
90
+ /** The site's external origin: the one reading used by POST validation, redemption and redirects. */
91
+ function resolveExternalOrigin(headers, requestUrl) {
92
+ const host = resolveExternalHost(headers) ?? requestUrl.host;
93
+ const isLocalHost = host.includes("localhost") || host.includes(".local");
94
+ return `${firstValue(headers.get("x-forwarded-proto")) ?? (isLocalHost ? "http" : requestUrl.protocol.replace(":", ""))}://${host}`;
95
+ }
96
+ /**
97
+ * Sec-Fetch-Site is set by the browser and no proxy alters it. Only where it's absent do we compare
98
+ * the Origin's host with the site's external host.
99
+ */
100
+ function isSameOriginPost(headers) {
101
+ const fetchSite = headers.get("sec-fetch-site");
102
+ if (fetchSite) return fetchSite === "same-origin";
103
+ const origin = headers.get("origin");
104
+ if (!origin || !URL.canParse(origin)) return false;
105
+ return new URL(origin).host.toLowerCase() === resolveExternalHost(headers)?.toLowerCase();
106
+ }
107
+ /** Picks the first page's heading and button. It reads the destination and nothing else. */
108
+ function portalEntryPurpose(redirectPath) {
109
+ const url = new URL(redirectPath, "https://site.invalid");
110
+ if (url.searchParams.has("waitlist_claim")) return "waitlist_claim";
111
+ const tab = url.searchParams.get(PORTAL_TAB_PARAM);
112
+ if (tab === "passes-memberships") return "membership";
113
+ if (url.pathname.startsWith("/portal/tickets/") || tab === "events" || tab === "appointments" || url.searchParams.has("portal_task")) return "booking";
114
+ return "general";
115
+ }
116
+ const ARRIVAL_QUERIES = {
117
+ none: "",
118
+ opened: "?entry=1",
119
+ stale: "?entry=1&stale=1",
120
+ link_sent: "?link=sent",
121
+ link_limited: "?link=limited",
122
+ demo_refused: "?link=demo"
123
+ };
124
+ function portalEntryHref(arrival) {
125
+ return `${PORTAL_ENTRY_PATH}${ARRIVAL_QUERIES[arrival]}`;
126
+ }
127
+ function parsePortalEntryArrival(params) {
128
+ if (params.link === "sent") return "link_sent";
129
+ if (params.link === "limited") return "link_limited";
130
+ if (params.link === "demo") return "demo_refused";
131
+ if (params.entry !== "1") return "none";
132
+ return params.stale === "1" ? "stale" : "opened";
133
+ }
134
+ /** Every state of the Continue page, decided in one place. */
135
+ function planPortalEntryPage(input) {
136
+ const { arrival, pending } = input;
137
+ if (!pending) return planWithoutLink(arrival);
138
+ const { entry, preview, fingerprint } = pending;
139
+ if (preview === "unavailable") return asView({
140
+ kind: "failed",
141
+ retryHref: portalEntryHref("opened"),
142
+ destination: entry.destination,
143
+ fingerprint
144
+ });
145
+ if (preview.state === "unknown") return sendAnswer(arrival, null) ?? asView({ kind: "unknown" });
146
+ if (preview.sameCustomer) return {
147
+ kind: "redirect",
148
+ destination: entry.destination
149
+ };
150
+ return sendAnswer(arrival, {
151
+ maskedEmail: preview.maskedEmail,
152
+ fingerprint
153
+ }) ?? planKnownLink(arrival, pending, preview);
154
+ }
155
+ function planKnownLink(arrival, pending, preview) {
156
+ if (arrival === "stale") return asView({
157
+ kind: "stale",
158
+ carryOnHref: portalEntryHref("opened")
159
+ });
160
+ if (preview.state !== "ready") return asView({
161
+ kind: preview.state,
162
+ resend: {
163
+ maskedEmail: preview.maskedEmail,
164
+ fingerprint: pending.fingerprint
165
+ }
166
+ });
167
+ return asView({
168
+ kind: "continue",
169
+ purpose: portalEntryPurpose(pending.entry.destination),
170
+ maskedEmail: preview.maskedEmail,
171
+ fingerprint: pending.fingerprint
172
+ });
173
+ }
174
+ function asView(view) {
175
+ return {
176
+ kind: "view",
177
+ view
178
+ };
179
+ }
180
+ /** What the callback came back to say about a request for a new link, if that's why they're here. */
181
+ function sendAnswer(arrival, resend) {
182
+ switch (arrival) {
183
+ case "link_sent": return asView({
184
+ kind: "link_sent",
185
+ resend
186
+ });
187
+ case "link_limited": return asView({
188
+ kind: "link_limited",
189
+ resend
190
+ });
191
+ case "demo_refused": return asView({ kind: "demo_refused" });
192
+ case "none":
193
+ case "opened":
194
+ case "stale": return null;
195
+ }
196
+ }
197
+ function planWithoutLink(arrival) {
198
+ return sendAnswer(arrival, null) ?? asView({ kind: arrival === "none" ? "unknown" : "cookies_blocked" });
199
+ }
200
+ async function postDashboard(url, body, timeoutMs) {
201
+ const controller = new AbortController();
202
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
203
+ try {
204
+ const response = await fetch(url, {
205
+ method: "POST",
206
+ headers: { "Content-Type": "application/json" },
207
+ cache: "no-store",
208
+ body: JSON.stringify(body),
209
+ signal: controller.signal
210
+ });
211
+ const json = await response.json().catch(() => null);
212
+ if (!response.ok) return {
213
+ ok: false,
214
+ status: response.status
215
+ };
216
+ const envelope = json;
217
+ return envelope?.success === true ? {
218
+ ok: true,
219
+ data: envelope.data
220
+ } : {
221
+ ok: false,
222
+ status: null
223
+ };
224
+ } catch {
225
+ return {
226
+ ok: false,
227
+ status: null
228
+ };
229
+ } finally {
230
+ clearTimeout(timeout);
231
+ }
232
+ }
233
+ /** Read-only. `apiBaseUrl` includes the /api prefix, as the page's client base URL does. */
234
+ async function previewPortalEntryToken(input) {
235
+ const result = await postDashboard(`${input.apiBaseUrl.replace(/\/$/, "")}/portal/auth/entry/preview`, {
236
+ siteId: input.siteId,
237
+ token: input.token,
238
+ ...input.sessionToken ? { sessionToken: input.sessionToken } : {}
239
+ }, input.timeoutMs ?? 1e4);
240
+ return result.ok ? readPreviewAnswer(result.data) : "unavailable";
241
+ }
242
+ /** The site and the dashboard can run different versions, so anything unexpected reads as unavailable. */
243
+ function readPreviewAnswer(data) {
244
+ const answer = data;
245
+ if (answer?.state === "unknown") return { state: "unknown" };
246
+ return (answer?.state === "ready" || answer?.state === "used" || answer?.state === "expired") && typeof answer.maskedEmail === "string" ? {
247
+ state: answer.state,
248
+ maskedEmail: answer.maskedEmail,
249
+ sameCustomer: answer.sameCustomer === true
250
+ } : "unavailable";
251
+ }
252
+ async function redeemPortalEntryToken(input) {
253
+ const result = await postDashboard(`${input.dashboardUrl}/api/portal/auth/entry/redeem`, {
254
+ token: input.token,
255
+ callbackOrigin: input.callbackOrigin
256
+ }, input.timeoutMs);
257
+ return result.ok ? readRedeemAnswer(result.data) : { kind: "unavailable" };
258
+ }
259
+ /** Anything the dashboard didn't plainly say reads as unavailable, never as a spent link. */
260
+ function readRedeemAnswer(data) {
261
+ if (data?.outcome === "signed_in" && data.sessionToken) return {
262
+ kind: "signed_in",
263
+ sessionToken: data.sessionToken
264
+ };
265
+ return [
266
+ "used",
267
+ "expired",
268
+ "unknown"
269
+ ].includes(data?.outcome ?? "") ? { kind: "not_redeemed" } : { kind: "unavailable" };
270
+ }
271
+ async function resendPortalEntryToken(input) {
272
+ const result = await postDashboard(`${input.dashboardUrl}/api/portal/auth/entry/resend`, {
273
+ token: input.token,
274
+ redirectPath: input.redirectPath,
275
+ callbackOrigin: input.callbackOrigin
276
+ }, input.timeoutMs);
277
+ if (!result.ok) return "unavailable";
278
+ const outcome = result.data?.outcome;
279
+ return outcome === "sent" || outcome === "rate_limited" || outcome === "demo_refused" || outcome === "unknown" ? outcome : "unavailable";
280
+ }
281
+ /**
282
+ * The dashboard answers success whether or not the address has an account, so this can't reveal who
283
+ * does. Limits are counted before any account lookup, and a demo site refuses every address. This
284
+ * route's IP limit is shared by everyone on an SDK site's server, which we accept because few people
285
+ * ever reach the address box.
286
+ */
287
+ async function requestPortalLinkForAddress(input) {
288
+ const redirectUrl = new URL(PORTAL_CALLBACK_PATH, input.callbackOrigin);
289
+ redirectUrl.searchParams.set(REDIRECT_TO_PARAM, input.destination);
290
+ const result = await postDashboard(`${input.dashboardUrl}/api/portal/auth/send-magic-link`, {
291
+ email: input.email,
292
+ siteId: input.siteId,
293
+ redirectUrl: redirectUrl.toString()
294
+ }, input.timeoutMs);
295
+ if (result.ok) return "answered";
296
+ if (result.status === 429) return "rate_limited";
297
+ return result.status === 403 ? "demo_refused" : "unavailable";
298
+ }
299
+ //#endregion
300
+ //#region src/portal/entryFailure.ts
301
+ function escapeHtml(value) {
302
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&#39;");
303
+ }
304
+ const STYLES = `
305
+ body{margin:0;font:17px/1.5 -apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;color:#23302e;background:#fff}
306
+ main{max-width:30rem;margin:0 auto;padding:2rem 1.25rem}
307
+ .site{font-weight:600;margin:0 0 2rem}
308
+ h1{font-size:1.625rem;line-height:1.2;font-weight:600;margin:0 0 .875rem}
309
+ p{margin:0 0 .875rem}
310
+ form{margin:0 0 .625rem}
311
+ button{display:block;width:100%;min-height:3.125rem;padding:.875rem 1rem;font:inherit;font-weight:600;border-radius:.5rem;border:1px solid #23302e;background:#23302e;color:#fff;cursor:pointer}
312
+ button.alt{background:transparent;color:#23302e}
313
+ .on{display:inline-block;margin:.5rem 0 1.5rem}
314
+ .help{border-top:1px solid #d8d3c7;padding-top:.875rem;color:#566461}
315
+ `;
316
+ function hiddenField(name, value) {
317
+ return value ? `<input type="hidden" name="${name}" value="${escapeHtml(value)}">` : "";
318
+ }
319
+ function renderPortalEntryFailureHtml(input) {
320
+ const carried = `${hiddenField("site_title", input.siteTitle)}${hiddenField("contact_email", input.contactEmail)}`;
321
+ const action = escapeHtml(PORTAL_CALLBACK_PATH);
322
+ const tryAgain = input.retry ? `<form method="post" action="${action}"><input type="hidden" name="intent" value="${input.retry.intent}">${hiddenField("fingerprint", input.retry.fingerprint)}${carried}<button type="submit">Try again</button></form>` : "";
323
+ const newLink = input.retry ? `<form method="post" action="${action}"><input type="hidden" name="intent" value="new_link">${hiddenField("fingerprint", input.retry.fingerprint)}${carried}<button type="submit" class="alt">Email me a new link</button></form>` : "";
324
+ const wayOn = `<a class="on" rel="noreferrer" referrerpolicy="no-referrer" href="${escapeHtml(input.retry?.destination ?? "/portal")}">Go to the page</a>`;
325
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex"><title>Sorry, that didn't work</title><style>${STYLES}</style></head><body><main>${input.siteTitle ? `<p class="site">${escapeHtml(input.siteTitle)}</p>` : ""}<h1>Sorry, that didn't work</h1><p>Something went wrong on our side, and it's nothing you did. Please try again in a minute.</p>${tryAgain}${newLink}${wayOn}${input.contactEmail ? `<p class="help">Need a hand? <a href="mailto:${escapeHtml(input.contactEmail)}">Email ${escapeHtml(input.siteTitle ?? "us")}</a></p>` : ""}</main></body></html>`;
326
+ }
327
+ //#endregion
328
+ //#region src/portal/callback.ts
329
+ /**
330
+ * Check if running in production environment.
331
+ */
332
+ function isProduction() {
333
+ return process.env.NODE_ENV === "production";
334
+ }
335
+ function serializeCookie(name, value, options) {
336
+ const parts = [`${name}=${encodeURIComponent(value)}`];
337
+ parts.push(`Path=${options.path ?? "/"}`);
338
+ if (options.httpOnly) parts.push("HttpOnly");
339
+ if (options.secure) parts.push("Secure");
340
+ if (options.sameSite) {
341
+ const sameSiteValue = options.sameSite === "lax" ? "Lax" : options.sameSite === "strict" ? "Strict" : "None";
342
+ parts.push(`SameSite=${sameSiteValue}`);
343
+ }
344
+ if (typeof options.maxAge === "number") parts.push(`Max-Age=${options.maxAge}`);
345
+ return parts.join("; ");
346
+ }
347
+ function createPortalRouteResponse(init) {
348
+ const headers = new Headers(init.headers);
349
+ const cookies = /* @__PURE__ */ new Map();
350
+ for (const cookie of init.cookies ?? []) {
351
+ cookies.set(cookie.name, cookie);
352
+ headers.append("Set-Cookie", serializeCookie(cookie.name, cookie.value, {
353
+ httpOnly: cookie.httpOnly,
354
+ secure: cookie.secure,
355
+ sameSite: cookie.sameSite,
356
+ path: cookie.path,
357
+ maxAge: cookie.maxAge
358
+ }));
359
+ }
360
+ const response = new Response(init.body ?? null, {
361
+ status: init.status,
362
+ headers
363
+ });
364
+ return Object.assign(response, { cookies: { get(name) {
365
+ return cookies.get(name);
366
+ } } });
367
+ }
368
+ function createJsonResponse(body, status) {
369
+ return createPortalRouteResponse({
370
+ body: JSON.stringify(body),
371
+ status,
372
+ headers: {
373
+ "Content-Type": "application/json",
374
+ "Cache-Control": "no-store",
375
+ "Referrer-Policy": "no-referrer"
376
+ }
377
+ });
378
+ }
379
+ /**
380
+ * Resolve the external origin for redirects.
381
+ *
382
+ * In dev, NextRequest.nextUrl.host can be 'localhost' even when the request was
383
+ * made to a subdomain like `foo.localhost`. Use forwarded/host headers to preserve
384
+ * the real host so we don't accidentally redirect to localhost (which can then
385
+ * trigger frontend middleware redirects to the dashboard).
386
+ */
387
+ function getRequestOrigin(request) {
388
+ return resolveExternalOrigin(request.headers, request.nextUrl);
389
+ }
390
+ /**
391
+ * Get dashboard URL from environment without requiring API keys.
392
+ * Returns null if not configured.
393
+ *
394
+ * This is a simpler alternative to getRiverbankEnv() that doesn't
395
+ * require SITE_ID or API_KEY to be set.
396
+ */
397
+ function getDashboardUrl() {
398
+ const target = process.env.RIVERBANK_ENV?.toLowerCase();
399
+ const prefix = target === "remote" || target === "production" || target === "prod" ? "RIVERBANK_REMOTE" : "RIVERBANK_LOCAL";
400
+ const url = process.env[`${prefix}_DASHBOARD_URL`];
401
+ if (!url) return null;
402
+ return url.replace(/\/api$/, "").replace(/\/$/, "");
403
+ }
404
+ /**
405
+ * Resolve dashboard URL from various sources.
406
+ */
407
+ function resolveDashboardUrl(option) {
408
+ if (typeof option === "string") return option;
409
+ if (typeof option === "function") return option();
410
+ return getDashboardUrl();
411
+ }
412
+ /** Keeps the dashboard's refusal status, so a bad code isn't mistaken for an outage. */
413
+ async function exchangePortalCode(params) {
414
+ const result = await postDashboard(`${params.dashboardUrl}/api/portal/auth/exchange`, {
415
+ portalCode: params.portalCode,
416
+ callbackOrigin: params.callbackOrigin
417
+ }, params.timeoutMs);
418
+ if (!result.ok) return {
419
+ kind: "refused",
420
+ status: result.status !== null && result.status < 500 ? result.status : 502
421
+ };
422
+ const sessionToken = result.data?.sessionToken;
423
+ return typeof sessionToken === "string" ? {
424
+ kind: "signed_in",
425
+ sessionToken
426
+ } : {
427
+ kind: "refused",
428
+ status: 502
429
+ };
430
+ }
431
+ function portalSessionCookie(token, secure) {
432
+ return {
433
+ name: PORTAL_TOKEN_COOKIE,
434
+ value: token,
435
+ httpOnly: true,
436
+ secure,
437
+ sameSite: "lax",
438
+ path: "/",
439
+ maxAge: PORTAL_COOKIE_MAX_AGE
440
+ };
441
+ }
442
+ async function readCallbackPostCode(request) {
443
+ const body = await request.json().catch(() => null);
444
+ return body && typeof body === "object" && "portalCode" in body && typeof body.portalCode === "string" && body.portalCode.trim() ? body.portalCode : null;
445
+ }
446
+ function isJsonRequest(request) {
447
+ return request.headers.get("content-type")?.split(";")[0]?.trim() === "application/json";
448
+ }
449
+ /** Gift claim: a JSON POST that keeps its JSON answer and its exchange code. */
450
+ async function completeGiftClaimPost(request, options, secure, exchangeTimeoutMs) {
451
+ const origin = getRequestOrigin(request);
452
+ const code = await readCallbackPostCode(request);
453
+ if (!code) return createJsonResponse({ success: false }, 400);
454
+ const dashboardUrl = resolveDashboardUrl(options.dashboardUrl);
455
+ if (!dashboardUrl) return createJsonResponse({ success: false }, 500);
456
+ const result = await exchangePortalCode({
457
+ dashboardUrl,
458
+ portalCode: code,
459
+ callbackOrigin: origin,
460
+ timeoutMs: exchangeTimeoutMs
461
+ });
462
+ if (result.kind === "refused") return createJsonResponse({ success: false }, result.status);
463
+ return createPortalRouteResponse({
464
+ status: 200,
465
+ body: JSON.stringify({ success: true }),
466
+ headers: {
467
+ "Content-Type": "application/json",
468
+ "Cache-Control": "no-store",
469
+ "Referrer-Policy": "no-referrer"
470
+ },
471
+ cookies: [portalSessionCookie(result.sessionToken, secure)]
472
+ });
473
+ }
474
+ function logRefusedPost(request) {
475
+ console.warn("[portal] refused a cross-origin callback POST", {
476
+ secFetchSite: request.headers.get("sec-fetch-site"),
477
+ origin: request.headers.get("origin"),
478
+ host: request.headers.get("host"),
479
+ forwardedHost: request.headers.get("x-forwarded-host")
480
+ });
481
+ }
482
+ function redirectResponse(location, cookies = []) {
483
+ return createPortalRouteResponse({
484
+ status: 303,
485
+ headers: {
486
+ Location: location.toString(),
487
+ "Referrer-Policy": "no-referrer",
488
+ "Cache-Control": "no-store"
489
+ },
490
+ cookies
491
+ });
492
+ }
493
+ function toEntryPage(origin, arrival, cookies = []) {
494
+ return redirectResponse(new URL(portalEntryHref(arrival), origin), cookies);
495
+ }
496
+ function entryCookie(value, maxAge, secure) {
497
+ return {
498
+ name: PORTAL_ENTRY_COOKIE,
499
+ value,
500
+ httpOnly: true,
501
+ secure,
502
+ sameSite: "lax",
503
+ path: "/",
504
+ maxAge
505
+ };
506
+ }
507
+ /**
508
+ * Opening a link: stores the token, consumes nothing, and moves on to a clean address. A link we
509
+ * can't read clears any pending one, so the page can't offer Continue for somebody else's.
510
+ */
511
+ function openEmailedLink(request, defaultRedirect, secure) {
512
+ const origin = getRequestOrigin(request);
513
+ const token = request.nextUrl.searchParams.get(PORTAL_ENTRY_PARAM);
514
+ if (!isPortalEntryToken(token)) return toEntryPage(origin, "none", [entryCookie("", 0, secure)]);
515
+ return toEntryPage(origin, "opened", [entryCookie(encodePortalEntryCookie({
516
+ token,
517
+ destination: resolveCallbackRedirect(request.nextUrl.searchParams.get(REDIRECT_TO_PARAM), defaultRedirect)
518
+ }), PORTAL_ENTRY_COOKIE_MAX_AGE, secure)]);
519
+ }
520
+ function formText(form, name) {
521
+ const value = form.get(name);
522
+ return typeof value === "string" ? value : "";
523
+ }
524
+ function readEntryFormRequest(form) {
525
+ const intent = formText(form, "intent");
526
+ if (intent === "continue") return {
527
+ intent,
528
+ fingerprint: formText(form, "fingerprint")
529
+ };
530
+ if (intent === "new_link") return {
531
+ intent,
532
+ fingerprint: formText(form, "fingerprint")
533
+ };
534
+ if (intent === "address") return {
535
+ intent,
536
+ email: formText(form, "email").trim().toLowerCase(),
537
+ siteId: formText(form, "site_id")
538
+ };
539
+ return { intent: null };
540
+ }
541
+ function failurePage(chrome, retry) {
542
+ return createPortalRouteResponse({
543
+ status: 503,
544
+ body: renderPortalEntryFailureHtml({
545
+ ...chrome,
546
+ retry
547
+ }),
548
+ headers: {
549
+ "Content-Type": "text/html; charset=utf-8",
550
+ "Cache-Control": "no-store",
551
+ "Referrer-Policy": "strict-origin"
552
+ }
553
+ });
554
+ }
555
+ async function completeContinue(input, fingerprint) {
556
+ const { chrome, entry, origin, secure, timeoutMs, dashboardUrl } = input;
557
+ if (!entry) return toEntryPage(origin, "opened");
558
+ if (fingerprint !== await portalEntryFingerprint(entry)) return toEntryPage(origin, "stale");
559
+ const retry = {
560
+ intent: "continue",
561
+ fingerprint,
562
+ destination: entry.destination
563
+ };
564
+ if (!dashboardUrl) return failurePage(chrome, retry);
565
+ const result = await redeemPortalEntryToken({
566
+ dashboardUrl,
567
+ token: entry.token,
568
+ callbackOrigin: origin,
569
+ timeoutMs
570
+ });
571
+ switch (result.kind) {
572
+ case "signed_in": {
573
+ const destination = buildSafeRedirectUrl(entry.destination, origin);
574
+ destination.searchParams.set(PORTAL_LOGIN_SUCCESS_PARAM, "success");
575
+ return redirectResponse(destination, [portalSessionCookie(result.sessionToken, secure), entryCookie("", 0, secure)]);
576
+ }
577
+ case "not_redeemed": return toEntryPage(origin, "opened");
578
+ case "unavailable": return failurePage(chrome, retry);
579
+ }
580
+ }
581
+ async function completeNewLink(input, fingerprint) {
582
+ const { chrome, entry, origin, timeoutMs, dashboardUrl } = input;
583
+ if (!entry) return toEntryPage(origin, "opened");
584
+ if (fingerprint !== await portalEntryFingerprint(entry)) return toEntryPage(origin, "stale");
585
+ const retry = {
586
+ intent: "new_link",
587
+ fingerprint,
588
+ destination: entry.destination
589
+ };
590
+ if (!dashboardUrl) return failurePage(chrome, retry);
591
+ switch (await resendPortalEntryToken({
592
+ dashboardUrl,
593
+ token: entry.token,
594
+ redirectPath: entry.destination,
595
+ callbackOrigin: origin,
596
+ timeoutMs
597
+ })) {
598
+ case "sent": return toEntryPage(origin, "link_sent");
599
+ case "rate_limited": return toEntryPage(origin, "link_limited");
600
+ case "demo_refused": return toEntryPage(origin, "demo_refused");
601
+ case "unknown": return toEntryPage(origin, "opened");
602
+ case "unavailable": return failurePage(chrome, retry);
603
+ }
604
+ }
605
+ /** The address box answers the same way for every address, so it can't reveal who has an account. */
606
+ async function completeAddressRequest(input, request) {
607
+ const { chrome, origin, timeoutMs, dashboardUrl, defaultRedirect, entry } = input;
608
+ if (!dashboardUrl) return failurePage(chrome, null);
609
+ switch (await requestPortalLinkForAddress({
610
+ dashboardUrl,
611
+ email: request.email,
612
+ siteId: request.siteId,
613
+ callbackOrigin: origin,
614
+ destination: entry?.destination ?? defaultRedirect,
615
+ timeoutMs
616
+ })) {
617
+ case "answered": return toEntryPage(origin, "link_sent");
618
+ case "rate_limited": return toEntryPage(origin, "link_limited");
619
+ case "demo_refused": return toEntryPage(origin, "demo_refused");
620
+ case "unavailable": return failurePage(chrome, null);
621
+ }
622
+ }
623
+ async function completeFormPost(request, options, secure, timeoutMs, defaultRedirect) {
624
+ const form = await request.formData().catch(() => new FormData());
625
+ const context = {
626
+ secure,
627
+ timeoutMs,
628
+ defaultRedirect,
629
+ chrome: {
630
+ siteTitle: formText(form, "site_title") || null,
631
+ contactEmail: formText(form, "contact_email") || null
632
+ },
633
+ origin: getRequestOrigin(request),
634
+ entry: parsePortalEntryCookie(request.cookies.get(PORTAL_ENTRY_COOKIE)?.value, defaultRedirect),
635
+ dashboardUrl: resolveDashboardUrl(options.dashboardUrl)
636
+ };
637
+ const formRequest = readEntryFormRequest(form);
638
+ switch (formRequest.intent) {
639
+ case "continue": return completeContinue(context, formRequest.fingerprint);
640
+ case "new_link": return completeNewLink(context, formRequest.fingerprint);
641
+ case "address": return completeAddressRequest(context, formRequest);
642
+ case null: return toEntryPage(context.origin, "opened");
643
+ }
644
+ }
645
+ function refusedPost(request) {
646
+ logRefusedPost(request);
647
+ return isJsonRequest(request) ? createJsonResponse({ success: false }, 403) : createPortalRouteResponse({
648
+ status: 403,
649
+ body: renderPortalEntryFailureHtml({
650
+ retry: null,
651
+ siteTitle: null,
652
+ contactEmail: null
653
+ }),
654
+ headers: {
655
+ "Content-Type": "text/html; charset=utf-8",
656
+ "Cache-Control": "no-store",
657
+ "Referrer-Policy": "no-referrer"
658
+ }
659
+ });
660
+ }
661
+ /**
662
+ * Create the GET and POST route handler for the portal callback.
663
+ *
664
+ * GET and HEAD open an emailed link and never sign anyone in. POST, from the site's own pages only:
665
+ * - a form with intent=continue spends the token and sets the portal cookie
666
+ * - a form with intent=new_link or intent=address emails a new link
667
+ * - JSON carries the gift claim's exchange code
668
+ *
669
+ * @param options - Configuration options
670
+ * @returns route handler function
671
+ */
672
+ function handlePortalCallback(options = {}) {
673
+ const defaultRedirect = resolveDefaultRedirect(options, DEFAULT_PORTAL_REDIRECT);
674
+ const secure = options.secure ?? isProduction();
675
+ const exchangeTimeoutMs = options.exchangeTimeoutMs ?? 1e4;
676
+ return async function callback(request) {
677
+ if (request.method !== "POST") return openEmailedLink(request, defaultRedirect, secure);
678
+ if (!isSameOriginPost(request.headers)) return refusedPost(request);
679
+ return isJsonRequest(request) ? completeGiftClaimPost(request, options, secure, exchangeTimeoutMs) : completeFormPost(request, options, secure, exchangeTimeoutMs, defaultRedirect);
680
+ };
681
+ }
682
+ /**
683
+ * Create a POST route handler for portal logout.
684
+ *
685
+ * This handler:
686
+ * 1. Gets the redirect path from form data or query params
687
+ * 2. Calls the dashboard logout API to invalidate the session
688
+ * 3. Clears the portal token cookie
689
+ * 4. Redirects to the validated path
690
+ *
691
+ * @param options - Configuration options
692
+ * @returns POST route handler function
693
+ */
694
+ function handlePortalLogout(options = {}) {
695
+ const defaultRedirect = resolveDefaultRedirect(options, "/");
696
+ const secure = options.secure ?? isProduction();
697
+ const { dashboardUrl } = options;
698
+ return async function POST(request) {
699
+ const portalToken = request.cookies.get(PORTAL_TOKEN_COOKIE)?.value;
700
+ let formRedirect = null;
701
+ try {
702
+ formRedirect = (await request.formData()).get(REDIRECT_TO_PARAM);
703
+ } catch {}
704
+ const redirectTo = resolveLogoutRedirect({
705
+ defaultRedirect,
706
+ formRedirect,
707
+ queryRedirect: request.nextUrl.searchParams.get(REDIRECT_TO_PARAM)
708
+ });
709
+ if (portalToken) {
710
+ const url = resolveDashboardUrl(dashboardUrl);
711
+ if (url) try {
712
+ await fetch(`${url}/api/portal/auth/logout`, {
713
+ method: "POST",
714
+ headers: { Authorization: `Bearer ${portalToken}` }
715
+ });
716
+ } catch {}
717
+ }
718
+ return createPortalRouteResponse({
719
+ status: 303,
720
+ headers: { Location: buildSafeRedirectUrl(redirectTo, getRequestOrigin(request)).toString() },
721
+ cookies: [{
722
+ name: PORTAL_TOKEN_COOKIE,
723
+ value: "",
724
+ httpOnly: true,
725
+ secure,
726
+ sameSite: "lax",
727
+ path: "/",
728
+ maxAge: 0
729
+ }, entryCookie("", 0, secure)]
730
+ });
731
+ };
732
+ }
733
+ //#endregion
734
+ //#region src/portal/validation.ts
735
+ /**
736
+ * Portal Validation Utilities
737
+ */
738
+ /**
739
+ * Validate that a redirect path is safe (prevents open redirects).
740
+ *
741
+ * Valid paths must:
742
+ * - Resolve to the same origin when parsed against a fixed base
743
+ * - Not contain backslashes or control characters
744
+ * - Not include encoded path separator/control-character payloads in the pathname
745
+ *
746
+ * @param path - The path to validate
747
+ * @returns True if the path is safe to redirect to
748
+ */
749
+ function isValidRedirectPath(path) {
750
+ return sanitizeSafeAppPath(path) !== null;
751
+ }
752
+ //#endregion
753
+ //#region src/portal/token.ts
754
+ /**
755
+ * Portal server helpers: callback, logout and cookie/token access.
756
+ *
757
+ * For a themed reserved route, use createPortalPage from @riverbankcms/sdk/next.
758
+ * For a custom host, import CustomerPortal from @riverbankcms/sdk/portal/client
759
+ * and pass siteId, apiBaseUrl and the nullable portalToken inside the site ThemeScope.
760
+ */
761
+ /**
762
+ * Get the portal token from the cookie store.
763
+ *
764
+ * @param cookieStore - The cookie store from `await cookies()`
765
+ * @returns The portal token, or null if not present
766
+ */
767
+ function getPortalToken(cookieStore) {
768
+ return cookieStore.get("portal_token")?.value ?? null;
769
+ }
770
+ /**
771
+ * Check if the user has a portal session.
772
+ *
773
+ * Note: This only checks if the cookie exists, not if it's valid.
774
+ * The actual validation happens when making API calls.
775
+ *
776
+ * @param cookieStore - The cookie store from `await cookies()`
777
+ * @returns True if a portal token cookie exists
778
+ */
779
+ function hasPortalSession(cookieStore) {
780
+ return getPortalToken(cookieStore) !== null;
781
+ }
782
+ //#endregion
783
+ export { handlePortalCallback as a, parsePortalEntryArrival as c, portalEntryHref as d, previewPortalEntryToken as f, getDashboardUrl as i, planPortalEntryPage as l, hasPortalSession as n, handlePortalLogout as o, isValidRedirectPath as r, decodePortalEntryCookieValue as s, getPortalToken as t, portalEntryFingerprint as u };