@wix/headless-gift-voucher 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/cjs/dist/__mocks__/gift-card.d.ts +14 -0
  2. package/cjs/dist/__mocks__/gift-card.d.ts.map +1 -0
  3. package/cjs/dist/__mocks__/gift-card.js +49 -0
  4. package/cjs/dist/enums/index.d.ts +52 -0
  5. package/cjs/dist/enums/index.d.ts.map +1 -0
  6. package/cjs/dist/enums/index.js +52 -0
  7. package/cjs/dist/react/GiftCard.d.ts +1318 -0
  8. package/cjs/dist/react/GiftCard.d.ts.map +1 -0
  9. package/cjs/dist/react/GiftCard.js +1126 -0
  10. package/cjs/dist/react/core/GiftCard.d.ts +863 -0
  11. package/cjs/dist/react/core/GiftCard.d.ts.map +1 -0
  12. package/cjs/dist/react/core/GiftCard.js +737 -0
  13. package/cjs/dist/react/index.d.ts +2 -0
  14. package/cjs/dist/react/index.d.ts.map +1 -0
  15. package/cjs/dist/react/index.js +1 -0
  16. package/cjs/dist/services/gift-card-checkout-service.d.ts +133 -0
  17. package/cjs/dist/services/gift-card-checkout-service.d.ts.map +1 -0
  18. package/cjs/dist/services/gift-card-checkout-service.js +159 -0
  19. package/cjs/dist/services/gift-card-service.d.ts +102 -0
  20. package/cjs/dist/services/gift-card-service.d.ts.map +1 -0
  21. package/cjs/dist/services/gift-card-service.js +165 -0
  22. package/cjs/dist/services/index.d.ts +3 -0
  23. package/cjs/dist/services/index.d.ts.map +1 -0
  24. package/cjs/dist/services/index.js +2 -0
  25. package/cjs/dist/utils/formatting-utils.d.ts +13 -0
  26. package/cjs/dist/utils/formatting-utils.d.ts.map +1 -0
  27. package/cjs/dist/utils/formatting-utils.js +38 -0
  28. package/cjs/dist/utils/gift-card-utils.d.ts +18 -0
  29. package/cjs/dist/utils/gift-card-utils.d.ts.map +1 -0
  30. package/cjs/dist/utils/gift-card-utils.js +118 -0
  31. package/cjs/dist/utils/validation-utils.d.ts +10 -0
  32. package/cjs/dist/utils/validation-utils.d.ts.map +1 -0
  33. package/cjs/dist/utils/validation-utils.js +24 -0
  34. package/dist/__mocks__/gift-card.d.ts +14 -0
  35. package/dist/__mocks__/gift-card.d.ts.map +1 -0
  36. package/dist/__mocks__/gift-card.js +49 -0
  37. package/dist/enums/index.d.ts +52 -0
  38. package/dist/enums/index.d.ts.map +1 -0
  39. package/dist/enums/index.js +52 -0
  40. package/dist/react/GiftCard.d.ts +1318 -0
  41. package/dist/react/GiftCard.d.ts.map +1 -0
  42. package/dist/react/GiftCard.js +1126 -0
  43. package/dist/react/core/GiftCard.d.ts +863 -0
  44. package/dist/react/core/GiftCard.d.ts.map +1 -0
  45. package/dist/react/core/GiftCard.js +737 -0
  46. package/dist/react/index.d.ts +2 -0
  47. package/dist/react/index.d.ts.map +1 -0
  48. package/dist/react/index.js +1 -0
  49. package/dist/services/gift-card-checkout-service.d.ts +133 -0
  50. package/dist/services/gift-card-checkout-service.d.ts.map +1 -0
  51. package/dist/services/gift-card-checkout-service.js +159 -0
  52. package/dist/services/gift-card-service.d.ts +102 -0
  53. package/dist/services/gift-card-service.d.ts.map +1 -0
  54. package/dist/services/gift-card-service.js +165 -0
  55. package/dist/services/index.d.ts +3 -0
  56. package/dist/services/index.d.ts.map +1 -0
  57. package/dist/services/index.js +2 -0
  58. package/dist/utils/formatting-utils.d.ts +13 -0
  59. package/dist/utils/formatting-utils.d.ts.map +1 -0
  60. package/dist/utils/formatting-utils.js +38 -0
  61. package/dist/utils/gift-card-utils.d.ts +18 -0
  62. package/dist/utils/gift-card-utils.d.ts.map +1 -0
  63. package/dist/utils/gift-card-utils.js +118 -0
  64. package/dist/utils/validation-utils.d.ts +10 -0
  65. package/dist/utils/validation-utils.d.ts.map +1 -0
  66. package/dist/utils/validation-utils.js +24 -0
  67. package/package.json +72 -0
  68. package/react/package.json +4 -0
  69. package/services/package.json +4 -0
