@riverbankcms/sdk 0.89.1 → 0.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -4
- package/dist/{PreviewEditorSidebar-JDR64FEC.mjs → PreviewEditorSidebar-FNFRVSIM.mjs} +3 -3
- package/dist/{PreviewEditorUI-67TMJMAF.mjs → PreviewEditorUI-3WXJFQXG.mjs} +3 -3
- package/dist/SdkPreviewModeRuntime-2UCIMKUB.mjs +8 -0
- package/dist/_dts/ai/src/contracts/proposals.d.ts +216 -0
- package/dist/_dts/altcha/src/AltchaWidget.d.ts +1 -1
- package/dist/_dts/api/src/bookingConfig.d.ts +3 -0
- package/dist/_dts/api/src/bookingOperations.d.ts +2 -0
- package/dist/_dts/api/src/bookingRecords.d.ts +4 -2
- package/dist/_dts/api/src/bookings.d.ts +3 -1
- package/dist/_dts/api/src/event-listing-destination.d.ts +59 -0
- package/dist/_dts/api/src/index.d.ts +10 -5
- package/dist/_dts/api/src/navigation/dashboardSettingsNav.d.ts +0 -1
- package/dist/_dts/api/src/navigation.d.ts +2 -0
- package/dist/_dts/api/src/publicExperienceEndpoints.d.ts +18 -6
- package/dist/_dts/api/src/request.d.ts +21 -0
- package/dist/_dts/api/src/sdk-event-upsert.d.ts +3 -1
- package/dist/_dts/api/src/sdkContracts.d.ts +2 -0
- package/dist/_dts/api/src/settings/permissions.d.ts +273 -0
- package/dist/_dts/api/src/types.d.ts +4 -1
- package/dist/_dts/api/src/url.d.ts +6 -3
- package/dist/_dts/block-form/src/utils/visibleWhen.d.ts +1 -0
- package/dist/_dts/block-form/src/widgets/RepeaterField/components/RepeaterThumbnailCard.d.ts +5 -1
- package/dist/_dts/block-form/src/widgets/RepeaterField/components/RepeaterThumbnailGrid.d.ts +9 -1
- package/dist/_dts/block-form/src/widgets/RepeaterField/components/index.d.ts +1 -0
- package/dist/_dts/blocks/src/contracts/non-block-islands.d.ts +7 -11
- package/dist/_dts/blocks/src/contracts/proof-block-islands.d.ts +6 -0
- package/dist/_dts/blocks/src/index.d.ts +2 -1
- package/dist/_dts/blocks/src/system/blocks/events/event-calendar.d.ts +14 -6
- package/dist/_dts/blocks/src/system/blocks/events/shared/schemas.d.ts +60 -2
- package/dist/_dts/blocks/src/system/blocks/events/shared/types.d.ts +16 -5
- package/dist/_dts/blocks/src/system/blocks/hero.d.ts +0 -2
- package/dist/_dts/blocks/src/system/blocks/media-text.d.ts +9 -9
- package/dist/_dts/blocks/src/system/blocks/shop.d.ts +3 -3
- package/dist/_dts/blocks/src/system/blocks/shop.shared.d.ts +8 -0
- package/dist/_dts/blocks/src/system/blocks/team-members.d.ts +1 -1
- package/dist/_dts/blocks/src/system/constants/events.d.ts +4 -1
- package/dist/_dts/blocks/src/system/manifest/schema.d.ts +3 -1
- package/dist/_dts/blocks/src/system/runtime/api/index.d.ts +1 -0
- package/dist/_dts/blocks/src/system/runtime/api/types.d.ts +17 -5
- package/dist/_dts/blocks/src/system/runtime/components/registry.client.d.ts +51 -6
- package/dist/_dts/blocks/src/system/runtime/components/runtime-backed-blocks.d.ts +24 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/course-registration/useCourseRegistrationWizard.d.ts +2 -2
- package/dist/_dts/blocks/src/system/runtime/nodes/event-details/logic.d.ts +1 -17
- package/dist/_dts/blocks/src/system/runtime/nodes/event-details.client.d.ts +5 -9
- package/dist/_dts/blocks/src/system/runtime/nodes/event-details.server.d.ts +5 -9
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration/event-registration.headless.contract.d.ts +7 -1
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration/eventPaymentOptions.d.ts +48 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration/types.d.ts +5 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration/useDiscountCodeUi.d.ts +4 -4
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration/useDiscountCodeUi.state.d.ts +50 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration/useEventRegistrationWizard.d.ts +2 -2
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration.interactive.d.ts +21 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/event-registration.server.d.ts +1 -1
- package/dist/_dts/blocks/src/system/runtime/nodes/events/EventCalendar.interactive.d.ts +11 -1
- package/dist/_dts/blocks/src/system/runtime/nodes/events/EventCombined.client.d.ts +2 -1
- package/dist/_dts/blocks/src/system/runtime/nodes/events/EventCombined.interactive.d.ts +11 -1
- package/dist/_dts/blocks/src/system/runtime/nodes/events/shared/calendarViewOptions.d.ts +10 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/events/shared/destination.d.ts +8 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/events/shared/eventProductEligibility.d.ts +24 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/events/shared/pricing.d.ts +3 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/events/shared/utils.d.ts +7 -0
- package/dist/_dts/blocks/src/system/runtime/nodes/shared/contract-schemas.d.ts +5 -2
- package/dist/_dts/blocks/src/system/runtime/nodes/shop-checkout-form.d.ts +2 -2
- package/dist/_dts/content-model/src/entry-slots/index.d.ts +1 -0
- package/dist/_dts/content-model/src/entry-slots/sdkBlocks.d.ts +21 -0
- package/dist/_dts/content-model/src/entry-slots/types.d.ts +7 -0
- package/dist/_dts/core/src/event-pricing.d.ts +12 -2
- package/dist/_dts/core/src/money-input.d.ts +18 -0
- package/dist/_dts/db/src/generated/supabase/database.types.d.ts +50 -0
- package/dist/_dts/media-editor/src/MediaEditor.d.ts +2 -1
- package/dist/_dts/media-editor/src/fieldUi.d.ts +6 -0
- package/dist/_dts/media-editor/src/index.d.ts +1 -1
- package/dist/_dts/preview-next/src/client/index.d.ts +1 -0
- package/dist/_dts/preview-next/src/client/preview/PreviewShell.d.ts +3 -2
- package/dist/_dts/preview-next/src/client/preview/PreviewShellLayout.d.ts +3 -2
- package/dist/_dts/preview-next/src/client/preview/PreviewThemedSiteDocument.d.ts +3 -2
- package/dist/_dts/preview-next/src/client/preview/SiteChromeEditableSurface.d.ts +2 -2
- package/dist/_dts/preview-next/src/client/preview/themeRuntime.d.ts +6 -0
- package/dist/_dts/preview-next/src/client/sdk/SdkPreviewMode.d.ts +2 -1
- package/dist/_dts/sdk/src/cli/commands/pull-dated-offering-scope.d.ts +10 -0
- package/dist/_dts/sdk/src/cli/content/reader.d.ts +12 -5
- package/dist/_dts/sdk/src/client/management/types.d.ts +6 -55
- package/dist/_dts/sdk/src/components.d.ts +1 -0
- package/dist/_dts/sdk/src/config/field-definitions.d.ts +3 -1
- package/dist/_dts/sdk/src/contracts/system-block-content.d.ts +3 -1
- package/dist/_dts/sdk/src/next/types.d.ts +8 -11
- package/dist/_dts/sdk/src/preview-next/client/index.d.ts +1 -1
- package/dist/_dts/sdk/src/public-api/contracts.d.ts +11 -1
- package/dist/_dts/sdk/src/rendering/blocks-theme-scope.d.ts +2 -1
- package/dist/_dts/sdk/src/rendering/components/Layout.d.ts +8 -7
- package/dist/_dts/sdk/src/rendering/components/pageShared.d.ts +5 -6
- package/dist/_dts/sdk/src/rendering/index.d.ts +1 -0
- package/dist/_dts/sdk/src/rendering/islands/types.d.ts +11 -1
- package/dist/_dts/sdk/src/rendering/server.d.ts +1 -0
- package/dist/_dts/sdk/src/rendering/themeRuntime.d.ts +26 -0
- package/dist/_dts/sdk/src/version.d.ts +1 -1
- package/dist/_dts/site-commands/src/commands.d.ts +18 -0
- package/dist/_dts/theme-core/src/ResponsiveScope.d.ts +12 -0
- package/dist/_dts/theme-core/src/accordions/types.d.ts +1 -1
- package/dist/_dts/theme-core/src/buttons/personalities/types.d.ts +2 -2
- package/dist/_dts/theme-core/src/buttons/types.d.ts +5 -5
- package/dist/_dts/theme-core/src/cards/types.d.ts +2 -2
- package/dist/_dts/theme-core/src/index.d.ts +2 -0
- package/dist/_dts/theme-core/src/mock-themes/all.d.ts +21 -21
- package/dist/_dts/theme-core/src/schema.d.ts +18 -18
- package/dist/_dts/theme-core/src/site-styles/designState.d.ts +2 -2
- package/dist/_dts/theme-core/src/site-styles/generatedSchemas.d.ts +2 -2
- package/dist/_dts/theme-core/src/site-styles/logoBranding.d.ts +4 -4
- package/dist/_dts/theme-core/src/themeRuntime.d.ts +11 -0
- package/dist/{chunk-F645A5UV.mjs → chunk-BOQXMCSP.mjs} +129 -101
- package/dist/{chunk-7YUAXONX.mjs → chunk-CR2VX432.mjs} +1563 -877
- package/dist/{chunk-HKJQERFR.mjs → chunk-FA6LVZ7C.mjs} +91 -55
- package/dist/{chunk-TGBJWKMP.mjs → chunk-H6TT5ZXI.mjs} +9 -1
- package/dist/{chunk-ZQRBLCW5.mjs → chunk-SYYJZPKU.mjs} +2 -2
- package/dist/{chunk-7N46MZHI.mjs → chunk-UG7I7S7W.mjs} +1 -1
- package/dist/cli/index.mjs +1057 -632
- package/dist/cli/init-docs/content/cli-reference.md +6 -1
- package/dist/cli/init-docs/content/content-management.md +27 -0
- package/dist/client/{accordion-MUCVNGQ7.mjs → accordion-4K7VGZ3I.mjs} +2 -2
- package/dist/client/{bookingForm-PKD6EFIE.mjs → bookingForm-3QXA3CIS.mjs} +26 -271
- package/dist/client/bookings.mjs +1586 -825
- package/dist/client/{carousel-3TKQSNJC.mjs → carousel-BEJKNGQ7.mjs} +3 -3
- package/dist/client/{cart-6XHSZK23.mjs → cart-44BBM6XG.mjs} +7 -8
- package/dist/client/{checkout-FVSPM6FI.mjs → checkout-THMHEYKF.mjs} +7 -8
- package/dist/client/{chunk-25W2EQUN.mjs → chunk-3H5CLFKT.mjs} +8 -0
- package/dist/client/{chunk-ZJZZA5EP.mjs → chunk-4COPESPO.mjs} +13 -16
- package/dist/client/chunk-5AJIMWKS.mjs +436 -0
- package/dist/client/{chunk-UQFY4AHX.mjs → chunk-B4H6QMPY.mjs} +157 -49
- package/dist/client/{chunk-VGLXACVK.mjs → chunk-DQIRKNZE.mjs} +1 -1
- package/dist/client/{chunk-7DH35FGA.mjs → chunk-EJBHK74Y.mjs} +1 -1
- package/dist/client/{chunk-SDIYSQAY.mjs → chunk-HIHOQGIP.mjs} +2 -3
- package/dist/client/{chunk-CQKKFEQD.mjs → chunk-JV7ZNAOU.mjs} +378 -111
- package/dist/client/{chunk-FHU6PFPM.mjs → chunk-KNTLBQ3N.mjs} +1 -1
- package/dist/client/{chunk-RSQWWUAD.mjs → chunk-PEDNDLPB.mjs} +4 -4
- package/dist/client/{chunk-EY42X22F.mjs → chunk-SLY6UDAS.mjs} +157 -5
- package/dist/client/{chunk-STJ2NCQM.mjs → chunk-WHZQDPBZ.mjs} +19 -1
- package/dist/client/{chunk-ZT5XE7FK.mjs → chunk-ZIAF2DA4.mjs} +1 -1
- package/dist/client/client.mjs +3552 -2898
- package/dist/client/{courseRegistration-ATZSYDHM.mjs → courseRegistration-URX7RCCK.mjs} +20 -58
- package/dist/client/{eventCalendar-6T2UGKKP.mjs → eventCalendar-GTENOQCE.mjs} +10 -11
- package/dist/client/{eventCombined-Q4VANXVF.mjs → eventCombined-EZVB72MF.mjs} +10 -11
- package/dist/client/{eventDetails-DW37E7VW.mjs → eventDetails-CH4BJR5Z.mjs} +10 -11
- package/dist/client/{eventListing-XURTSAUW.mjs → eventListing-4BVOI5HS.mjs} +10 -11
- package/dist/client/{eventRegistration-MRKEVAXW.mjs → eventRegistration-37LPIKIE.mjs} +10 -11
- package/dist/client/{form-WZZFFGMU.mjs → form-FX3Y54YK.mjs} +7 -7
- package/dist/client/{headerSection-EQYVQBLM.mjs → headerSection-UOZZGVYL.mjs} +3 -3
- package/dist/client/hooks.mjs +1169 -1063
- package/dist/client/{locationMap-MFF5VAZR.mjs → locationMap-VSIPKV35.mjs} +3 -3
- package/dist/client/{newsletterForm-JQ77UYIE.mjs → newsletterForm-6FRJKNAF.mjs} +5 -5
- package/dist/client/{productDetail-25LMT3IZ.mjs → productDetail-6AHMLXCO.mjs} +7 -8
- package/dist/client/{productList-5ABEMKUG.mjs → productList-M2CYIZVH.mjs} +7 -8
- package/dist/client/rendering/client.mjs +2912 -2316
- package/dist/client/rendering/islands.mjs +19 -19
- package/dist/client/rendering.mjs +2874 -2230
- package/dist/client/{shop-OMMQZ6YO.mjs → shop-AUOT6GEX.mjs} +7 -8
- package/dist/client/spam-protection.mjs +4 -5
- package/dist/preview-next/before-render.mjs +2 -2
- package/dist/preview-next/client/runtime.mjs +5 -5
- package/dist/{sdk-runtime-WNLBZ3ZH.mjs → sdk-runtime-6GPJNLU6.mjs} +6 -6
- package/dist/server/components.mjs +1856 -1509
- package/dist/server/config-validation.mjs +1394 -1288
- package/dist/server/config.mjs +1394 -1288
- package/dist/server/data.mjs +1169 -1063
- package/dist/server/index.mjs +135 -100
- package/dist/server/navigation.mjs +20 -30
- package/dist/server/next.mjs +1936 -1576
- package/dist/server/page-converter.mjs +1081 -967
- package/dist/server/prebuild.mjs +1 -1
- package/dist/server/rendering/server.mjs +1868 -1521
- package/dist/server/rendering.mjs +1878 -1531
- package/dist/server/routing.mjs +1248 -1089
- package/dist/server/server.mjs +1312 -1171
- package/dist/server/theme-bridge.mjs +8 -5
- package/package.json +3 -3
- package/dist/SdkPreviewModeRuntime-ZBEMRV7N.mjs +0 -8
- package/dist/client/chunk-LQFDYWPJ.mjs +0 -184
- package/dist/client/chunk-ZFHRN6W2.mjs +0 -66
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { normalizeCarouselProps, CarouselNodeClient } from './chunk-
|
|
1
|
+
import { normalizeCarouselProps, CarouselNodeClient } from './chunk-EJBHK74Y.mjs';
|
|
2
2
|
import './chunk-6N7YRNYU.mjs';
|
|
3
3
|
import { mountReactIsland } from './chunk-N7PBWBWQ.mjs';
|
|
4
|
-
import { defineIslandPropsDecoder } from './chunk-
|
|
5
|
-
import './chunk-
|
|
4
|
+
import { defineIslandPropsDecoder } from './chunk-B4H6QMPY.mjs';
|
|
5
|
+
import './chunk-3H5CLFKT.mjs';
|
|
6
6
|
import { jsx } from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
8
|
var decode = defineIslandPropsDecoder("carousel");
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { mountShopBlockIsland, CartClient } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { mountShopBlockIsland, CartClient } from './chunk-4COPESPO.mjs';
|
|
2
|
+
import './chunk-DQIRKNZE.mjs';
|
|
3
|
+
import './chunk-EJBHK74Y.mjs';
|
|
4
4
|
import './chunk-6N7YRNYU.mjs';
|
|
5
|
-
import './chunk-ZFHRN6W2.mjs';
|
|
6
5
|
import './chunk-L4J5Y62O.mjs';
|
|
7
|
-
import './chunk-
|
|
6
|
+
import './chunk-SLY6UDAS.mjs';
|
|
8
7
|
import './chunk-3DCJ45Z2.mjs';
|
|
9
8
|
import './chunk-WBQG7VJA.mjs';
|
|
10
|
-
import './chunk-
|
|
9
|
+
import './chunk-WHZQDPBZ.mjs';
|
|
11
10
|
import './chunk-N7PBWBWQ.mjs';
|
|
12
|
-
import { defineIslandPropsDecoder } from './chunk-
|
|
13
|
-
import './chunk-
|
|
11
|
+
import { defineIslandPropsDecoder } from './chunk-B4H6QMPY.mjs';
|
|
12
|
+
import './chunk-3H5CLFKT.mjs';
|
|
14
13
|
|
|
15
14
|
// src/rendering/islands/enhancers/cart.tsx
|
|
16
15
|
var decode = defineIslandPropsDecoder("cart");
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { mountShopBlockIsland, CheckoutClient } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
import { mountShopBlockIsland, CheckoutClient } from './chunk-4COPESPO.mjs';
|
|
2
|
+
import './chunk-DQIRKNZE.mjs';
|
|
3
|
+
import './chunk-EJBHK74Y.mjs';
|
|
4
4
|
import './chunk-6N7YRNYU.mjs';
|
|
5
|
-
import './chunk-ZFHRN6W2.mjs';
|
|
6
5
|
import './chunk-L4J5Y62O.mjs';
|
|
7
|
-
import './chunk-
|
|
6
|
+
import './chunk-SLY6UDAS.mjs';
|
|
8
7
|
import './chunk-3DCJ45Z2.mjs';
|
|
9
8
|
import './chunk-WBQG7VJA.mjs';
|
|
10
|
-
import './chunk-
|
|
9
|
+
import './chunk-WHZQDPBZ.mjs';
|
|
11
10
|
import './chunk-N7PBWBWQ.mjs';
|
|
12
|
-
import { defineIslandPropsDecoder } from './chunk-
|
|
13
|
-
import './chunk-
|
|
11
|
+
import { defineIslandPropsDecoder } from './chunk-B4H6QMPY.mjs';
|
|
12
|
+
import './chunk-3H5CLFKT.mjs';
|
|
14
13
|
|
|
15
14
|
// src/rendering/islands/enhancers/checkout.tsx
|
|
16
15
|
var decode = defineIslandPropsDecoder("checkout");
|
|
@@ -88,6 +88,8 @@ function publicEventPricingType(pricing) {
|
|
|
88
88
|
case "ticket_types":
|
|
89
89
|
case "course":
|
|
90
90
|
return isFreePublicEventPriceDisplay(pricing.display) ? "free" : "paid";
|
|
91
|
+
case "external":
|
|
92
|
+
return "external";
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
function publicEventPricingCurrency(pricing) {
|
|
@@ -99,6 +101,8 @@ function publicEventPricingCurrency(pricing) {
|
|
|
99
101
|
return pricing.currency;
|
|
100
102
|
case "course":
|
|
101
103
|
return pricing.display.display.currency;
|
|
104
|
+
case "external":
|
|
105
|
+
return null;
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
function publicEventScalarPrice(pricing) {
|
|
@@ -113,6 +117,7 @@ function publicEventPricingMode(pricing) {
|
|
|
113
117
|
return "ticket_types";
|
|
114
118
|
case "drop_in":
|
|
115
119
|
case "course":
|
|
120
|
+
case "external":
|
|
116
121
|
return void 0;
|
|
117
122
|
}
|
|
118
123
|
}
|
|
@@ -130,6 +135,7 @@ function isFreePublicEventPriceDisplay(display) {
|
|
|
130
135
|
case "range":
|
|
131
136
|
case "mixed":
|
|
132
137
|
case "unavailable":
|
|
138
|
+
case "external":
|
|
133
139
|
return false;
|
|
134
140
|
}
|
|
135
141
|
}
|
|
@@ -160,6 +166,8 @@ function formatBookingPriceDisplay(display, options = {}) {
|
|
|
160
166
|
return display.paidToAmount > display.paidFromAmount ? `Free / ${formatCurrencyAmount(display.paidFromAmount, display.currency, options)} - ${formatCurrencyAmount(display.paidToAmount, display.currency, options)}` : `Free / ${formatCurrencyAmount(display.paidFromAmount, display.currency, options)}`;
|
|
161
167
|
case "unavailable":
|
|
162
168
|
return "Pricing unavailable";
|
|
169
|
+
case "external":
|
|
170
|
+
return display.label;
|
|
163
171
|
case "course":
|
|
164
172
|
return formatCoursePriceDisplayLabel(display.display, options);
|
|
165
173
|
default:
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { addPassToCommerceCart, useCommerceCart } from './chunk-
|
|
3
|
-
import { CarouselNodeClient } from './chunk-
|
|
4
|
-
import { useDiscountCodeUi } from './chunk-ZFHRN6W2.mjs';
|
|
2
|
+
import { addPassToCommerceCart, useCommerceCart } from './chunk-DQIRKNZE.mjs';
|
|
3
|
+
import { CarouselNodeClient } from './chunk-EJBHK74Y.mjs';
|
|
5
4
|
import { buildRouteIslandApiConfig } from './chunk-L4J5Y62O.mjs';
|
|
6
|
-
import { createBodyThemePortalRoot, consumeSearchParams, scrollToBlock, TerminalPanel, StateIcon, CheckIcon, CrossIcon, ActionRow, DiscountCodeDisclosure, consumeSearchParam, buildCheckoutReturnUrls } from './chunk-
|
|
5
|
+
import { useDiscountCodeUi, createBodyThemePortalRoot, consumeSearchParams, scrollToBlock, TerminalPanel, StateIcon, CheckIcon, CrossIcon, ActionRow, DiscountCodeDisclosure, consumeSearchParam, buildCheckoutReturnUrls } from './chunk-SLY6UDAS.mjs';
|
|
7
6
|
import { ModalShell, resolveDedicatedCheckoutPath } from './chunk-WBQG7VJA.mjs';
|
|
8
|
-
import { useBlockApi, FeedbackMessage, BlockApiProvider } from './chunk-
|
|
7
|
+
import { useBlockApi, FeedbackMessage, BlockApiProvider, discountAvailabilityHasDiscounts, discountAvailabilityAllowsManualEntry, getAutoAppliedDiscountPreview } from './chunk-WHZQDPBZ.mjs';
|
|
9
8
|
import { mountReactIsland } from './chunk-N7PBWBWQ.mjs';
|
|
10
|
-
import { themeButtonClassName, formatCommercePrice, formatInterval, getShopDisplayForItems, deriveCommerceCheckoutState, buildProductDetailDisplay, productItemKey, buildProductCartItem, buildProductCardDisplay,
|
|
11
|
-
import { assertNever, ok, err, getCurrentResolveImageUrlContext, resolveImageUrlWithContext, ImagePresets } from './chunk-
|
|
9
|
+
import { themeButtonClassName, formatCommercePrice, formatInterval, getShopDisplayForItems, deriveCommerceCheckoutState, buildProductDetailDisplay, productItemKey, buildProductCartItem, buildProductCardDisplay, assertNever as assertNever$1, reportWorkflowError, clearWorkflowFeedback, unwrapRichTextRoot, createRichTextDocFromMarkdown, isRecord } from './chunk-B4H6QMPY.mjs';
|
|
10
|
+
import { assertNever, ok, err, getCurrentResolveImageUrlContext, resolveImageUrlWithContext, ImagePresets } from './chunk-3H5CLFKT.mjs';
|
|
12
11
|
import * as React3 from 'react';
|
|
13
12
|
import React3__default, { useState, useRef, useCallback, useEffect } from 'react';
|
|
14
13
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -443,7 +442,7 @@ function shopCheckoutReducer(state, action) {
|
|
|
443
442
|
notice: action.notice
|
|
444
443
|
};
|
|
445
444
|
default:
|
|
446
|
-
return
|
|
445
|
+
return assertNever$1(action);
|
|
447
446
|
}
|
|
448
447
|
}
|
|
449
448
|
|
|
@@ -574,15 +573,13 @@ function planCartDiscountAvailabilityRequests(checkout) {
|
|
|
574
573
|
}));
|
|
575
574
|
}
|
|
576
575
|
function aggregateCartDiscountUiState(availability) {
|
|
577
|
-
if (!availability.some(
|
|
576
|
+
if (!availability.some(discountAvailabilityHasDiscounts)) {
|
|
578
577
|
return { type: "unavailable" };
|
|
579
578
|
}
|
|
580
|
-
if (availability.some(
|
|
579
|
+
if (availability.some(discountAvailabilityAllowsManualEntry)) {
|
|
581
580
|
return { type: "manual-allowed" };
|
|
582
581
|
}
|
|
583
|
-
const autoAppliedDiscount = availability.find(
|
|
584
|
-
(item) => item.autoAppliedDiscount
|
|
585
|
-
)?.autoAppliedDiscount ?? null;
|
|
582
|
+
const autoAppliedDiscount = availability.map(getAutoAppliedDiscountPreview).find((discount) => discount !== null) ?? null;
|
|
586
583
|
return {
|
|
587
584
|
type: "auto-only",
|
|
588
585
|
autoAppliedDiscount
|
|
@@ -681,7 +678,7 @@ function discountApplyReducer(state, action) {
|
|
|
681
678
|
status: { type: "idle" }
|
|
682
679
|
};
|
|
683
680
|
default:
|
|
684
|
-
return
|
|
681
|
+
return assertNever$1(action);
|
|
685
682
|
}
|
|
686
683
|
}
|
|
687
684
|
function getAppliedDiscountCode(state) {
|
|
@@ -712,7 +709,7 @@ function getDiscountApplyFeedback(status, formatPrice) {
|
|
|
712
709
|
message: status.message
|
|
713
710
|
};
|
|
714
711
|
default:
|
|
715
|
-
return
|
|
712
|
+
return assertNever$1(status);
|
|
716
713
|
}
|
|
717
714
|
}
|
|
718
715
|
var DISCOUNT_APPLY_MESSAGES = {
|
|
@@ -1283,7 +1280,7 @@ function shopPassesMembershipsReducer(state, action) {
|
|
|
1283
1280
|
returnNotice: null
|
|
1284
1281
|
};
|
|
1285
1282
|
default:
|
|
1286
|
-
return
|
|
1283
|
+
return assertNever$1(action);
|
|
1287
1284
|
}
|
|
1288
1285
|
}
|
|
1289
1286
|
function getOpenCheckout(state) {
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatPrice } from './chunk-SLY6UDAS.mjs';
|
|
3
|
+
import { assertNever } from './chunk-B4H6QMPY.mjs';
|
|
4
|
+
import { resolveFlexibleBalanceInitialPaymentCents, resolveFlexibleBalanceDueAt, getBookingInstalmentDepositRefundability, splitAmountWithRemainderInFirst, addIntervalPreservingMonthAnchor, clampConfiguredAmount, getBookingInstalmentPlanIntervalCount, omitZeroAmountFutureRows } from './chunk-3H5CLFKT.mjs';
|
|
5
|
+
import { useReducer, useRef, useCallback, useEffect } from 'react';
|
|
6
|
+
|
|
7
|
+
// ../blocks/src/system/runtime/shared/bookingPaymentOptionCopy.ts
|
|
8
|
+
function buildUpfrontBookingPaymentOptionCopy(formattedTotal) {
|
|
9
|
+
return {
|
|
10
|
+
title: "Pay in full",
|
|
11
|
+
description: "Pay everything today and your booking is confirmed.",
|
|
12
|
+
ctaLabel: `Pay ${formattedTotal} now`
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function buildDeferredManualBookingPaymentOptionCopy() {
|
|
16
|
+
return {
|
|
17
|
+
title: "Pay offline",
|
|
18
|
+
description: "Book now and pay the business later, outside the platform.",
|
|
19
|
+
helperText: "Nothing is due today.",
|
|
20
|
+
ctaLabel: "Book now"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function buildInstalmentBookingPaymentOptionCopy(input) {
|
|
24
|
+
return {
|
|
25
|
+
title: "Payment plan",
|
|
26
|
+
description: describeInstalmentPlanCopy(input),
|
|
27
|
+
helperText: "You can pay the rest early any time in your customer portal.",
|
|
28
|
+
ctaLabel: `Pay ${input.formattedDueToday} now`
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function describeInstalmentPlanCopy(input) {
|
|
32
|
+
if (input.depositRefundability) {
|
|
33
|
+
return `Pay ${input.formattedDueToday} today, then continue with scheduled payments. Your deposit is ${formatDepositRefundabilityLabel(input.depositRefundability)}.`;
|
|
34
|
+
}
|
|
35
|
+
if (input.futurePaymentCount === 0) {
|
|
36
|
+
return `Pay ${input.formattedDueToday} today.`;
|
|
37
|
+
}
|
|
38
|
+
if (input.futurePaymentCount === 1) {
|
|
39
|
+
return `Pay ${input.formattedDueToday} today, then one more payment later.`;
|
|
40
|
+
}
|
|
41
|
+
const formattedFirstFuture = input.formattedFirstFuture ?? input.formattedDueToday;
|
|
42
|
+
return `Pay ${input.formattedDueToday} today, then ${input.futurePaymentCount} more ${input.cadenceLabel} payments from ${formattedFirstFuture}.`;
|
|
43
|
+
}
|
|
44
|
+
function buildFlexibleBalanceBookingPaymentOptionCopy(input) {
|
|
45
|
+
return {
|
|
46
|
+
title: "Deposit now, pay the rest later",
|
|
47
|
+
description: `Pay ${input.formattedDueToday} today, then pay the remaining balance any time before ${input.dueDateLabel}. Your deposit is ${formatDepositRefundabilityLabel(input.depositRefundability)}.`,
|
|
48
|
+
helperText: "You can return in your customer portal to pay the rest before the due date.",
|
|
49
|
+
ctaLabel: `Pay ${input.formattedDueToday} now`
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function formatDepositRefundabilityLabel(depositRefundability) {
|
|
53
|
+
return depositRefundability === "non_refundable" ? "non-refundable" : "refundable";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ../blocks/src/system/runtime/shared/bookingPaymentOptions.ts
|
|
57
|
+
function buildBookingPaymentSelectionViewModel(input) {
|
|
58
|
+
const currency = input.priceCurrency ?? "USD";
|
|
59
|
+
const totalCents = Math.max(0, input.priceAmount ?? 0);
|
|
60
|
+
const allowedOptions = input.paymentTerms?.allowedOptions ?? [{ kind: "upfront" }];
|
|
61
|
+
const mode = allowedOptions.length > 1 ? "choice_required" : "single_option";
|
|
62
|
+
return {
|
|
63
|
+
mode,
|
|
64
|
+
sectionTitle: mode === "choice_required" ? "Choose how you'd like to pay" : "Payment",
|
|
65
|
+
serviceTitle: input.serviceTitle,
|
|
66
|
+
options: allowedOptions.map((option) => buildBookingPaymentOptionViewModel({
|
|
67
|
+
option,
|
|
68
|
+
totalCents,
|
|
69
|
+
currency,
|
|
70
|
+
bookingStartAt: input.bookingStartAt,
|
|
71
|
+
locale: input.locale
|
|
72
|
+
}))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function buildBookingPaymentOptionViewModel(input) {
|
|
76
|
+
switch (input.option.kind) {
|
|
77
|
+
case "upfront": {
|
|
78
|
+
const formattedTotal = formatPrice(input.totalCents, input.currency, input.locale);
|
|
79
|
+
const copy = buildUpfrontBookingPaymentOptionCopy(formattedTotal);
|
|
80
|
+
return {
|
|
81
|
+
kind: "upfront",
|
|
82
|
+
title: copy.title,
|
|
83
|
+
description: copy.description,
|
|
84
|
+
summaryRows: [
|
|
85
|
+
{ label: "Total", value: formattedTotal },
|
|
86
|
+
{ label: "Due today", value: formattedTotal }
|
|
87
|
+
],
|
|
88
|
+
ctaLabel: copy.ctaLabel
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
case "deferred_manual": {
|
|
92
|
+
const formattedTotal = formatPrice(input.totalCents, input.currency, input.locale);
|
|
93
|
+
const copy = buildDeferredManualBookingPaymentOptionCopy();
|
|
94
|
+
return {
|
|
95
|
+
kind: "deferred_manual",
|
|
96
|
+
title: copy.title,
|
|
97
|
+
description: copy.description,
|
|
98
|
+
summaryRows: [
|
|
99
|
+
{ label: "Total", value: formattedTotal },
|
|
100
|
+
{ label: "Due today", value: formatPrice(0, input.currency, input.locale) }
|
|
101
|
+
],
|
|
102
|
+
helperText: copy.helperText,
|
|
103
|
+
ctaLabel: copy.ctaLabel
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
case "instalment_plan": {
|
|
107
|
+
const schedulePreview = buildInstalmentSchedulePreview({
|
|
108
|
+
totalCents: input.totalCents,
|
|
109
|
+
option: input.option,
|
|
110
|
+
bookingStartAt: input.bookingStartAt
|
|
111
|
+
});
|
|
112
|
+
const dueToday = schedulePreview[0]?.amountCents ?? input.totalCents;
|
|
113
|
+
const futureRows = schedulePreview.slice(1);
|
|
114
|
+
const formattedTotal = formatPrice(input.totalCents, input.currency, input.locale);
|
|
115
|
+
const formattedDueToday = formatPrice(dueToday, input.currency, input.locale);
|
|
116
|
+
const depositRefundability = getBookingInstalmentDepositRefundability(input.option.plan);
|
|
117
|
+
const copy = buildInstalmentBookingPaymentOptionCopy({
|
|
118
|
+
formattedDueToday,
|
|
119
|
+
futurePaymentCount: futureRows.length,
|
|
120
|
+
formattedFirstFuture: futureRows[0] ? formatPrice(futureRows[0].amountCents, input.currency, input.locale) : null,
|
|
121
|
+
cadenceLabel: getPaymentCadenceLabel(input.option.plan),
|
|
122
|
+
depositRefundability
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
kind: "instalment_plan",
|
|
126
|
+
title: copy.title,
|
|
127
|
+
description: copy.description,
|
|
128
|
+
summaryRows: [
|
|
129
|
+
{ label: "Total", value: formattedTotal },
|
|
130
|
+
{ label: "Due today", value: formattedDueToday },
|
|
131
|
+
...depositRefundability ? [{
|
|
132
|
+
label: "Deposit policy",
|
|
133
|
+
value: depositRefundability === "non_refundable" ? "Non-refundable" : "Refundable"
|
|
134
|
+
}] : [],
|
|
135
|
+
...futureRows.map((row) => ({
|
|
136
|
+
label: formatScheduleDate(row.dueAt, input.locale),
|
|
137
|
+
value: formatPrice(row.amountCents, input.currency, input.locale)
|
|
138
|
+
}))
|
|
139
|
+
],
|
|
140
|
+
helperText: copy.helperText,
|
|
141
|
+
ctaLabel: copy.ctaLabel
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
case "flexible_balance": {
|
|
145
|
+
const dueToday = resolveFlexibleBalanceInitialPaymentCents({
|
|
146
|
+
totalAmountCents: input.totalCents,
|
|
147
|
+
config: input.option.config
|
|
148
|
+
});
|
|
149
|
+
const remainingBalance = Math.max(0, input.totalCents - dueToday);
|
|
150
|
+
const formattedTotal = formatPrice(input.totalCents, input.currency, input.locale);
|
|
151
|
+
const formattedDueToday = formatPrice(dueToday, input.currency, input.locale);
|
|
152
|
+
const formattedRemainingBalance = formatPrice(remainingBalance, input.currency, input.locale);
|
|
153
|
+
const dueAt = resolveFlexibleBalanceDueAt({
|
|
154
|
+
bookingStartAt: input.bookingStartAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
155
|
+
dueDateRule: input.option.config.dueDateRule
|
|
156
|
+
});
|
|
157
|
+
const copy = buildFlexibleBalanceBookingPaymentOptionCopy({
|
|
158
|
+
formattedDueToday,
|
|
159
|
+
dueDateLabel: formatScheduleDate(dueAt, input.locale),
|
|
160
|
+
depositRefundability: input.option.config.depositRefundability
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
kind: "flexible_balance",
|
|
164
|
+
title: copy.title,
|
|
165
|
+
description: copy.description,
|
|
166
|
+
summaryRows: [
|
|
167
|
+
{ label: "Total", value: formattedTotal },
|
|
168
|
+
{ label: "Due today", value: formattedDueToday },
|
|
169
|
+
{ label: "Remaining balance", value: formattedRemainingBalance },
|
|
170
|
+
{ label: "Balance due by", value: formatScheduleDate(dueAt, input.locale) },
|
|
171
|
+
{
|
|
172
|
+
label: "Deposit policy",
|
|
173
|
+
value: input.option.config.depositRefundability === "non_refundable" ? "Non-refundable" : "Refundable"
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
helperText: copy.helperText,
|
|
177
|
+
ctaLabel: copy.ctaLabel
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
default:
|
|
181
|
+
return assertNever(input.option);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function buildInstalmentSchedulePreview(input) {
|
|
185
|
+
const startAt = input.bookingStartAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
186
|
+
switch (input.option.plan.kind) {
|
|
187
|
+
case "deposit_plus_one_remainder": {
|
|
188
|
+
const deposit = clampConfiguredAmount(input.option.plan.depositAmountCents, input.totalCents);
|
|
189
|
+
const remainder = Math.max(0, input.totalCents - deposit);
|
|
190
|
+
return compactSchedulePreview([
|
|
191
|
+
{ dueAt: startAt, amountCents: deposit },
|
|
192
|
+
{
|
|
193
|
+
dueAt: addIntervalPreservingMonthAnchor(
|
|
194
|
+
startAt,
|
|
195
|
+
input.option.plan.remainderDueCount,
|
|
196
|
+
input.option.plan.intervalUnit
|
|
197
|
+
),
|
|
198
|
+
amountCents: remainder
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
case "deposit_plus_scheduled_instalments": {
|
|
203
|
+
const plan = input.option.plan;
|
|
204
|
+
const deposit = clampConfiguredAmount(plan.depositAmountCents, input.totalCents);
|
|
205
|
+
const remaining = Math.max(0, input.totalCents - deposit);
|
|
206
|
+
const instalments = splitAmountWithRemainderInFirst(
|
|
207
|
+
remaining,
|
|
208
|
+
plan.instalmentCount
|
|
209
|
+
);
|
|
210
|
+
return compactSchedulePreview([
|
|
211
|
+
{ dueAt: startAt, amountCents: deposit },
|
|
212
|
+
...instalments.map((amountCents, index) => ({
|
|
213
|
+
dueAt: addIntervalPreservingMonthAnchor(
|
|
214
|
+
startAt,
|
|
215
|
+
plan.intervalCount * (index + 1),
|
|
216
|
+
plan.intervalUnit
|
|
217
|
+
),
|
|
218
|
+
amountCents
|
|
219
|
+
}))
|
|
220
|
+
]);
|
|
221
|
+
}
|
|
222
|
+
case "equal_scheduled_instalments": {
|
|
223
|
+
const plan = input.option.plan;
|
|
224
|
+
const instalments = splitAmountWithRemainderInFirst(
|
|
225
|
+
input.totalCents,
|
|
226
|
+
plan.instalmentCount
|
|
227
|
+
);
|
|
228
|
+
return compactSchedulePreview(instalments.map((amountCents, index) => ({
|
|
229
|
+
dueAt: index === 0 ? startAt : addIntervalPreservingMonthAnchor(
|
|
230
|
+
startAt,
|
|
231
|
+
plan.intervalCount * index,
|
|
232
|
+
plan.intervalUnit
|
|
233
|
+
),
|
|
234
|
+
amountCents
|
|
235
|
+
})));
|
|
236
|
+
}
|
|
237
|
+
default:
|
|
238
|
+
return assertNever(input.option.plan);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function getPaymentCadenceLabel(plan) {
|
|
242
|
+
const intervalCount = getBookingInstalmentPlanIntervalCount(plan);
|
|
243
|
+
const unitLabel = intervalCount === 1 ? plan.intervalUnit : `${plan.intervalUnit}s`;
|
|
244
|
+
return intervalCount === 1 ? unitLabel : `every ${intervalCount} ${unitLabel}`;
|
|
245
|
+
}
|
|
246
|
+
function compactSchedulePreview(schedule) {
|
|
247
|
+
return omitZeroAmountFutureRows(schedule);
|
|
248
|
+
}
|
|
249
|
+
function formatScheduleDate(isoString, locale) {
|
|
250
|
+
const date = new Date(isoString);
|
|
251
|
+
if (!Number.isFinite(date.getTime())) {
|
|
252
|
+
return isoString;
|
|
253
|
+
}
|
|
254
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(date);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ../blocks/src/system/runtime/hooks/usePolling.state.ts
|
|
258
|
+
function createInitialPollingState() {
|
|
259
|
+
return {
|
|
260
|
+
tag: "idle",
|
|
261
|
+
result: null,
|
|
262
|
+
error: null
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function pollingReducer(state, action) {
|
|
266
|
+
switch (action.type) {
|
|
267
|
+
case "polling-went-idle":
|
|
268
|
+
return createInitialPollingState();
|
|
269
|
+
case "polling-reset":
|
|
270
|
+
return {
|
|
271
|
+
tag: "polling",
|
|
272
|
+
result: null,
|
|
273
|
+
error: null
|
|
274
|
+
};
|
|
275
|
+
case "polling-progressed":
|
|
276
|
+
return {
|
|
277
|
+
tag: "polling",
|
|
278
|
+
result: action.result,
|
|
279
|
+
error: null
|
|
280
|
+
};
|
|
281
|
+
case "polling-completed":
|
|
282
|
+
return {
|
|
283
|
+
tag: "completed",
|
|
284
|
+
result: action.result,
|
|
285
|
+
error: null
|
|
286
|
+
};
|
|
287
|
+
case "polling-failed":
|
|
288
|
+
return {
|
|
289
|
+
tag: "failed",
|
|
290
|
+
result: action.result,
|
|
291
|
+
error: null
|
|
292
|
+
};
|
|
293
|
+
case "polling-request-failed":
|
|
294
|
+
switch (state.tag) {
|
|
295
|
+
case "idle":
|
|
296
|
+
return {
|
|
297
|
+
tag: "polling",
|
|
298
|
+
result: null,
|
|
299
|
+
error: action.error
|
|
300
|
+
};
|
|
301
|
+
case "polling":
|
|
302
|
+
return {
|
|
303
|
+
tag: "polling",
|
|
304
|
+
result: state.result,
|
|
305
|
+
error: action.error
|
|
306
|
+
};
|
|
307
|
+
case "completed":
|
|
308
|
+
case "failed":
|
|
309
|
+
case "timeout":
|
|
310
|
+
return state;
|
|
311
|
+
default:
|
|
312
|
+
return assertNever(state);
|
|
313
|
+
}
|
|
314
|
+
case "polling-timed-out":
|
|
315
|
+
return {
|
|
316
|
+
tag: "timeout",
|
|
317
|
+
result: state.result,
|
|
318
|
+
error: new Error("Polling timed out")
|
|
319
|
+
};
|
|
320
|
+
default:
|
|
321
|
+
return assertNever(action);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// ../blocks/src/system/runtime/hooks/usePolling.ts
|
|
326
|
+
var DEFAULT_MAX_ATTEMPTS = 10;
|
|
327
|
+
var DEFAULT_POLL_INTERVAL = 1e3;
|
|
328
|
+
function usePolling(config) {
|
|
329
|
+
const [state, dispatch] = useReducer(
|
|
330
|
+
pollingReducer,
|
|
331
|
+
void 0,
|
|
332
|
+
createInitialPollingState
|
|
333
|
+
);
|
|
334
|
+
const attemptsRef = useRef(0);
|
|
335
|
+
const timeoutRef = useRef(null);
|
|
336
|
+
const isPollingRef = useRef(false);
|
|
337
|
+
const isActiveRef = useRef(false);
|
|
338
|
+
const generationRef = useRef(0);
|
|
339
|
+
const configRef = useRef(config);
|
|
340
|
+
configRef.current = config;
|
|
341
|
+
const cleanup = useCallback(() => {
|
|
342
|
+
isActiveRef.current = false;
|
|
343
|
+
generationRef.current += 1;
|
|
344
|
+
if (timeoutRef.current) {
|
|
345
|
+
clearTimeout(timeoutRef.current);
|
|
346
|
+
timeoutRef.current = null;
|
|
347
|
+
}
|
|
348
|
+
isPollingRef.current = false;
|
|
349
|
+
}, []);
|
|
350
|
+
const resetState = useCallback(() => {
|
|
351
|
+
dispatch({ type: "polling-reset" });
|
|
352
|
+
attemptsRef.current = 0;
|
|
353
|
+
}, []);
|
|
354
|
+
const poll = useCallback(async () => {
|
|
355
|
+
const cfg = configRef.current;
|
|
356
|
+
if (!cfg) return true;
|
|
357
|
+
if (isPollingRef.current) return false;
|
|
358
|
+
const maxAttempts = cfg.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
359
|
+
if (attemptsRef.current >= maxAttempts) {
|
|
360
|
+
dispatch({ type: "polling-timed-out" });
|
|
361
|
+
cleanup();
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
isPollingRef.current = true;
|
|
365
|
+
attemptsRef.current += 1;
|
|
366
|
+
const generation = generationRef.current;
|
|
367
|
+
try {
|
|
368
|
+
const data = await cfg.pollFn();
|
|
369
|
+
if (generation !== generationRef.current || !isActiveRef.current) {
|
|
370
|
+
isPollingRef.current = false;
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
if (cfg.isFailed?.(data)) {
|
|
374
|
+
dispatch({ type: "polling-failed", result: data });
|
|
375
|
+
cleanup();
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
if (cfg.isComplete(data)) {
|
|
379
|
+
dispatch({ type: "polling-completed", result: data });
|
|
380
|
+
cleanup();
|
|
381
|
+
return true;
|
|
382
|
+
}
|
|
383
|
+
dispatch({ type: "polling-progressed", result: data });
|
|
384
|
+
isPollingRef.current = false;
|
|
385
|
+
return false;
|
|
386
|
+
} catch (err) {
|
|
387
|
+
if (generation !== generationRef.current || !isActiveRef.current) {
|
|
388
|
+
isPollingRef.current = false;
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
if (err instanceof Error) {
|
|
392
|
+
dispatch({ type: "polling-request-failed", error: err });
|
|
393
|
+
}
|
|
394
|
+
isPollingRef.current = false;
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}, [cleanup]);
|
|
398
|
+
const schedulePoll = useCallback(() => {
|
|
399
|
+
if (!isActiveRef.current) return;
|
|
400
|
+
const cfg = configRef.current;
|
|
401
|
+
const pollInterval = cfg?.interval ?? DEFAULT_POLL_INTERVAL;
|
|
402
|
+
const doPoll = async () => {
|
|
403
|
+
const shouldStop = await poll();
|
|
404
|
+
if (!shouldStop && isActiveRef.current) {
|
|
405
|
+
timeoutRef.current = setTimeout(doPoll, pollInterval);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
void doPoll();
|
|
409
|
+
}, [poll]);
|
|
410
|
+
useEffect(() => {
|
|
411
|
+
if (!config) {
|
|
412
|
+
cleanup();
|
|
413
|
+
dispatch({ type: "polling-went-idle" });
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
resetState();
|
|
417
|
+
isActiveRef.current = true;
|
|
418
|
+
schedulePoll();
|
|
419
|
+
return cleanup;
|
|
420
|
+
}, [config, cleanup, resetState, schedulePoll]);
|
|
421
|
+
const retry = useCallback(() => {
|
|
422
|
+
if (!configRef.current) return;
|
|
423
|
+
cleanup();
|
|
424
|
+
resetState();
|
|
425
|
+
isActiveRef.current = true;
|
|
426
|
+
schedulePoll();
|
|
427
|
+
}, [cleanup, resetState, schedulePoll]);
|
|
428
|
+
return {
|
|
429
|
+
status: config ? state.tag : "idle",
|
|
430
|
+
result: config ? state.result : null,
|
|
431
|
+
error: config ? state.error : null,
|
|
432
|
+
retry
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export { buildBookingPaymentSelectionViewModel, usePolling };
|