@@ -0,0 +1,2 @@
1
+ export * as GiftCard from './GiftCard.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ export * as GiftCard from './GiftCard.js';
@@ -0,0 +1,133 @@
1
+ import type { giftVoucherProducts } from '@wix/gift-vouchers';
2
+ import * as checkout from '@wix/auto_sdk_ecom_checkout';
3
+ import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
4
+ export type LineItem = checkout.LineItem;
5
+ /**
6
+ * Gift card catalog options for cart line items
7
+ */
8
+ export interface GiftCardCatalogOptions {
9
+ quantity: number;
10
+ currency: string;
11
+ variantId?: string;
12
+ customAmount?: number;
13
+ giftingInfo?: {
14
+ recipientInfo: {
15
+ firstName: string;
16
+ lastName: string;
17
+ email: string;
18
+ };
19
+ greetingMessage?: string;
20
+ deliverAt?: Date;
21
+ };
22
+ wixGiftCardsAppNewCatalog: true;
23
+ }
24
+ /**
25
+ * MultiCurrencyPrice type from the Wix Gift Vouchers API
26
+ */
27
+ export type MultiCurrencyPrice = giftVoucherProducts.MultiCurrencyPrice;
28
+ /**
29
+ * Current price data based on selected variant.
30
+ * Contains raw numeric amounts - use Money component for formatting.
31
+ */
32
+ export interface CurrentPriceData {
33
+ /** Price amount as number (what the customer pays) */
34
+ price: number;
35
+ /** Original value as number (what the gift card is worth) */
36
+ value: number;
37
+ /** Whether current selection has a discount (price < value) */
38
+ hasDiscount: boolean;
39
+ }
40
+ /**
41
+ * Custom amount input data for min/max validation
42
+ */
43
+ export interface CustomAmountData {
44
+ /** Minimum allowed custom amount */
45
+ min: number | null;
46
+ /** Maximum allowed custom amount */
47
+ max: number | null;
48
+ }
49
+ /**
50
+ * API interface for the GiftCardCheckout service.
51
+ * Manages variant selection state and computed values based on selection.
52
+ */
53
+ export interface GiftCardCheckoutServiceAPI {
54
+ /** Currently selected variant ID (preset variant _id or 'custom') */
55
+ selectedVariantId: Signal<string | null>;
56
+ /** Current image based on selection (selectedVariant.image ?? product.image) */
57
+ currentImage: ReadOnlySignal<string | null>;
58
+ /** Current price data based on selection (price, value, discount info) */
59
+ currentPriceData: ReadOnlySignal<CurrentPriceData | null>;
60
+ /** User-entered custom amount (defaults to 0) */
61
+ customAmount: Signal<number>;
62
+ /** Whether the custom amount is valid (within min/max range) */
63
+ isCustomAmountValid: ReadOnlySignal<boolean>;
64
+ /** Custom amount validation data (min/max values) */
65
+ customAmountData: ReadOnlySignal<CustomAmountData>;
66
+ /** Current quantity of gift cards to purchase (default: 1) */
67
+ quantity: Signal<number>;
68
+ /** Whether this is a gift purchase (for someone else) or self-purchase */
69
+ isGift: Signal<boolean>;
70
+ /** Recipient email address */
71
+ recipientEmail: Signal<string>;
72
+ /** Whether the recipient email is valid */
73
+ isRecipientEmailValid: ReadOnlySignal<boolean>;
74
+ /** Recipient name (optional) */
75
+ recipientName: Signal<string>;
76
+ /** Delivery date for the gift card (default: immediate delivery) */
77
+ deliverAt: Signal<Date>;
78
+ /** Personal message to include with the gift card (optional) */
79
+ recipientMessage: Signal<string>;
80
+ /** Whether to show validation errors (set to true after form submission attempt) */
81
+ showErrors: Signal<boolean>;
82
+ /** Whether the form is valid and can add to cart */
83
+ canAddToCart: ReadOnlySignal<boolean>;
84
+ /** Computed line items ready for cart API */
85
+ lineItems: ReadOnlySignal<LineItem[]>;
86
+ /** Set the selected variant by ID */
87
+ setVariant: (variantId: string | null) => void;
88
+ /** Set the custom amount value */
89
+ setCustomAmount: (amount: number) => void;
90
+ /** Set the quantity value */
91
+ setQuantity: (quantity: number) => void;
92
+ /** Set whether this is a gift purchase */
93
+ setIsGift: (value: boolean) => void;
94
+ /** Set the recipient email */
95
+ setRecipientEmail: (email: string) => void;
96
+ /** Set the recipient name */
97
+ setRecipientName: (name: string) => void;
98
+ /** Set the delivery date */
99
+ setDeliverAt: (date: Date) => void;
100
+ /** Set the recipient message */
101
+ setRecipientMessage: (message: string) => void;
102
+ /** Set whether to show validation errors */
103
+ setShowErrors: (show: boolean) => void;
104
+ /** Validates the form and triggers error display. */
105
+ validateAndShowErrors: () => boolean;
106
+ }
107
+ /**
108
+ * Service definition for the GiftCardCheckout service.
109
+ */
110
+ export declare const GiftCardCheckoutServiceDefinition: string & {
111
+ __api: GiftCardCheckoutServiceAPI;
112
+ __config: {};
113
+ isServiceDefinition?: boolean;
114
+ } & GiftCardCheckoutServiceAPI;
115
+ /**
116
+ * Configuration interface for the GiftCardCheckoutService.
117
+ * Currently empty, but can be extended for initial state.
118
+ */
119
+ export interface GiftCardCheckoutServiceConfig {
120
+ }
121
+ /**
122
+ * Implementation of the GiftCardCheckout service.
123
+ * Manages variant selection and provides computed values based on selection.
124
+ *
125
+ * Dependencies:
126
+ * - GiftCardServiceDefinition: to get product data
127
+ */
128
+ export declare const GiftCardCheckoutService: import("@wix/services-definitions").ServiceFactory<string & {
129
+ __api: GiftCardCheckoutServiceAPI;
130
+ __config: {};
131
+ isServiceDefinition?: boolean;
132
+ } & GiftCardCheckoutServiceAPI, GiftCardCheckoutServiceConfig>;
133
+ //# sourceMappingURL=gift-card-checkout-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gift-card-checkout-service.d.ts","sourceRoot":"","sources":["../../src/services/gift-card-checkout-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,QAAQ,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,cAAc,EACpB,MAAM,iDAAiD,CAAC;AAczD,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB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AE/C,4CAA4C;IAC5C,aAAa,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAEvC,qDAAqD;IACrD,qBAAqB,EAAE,MAAM,OAAO,CAAC;CACtC;AAED;;GAEG;AACH,eAAO,MAAM,iCAAiC;;;;8BACmB,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,6BAA6B;CAAG;AAEjD;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB;;;;8DAgNjC,CAAC"}
@@ -0,0 +1,159 @@
1
+ import { defineService, implementService } from '@wix/services-definitions';
2
+ import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
3
+ import { GiftCardServiceDefinition } from './gift-card-service.js';
4
+ import { getCurrentImage, getCurrentPriceData, getCustomAmountData, canAddToCartCheck, productToLineItems, } from '../utils/gift-card-utils.js';
5
+ import { validateCustomAmount, validateEmail, } from '../utils/validation-utils.js';
6
+ /**
7
+ * Service definition for the GiftCardCheckout service.
8
+ */
9
+ export const GiftCardCheckoutServiceDefinition = defineService('gift-card-checkout');
10
+ /**
11
+ * Implementation of the GiftCardCheckout service.
12
+ * Manages variant selection and provides computed values based on selection.
13
+ *
14
+ * Dependencies:
15
+ * - GiftCardServiceDefinition: to get product data
16
+ */
17
+ export const GiftCardCheckoutService = implementService.withConfig()(GiftCardCheckoutServiceDefinition, ({ getService }) => {
18
+ const signalsService = getService(SignalsServiceDefinition);
19
+ const giftCardService = getService(GiftCardServiceDefinition);
20
+ const getInitialVariantId = () => {
21
+ const product = giftCardService.product.get();
22
+ const firstVariant = product?.presetVariants?.[0];
23
+ return firstVariant?._id ?? null;
24
+ };
25
+ const selectedVariantId = signalsService.signal(getInitialVariantId());
26
+ const customAmount = signalsService.signal(undefined);
27
+ const quantity = signalsService.signal(1);
28
+ const isGift = signalsService.signal(true);
29
+ const recipientEmail = signalsService.signal('');
30
+ const recipientName = signalsService.signal('');
31
+ const deliverAt = signalsService.signal(new Date());
32
+ const recipientMessage = signalsService.signal('');
33
+ const showErrors = signalsService.signal(false);
34
+ const currentImage = signalsService.computed(() => {
35
+ const product = giftCardService.product.get();
36
+ const variantId = selectedVariantId.get();
37
+ return getCurrentImage(product, variantId);
38
+ });
39
+ const currentPriceData = signalsService.computed(() => {
40
+ const product = giftCardService.product.get();
41
+ const variantId = selectedVariantId.get();
42
+ const customAmountValue = customAmount.get();
43
+ return getCurrentPriceData(product, variantId, customAmountValue);
44
+ });
45
+ const customAmountData = signalsService.computed(() => {
46
+ const product = giftCardService.product.get();
47
+ return getCustomAmountData(product);
48
+ });
49
+ const isCustomAmountValid = signalsService.computed(() => {
50
+ const amount = customAmount.get();
51
+ const data = customAmountData.get();
52
+ return validateCustomAmount(amount, data);
53
+ });
54
+ const isRecipientEmailValid = signalsService.computed(() => {
55
+ const email = recipientEmail.get();
56
+ return validateEmail(email);
57
+ });
58
+ const canAddToCart = signalsService.computed(() => {
59
+ const product = giftCardService.product.get();
60
+ const variantId = selectedVariantId.get();
61
+ const isGiftPurchase = isGift.get();
62
+ const isCustomAmountValidCheck = isCustomAmountValid.get();
63
+ const isRecipientEmailValidCheck = isRecipientEmailValid.get();
64
+ return canAddToCartCheck(product, variantId, isGiftPurchase, isCustomAmountValidCheck, isRecipientEmailValidCheck);
65
+ });
66
+ const lineItems = signalsService.computed(() => {
67
+ const product = giftCardService.product.get();
68
+ const currency = giftCardService.currencyCode.get();
69
+ const variantId = selectedVariantId.get();
70
+ const customAmountValue = customAmount.get();
71
+ const qty = quantity.get();
72
+ const isGiftPurchase = isGift.get();
73
+ const recipientEmailValue = recipientEmail.get();
74
+ const recipientNameValue = recipientName.get();
75
+ const deliverAtValue = deliverAt.get();
76
+ const recipientMessageValue = recipientMessage.get();
77
+ return productToLineItems(product, currency, variantId, customAmountValue, qty, isGiftPurchase, recipientEmailValue, recipientNameValue, deliverAtValue, recipientMessageValue);
78
+ });
79
+ const validateAndShowErrors = () => {
80
+ setShowErrors(true);
81
+ return canAddToCart.get();
82
+ };
83
+ const setVariant = (variantId) => {
84
+ selectedVariantId.set(variantId);
85
+ };
86
+ const setCustomAmount = (amount) => {
87
+ customAmount.set(amount);
88
+ };
89
+ const setQuantity = (value) => {
90
+ if (value >= 1) {
91
+ quantity.set(value);
92
+ }
93
+ };
94
+ const setIsGift = (value) => {
95
+ isGift.set(value);
96
+ };
97
+ const setRecipientEmail = (email) => {
98
+ recipientEmail.set(email);
99
+ };
100
+ const setRecipientName = (name) => {
101
+ recipientName.set(name);
102
+ };
103
+ const setDeliverAt = (date) => {
104
+ deliverAt.set(date);
105
+ };
106
+ const setRecipientMessage = (message) => {
107
+ recipientMessage.set(message);
108
+ };
109
+ const setShowErrors = (show) => {
110
+ showErrors.set(show);
111
+ };
112
+ // Use effect to set initial variant when product loads (if not already set)
113
+ signalsService.effect(() => {
114
+ const loadedProduct = giftCardService.product.get();
115
+ if (loadedProduct && !selectedVariantId.get()) {
116
+ const firstVariant = loadedProduct.presetVariants?.[0];
117
+ if (firstVariant?._id) {
118
+ selectedVariantId.set(firstVariant._id);
119
+ }
120
+ }
121
+ });
122
+ // Use effect to set initial custom amount to min value when product loads
123
+ signalsService.effect(() => {
124
+ const loadedProduct = giftCardService.product.get();
125
+ const currentAmount = customAmount.get();
126
+ if (loadedProduct && currentAmount === undefined) {
127
+ const minValue = loadedProduct.customVariant?.minValue?.amount;
128
+ customAmount.set(minValue ? parseFloat(minValue) : 1);
129
+ }
130
+ });
131
+ return {
132
+ selectedVariantId,
133
+ currentImage,
134
+ currentPriceData,
135
+ customAmount,
136
+ isCustomAmountValid,
137
+ customAmountData,
138
+ quantity,
139
+ isGift,
140
+ recipientEmail,
141
+ isRecipientEmailValid,
142
+ recipientName,
143
+ deliverAt,
144
+ recipientMessage,
145
+ showErrors,
146
+ canAddToCart,
147
+ lineItems,
148
+ setVariant,
149
+ setCustomAmount,
150
+ setQuantity,
151
+ setIsGift,
152
+ setRecipientEmail,
153
+ setRecipientName,
154
+ setDeliverAt,
155
+ setRecipientMessage,
156
+ setShowErrors,
157
+ validateAndShowErrors,
158
+ };
159
+ });
@@ -0,0 +1,102 @@
1
+ import { giftVoucherProducts } from '@wix/gift-vouchers';
2
+ import { type Signal } from '@wix/services-definitions/core-services/signals';
3
+ /**
4
+ * Gift card product type from the Wix Gift Vouchers API
5
+ */
6
+ export type GiftCardProduct = giftVoucherProducts.GiftCardProduct;
7
+ /**
8
+ * API interface for the GiftCard service.
9
+ * Provides reactive gift card product data management.
10
+ */
11
+ export interface GiftCardServiceAPI {
12
+ /** Reactive signal containing the gift card product data */
13
+ product: Signal<GiftCardProduct | undefined>;
14
+ /** Reactive signal indicating if the product is currently being loaded */
15
+ isLoading: Signal<boolean>;
16
+ /** Reactive signal containing any error message, or null if no error */
17
+ error: Signal<string | null>;
18
+ /** Reactive signal containing the currency code (e.g., "EUR", "USD") */
19
+ currencyCode: Signal<string>;
20
+ /** Reactive signal containing the locale code (e.g., "en-US", "he-IL") */
21
+ locale: Signal<string>;
22
+ /** Function to load the gift card product */
23
+ loadProduct: () => Promise<void>;
24
+ }
25
+ /**
26
+ * Service definition for the GiftCard service.
27
+ */
28
+ export declare const GiftCardServiceDefinition: string & {
29
+ __api: GiftCardServiceAPI;
30
+ __config: {};
31
+ isServiceDefinition?: boolean;
32
+ } & GiftCardServiceAPI;
33
+ /**
34
+ * Configuration interface for the GiftCardService.
35
+ * Either provide a product directly (SSR) or leave undefined to auto-fetch.
36
+ */
37
+ export interface GiftCardServiceConfig {
38
+ /** The gift card product data (optional - if not provided, will be fetched) */
39
+ product?: GiftCardProduct;
40
+ /** ISO currency code (e.g., "EUR", "USD"). If not provided, resolved internally from site settings */
41
+ currencyCode?: string;
42
+ }
43
+ export declare const GiftCardService: import("@wix/services-definitions").ServiceFactory<string & {
44
+ __api: GiftCardServiceAPI;
45
+ __config: {};
46
+ isServiceDefinition?: boolean;
47
+ } & GiftCardServiceAPI, GiftCardServiceConfig>;
48
+ /**
49
+ * Success result interface for gift card service configuration loading.
50
+ */
51
+ export interface SuccessGiftCardServiceConfigResult {
52
+ type: 'success';
53
+ config: GiftCardServiceConfig;
54
+ }
55
+ /**
56
+ * Not found result interface for gift card service configuration loading.
57
+ */
58
+ export interface NotFoundGiftCardServiceConfigResult {
59
+ type: 'notFound';
60
+ }
61
+ /**
62
+ * Options for loading gift card service configuration.
63
+ */
64
+ export interface LoadGiftCardServiceConfigOptions {
65
+ /** ISO currency code (e.g., "EUR", "USD") to use for price formatting.
66
+ * If not provided, it will be fetched from site settings. */
67
+ currency?: string;
68
+ }
69
+ /**
70
+ * Loads gift card service configuration for SSR.
71
+ * Fetches the first gift card product from the API and optionally
72
+ * fetches the site currency from Wix site settings.
73
+ *
74
+ * @param options - Optional configuration for loading
75
+ * @returns Promise that resolves to GiftCardServiceConfigResult (success with config or notFound)
76
+ *
77
+ * @example
78
+ * ```astro
79
+ * ---
80
+ * import { loadGiftCardServiceConfig } from '@wix/headless-gift-voucher/services';
81
+ * import { GiftCard } from '@wix/headless-gift-voucher/react';
82
+ *
83
+ * // Option 1: Auto-fetch currency from site settings (default)
84
+ * const result = await loadGiftCardServiceConfig();
85
+ *
86
+ * // Option 2: Provide explicit currency (skips site settings fetch)
87
+ * const result = await loadGiftCardServiceConfig({
88
+ * currency: 'EUR'
89
+ * });
90
+ *
91
+ * if (result.type === 'notFound') {
92
+ * return Astro.redirect('/404');
93
+ * }
94
+ * ---
95
+ *
96
+ * <GiftCard.Root giftCardServiceConfig={result.config}>
97
+ * <GiftCard.Name />
98
+ * </GiftCard.Root>
99
+ * ```
100
+ */
101
+ export declare function loadGiftCardServiceConfig(options?: LoadGiftCardServiceConfigOptions): Promise<SuccessGiftCardServiceConfigResult | NotFoundGiftCardServiceConfigResult>;
102
+ //# sourceMappingURL=gift-card-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gift-card-service.d.ts","sourceRoot":"","sources":["../../src/services/gift-card-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD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CAAkC,GAAG,mCAAmC,CACzE,CAwBA"}
@@ -0,0 +1,165 @@
1
+ import { i18n } from '@wix/essentials';
2
+ import { giftVoucherProducts } from '@wix/gift-vouchers';
3
+ import { defineService, implementService } from '@wix/services-definitions';
4
+ import { ecommerceSettings } from '@wix/ecom';
5
+ import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
6
+ import { DEFAULT_CURRENCY_CODE, DEFAULT_LOCALE } from '../enums/index.js';
7
+ /**
8
+ * Service definition for the GiftCard service.
9
+ */
10
+ export const GiftCardServiceDefinition = defineService('gift-card');
11
+ /**
12
+ * Internal helper function to load the gift card product from the Wix API.
13
+ */
14
+ const loadGiftCardProduct = async () => {
15
+ const result = await giftVoucherProducts.queryGiftCardProducts().find();
16
+ return result?.items?.[0];
17
+ };
18
+ /**
19
+ * Implementation of the GiftCard service.
20
+ * Supports both SSR (config with product) and client-side (auto-fetch).
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * // With SSR config (product pre-loaded)
25
+ * <GiftCard.Root giftCardServiceConfig={{ product: myGiftCardProduct }}>
26
+ * <GiftCard.Name />
27
+ * </GiftCard.Root>
28
+ *
29
+ * // Without config (will auto-fetch)
30
+ * <GiftCard.Root giftCardServiceConfig={{}}>
31
+ * <GiftCard.Name />
32
+ * </GiftCard.Root>
33
+ * ```
34
+ */
35
+ /**
36
+ * Internal helper function to load the site currency from Wix site settings.
37
+ * @returns Promise that resolves to the site currency code (e.g., "USD", "EUR")
38
+ */
39
+ const loadSiteCurrency = async () => {
40
+ const settings = await ecommerceSettings.getEcommerceSettings([
41
+ 'BUSINESS_INFO',
42
+ ]);
43
+ return settings.ecommerceSettings?.businessInfo?.currency;
44
+ };
45
+ /**
46
+ * Internal helper function to get the locale from i18n service.
47
+ * @returns The locale code (e.g., "en-US", "he-IL")
48
+ */
49
+ const loadLocale = () => {
50
+ try {
51
+ return i18n.getLocale() ?? DEFAULT_LOCALE;
52
+ }
53
+ catch (e) {
54
+ console.warn('Failed to get locale, using default:', e);
55
+ return DEFAULT_LOCALE;
56
+ }
57
+ };
58
+ export const GiftCardService = implementService.withConfig()(GiftCardServiceDefinition, ({ getService, config }) => {
59
+ const signalsService = getService(SignalsServiceDefinition);
60
+ const product = signalsService.signal(config.product);
61
+ const currencyCode = signalsService.signal(config.currencyCode ?? '');
62
+ const locale = signalsService.signal(loadLocale());
63
+ const isLoading = signalsService.signal(!config.product || !config.currencyCode);
64
+ const error = signalsService.signal(null);
65
+ const loadCurrency = async () => {
66
+ isLoading.set(true);
67
+ error.set(null);
68
+ try {
69
+ const siteCurrency = await loadSiteCurrency();
70
+ currencyCode.set(siteCurrency);
71
+ }
72
+ catch (e) {
73
+ console.warn('Failed to load currency, using default:', e);
74
+ currencyCode.set(DEFAULT_CURRENCY_CODE);
75
+ }
76
+ isLoading.set(false);
77
+ };
78
+ const loadProduct = async () => {
79
+ isLoading.set(true);
80
+ error.set(null);
81
+ try {
82
+ const giftCardProduct = await loadGiftCardProduct();
83
+ if (!giftCardProduct) {
84
+ error.set('Gift card product not found');
85
+ }
86
+ else {
87
+ product.set(giftCardProduct);
88
+ }
89
+ }
90
+ catch (e) {
91
+ error.set(e instanceof Error ? e.message : 'Failed to load gift card');
92
+ }
93
+ isLoading.set(false);
94
+ };
95
+ if (!config.currencyCode) {
96
+ loadCurrency();
97
+ }
98
+ if (!config.product) {
99
+ loadProduct();
100
+ }
101
+ return {
102
+ product,
103
+ isLoading,
104
+ error,
105
+ currencyCode,
106
+ locale,
107
+ loadProduct,
108
+ };
109
+ });
110
+ /**
111
+ * Loads gift card service configuration for SSR.
112
+ * Fetches the first gift card product from the API and optionally
113
+ * fetches the site currency from Wix site settings.
114
+ *
115
+ * @param options - Optional configuration for loading
116
+ * @returns Promise that resolves to GiftCardServiceConfigResult (success with config or notFound)
117
+ *
118
+ * @example
119
+ * ```astro
120
+ * ---
121
+ * import { loadGiftCardServiceConfig } from '@wix/headless-gift-voucher/services';
122
+ * import { GiftCard } from '@wix/headless-gift-voucher/react';
123
+ *
124
+ * // Option 1: Auto-fetch currency from site settings (default)
125
+ * const result = await loadGiftCardServiceConfig();
126
+ *
127
+ * // Option 2: Provide explicit currency (skips site settings fetch)
128
+ * const result = await loadGiftCardServiceConfig({
129
+ * currency: 'EUR'
130
+ * });
131
+ *
132
+ * if (result.type === 'notFound') {
133
+ * return Astro.redirect('/404');
134
+ * }
135
+ * ---
136
+ *
137
+ * <GiftCard.Root giftCardServiceConfig={result.config}>
138
+ * <GiftCard.Name />
139
+ * </GiftCard.Root>
140
+ * ```
141
+ */
142
+ export async function loadGiftCardServiceConfig(options) {
143
+ try {
144
+ // Load product and optionally currency in parallel
145
+ // Currency is fetched from site settings only if not provided in options
146
+ const [giftCardProduct, siteCurrency] = await Promise.all([
147
+ loadGiftCardProduct(),
148
+ options?.currency ? Promise.resolve(undefined) : loadSiteCurrency(),
149
+ ]);
150
+ if (!giftCardProduct) {
151
+ return { type: 'notFound' };
152
+ }
153
+ return {
154
+ type: 'success',
155
+ config: {
156
+ product: giftCardProduct,
157
+ currencyCode: options?.currency ?? siteCurrency,
158
+ },
159
+ };
160
+ }
161
+ catch (error) {
162
+ console.error('Failed to load gift card product:', error);
163
+ return { type: 'notFound' };
164
+ }
165
+ }
@@ -0,0 +1,3 @@
1
+ export { GiftCardService, GiftCardServiceDefinition, type GiftCardServiceConfig, type GiftCardServiceAPI, type GiftCardProduct, loadGiftCardServiceConfig, type LoadGiftCardServiceConfigOptions, } from './gift-card-service.js';
2
+ export { GiftCardCheckoutService, GiftCardCheckoutServiceDefinition, type GiftCardCheckoutServiceConfig, type GiftCardCheckoutServiceAPI, type CurrentPriceData, type MultiCurrencyPrice, type CustomAmountData, type LineItem, type GiftCardCatalogOptions, } from './gift-card-checkout-service.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,yBAAyB,EACzB,KAAK,gCAAgC,GACtC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,uBAAuB,EACvB,iCAAiC,EACjC,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,sBAAsB,GAC5B,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { GiftCardService, GiftCardServiceDefinition, loadGiftCardServiceConfig, } from './gift-card-service.js';
2
+ export { GiftCardCheckoutService, GiftCardCheckoutServiceDefinition, } from './gift-card-checkout-service.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Get currency symbol from currency code using Intl.NumberFormat
3
+ */
4
+ export declare function getCurrencySymbol(currencyCode: string): string;
5
+ /**
6
+ * Formats a date according to the given locale.
7
+ */
8
+ export declare function formatDate(date: Date, locale: string): string;
9
+ /**
10
+ * Formats a date for HTML date input (YYYY-MM-DD).
11
+ */
12
+ export declare function formatDateForInput(date: Date): string;
13
+ //# sourceMappingURL=formatting-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting-utils.d.ts","sourceRoot":"","sources":["../../src/utils/formatting-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAc9D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAKrD"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Get currency symbol from currency code using Intl.NumberFormat
3
+ */
4
+ export function getCurrencySymbol(currencyCode) {
5
+ try {
6
+ // the locale does not matter for the narrowSymbol
7
+ const formatter = new Intl.NumberFormat('en', {
8
+ style: 'currency',
9
+ currency: currencyCode,
10
+ currencyDisplay: 'narrowSymbol',
11
+ });
12
+ const parts = formatter.formatToParts(0);
13
+ const symbolPart = parts.find((part) => part.type === 'currency');
14
+ return symbolPart?.value ?? currencyCode;
15
+ }
16
+ catch {
17
+ return currencyCode;
18
+ }
19
+ }
20
+ /**
21
+ * Formats a date according to the given locale.
22
+ */
23
+ export function formatDate(date, locale) {
24
+ return date.toLocaleDateString(locale, {
25
+ year: 'numeric',
26
+ month: 'short',
27
+ day: 'numeric',
28
+ });
29
+ }
30
+ /**
31
+ * Formats a date for HTML date input (YYYY-MM-DD).
32
+ */
33
+ export function formatDateForInput(date) {
34
+ const year = date.getFullYear();
35
+ const month = String(date.getMonth() + 1).padStart(2, '0');
36
+ const day = String(date.getDate()).padStart(2, '0');
37
+ return `${year}-${month}-${day}`;
38
+ }
@@ -0,0 +1,18 @@
1
+ import { CurrentPriceData, CustomAmountData, LineItem } from '../services/gift-card-checkout-service.js';
2
+ import { GiftCardProduct } from '../services/gift-card-service.js';
3
+ export declare function getCurrentImage(product: GiftCardProduct | undefined, selectedVariantId: string | null): string | null;
4
+ /**
5
+ * Gets the current price data based on the selected variant.
6
+ * Returns raw numeric amounts - use Money component for formatting.
7
+ */
8
+ export declare function getCurrentPriceData(product: GiftCardProduct | undefined, selectedVariantId: string | null, customAmount: number): CurrentPriceData | null;
9
+ /**
10
+ * Gets the min/max values for custom amount validation from the product.
11
+ */
12
+ export declare function getCustomAmountData(product: GiftCardProduct | undefined): CustomAmountData;
13
+ export declare function canAddToCartCheck(product: GiftCardProduct | undefined, variantId: string | null, isGiftPurchase: boolean, isCustomAmountValidCheck: boolean, isRecipientEmailValidCheck: boolean): boolean;
14
+ /**
15
+ * Converts the product data to line items for the cart API.
16
+ */
17
+ export declare function productToLineItems(product: GiftCardProduct | undefined, currency: string, variantId: string | null, customAmount: number, qty: number, isGiftPurchase: boolean, recipientEmail: string, recipientName: string, deliverAt: Date, recipientMessage: string): LineItem[];
18
+ //# sourceMappingURL=gift-card-utils.d.ts.map