@storepecker/storefront-core 2.9.1 → 2.10.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 (91) hide show
  1. package/dist/address-BdIB6IuI.d.cts +42 -0
  2. package/dist/address-BdIB6IuI.d.ts +42 -0
  3. package/dist/api/index.cjs +36 -32
  4. package/dist/api/index.d.cts +20 -17
  5. package/dist/api/index.d.ts +20 -17
  6. package/dist/api/index.js +4 -4
  7. package/dist/{buy-now-BqVWXyy8.d.cts → buy-now-CDug6LJ_.d.ts} +2 -2
  8. package/dist/{buy-now-DFdnuLjO.d.ts → buy-now-DrKY5_9R.d.cts} +2 -2
  9. package/dist/checkout/index.cjs +163 -76
  10. package/dist/checkout/index.d.cts +37 -26
  11. package/dist/checkout/index.d.ts +37 -26
  12. package/dist/checkout/index.js +50 -64
  13. package/dist/checkout-totals-CbmXM9L7.d.cts +220 -0
  14. package/dist/checkout-totals-DU8l-Wyb.d.ts +220 -0
  15. package/dist/{chunk-IG4BW3ZB.cjs → chunk-32X4SWN4.cjs} +3 -3
  16. package/dist/{chunk-NQZ5GUOG.cjs → chunk-3YPE6UPC.cjs} +24 -16
  17. package/dist/{chunk-RDUT4W3B.cjs → chunk-6APRQ2ED.cjs} +4 -1
  18. package/dist/{chunk-ICKTXS6B.js → chunk-6IXTFZFS.js} +3 -3
  19. package/dist/{chunk-7M5CVYZJ.js → chunk-A7EI7XLU.js} +8 -1
  20. package/dist/chunk-DZPK7GPG.js +601 -0
  21. package/dist/{chunk-TH7OAMGC.js → chunk-E4D4XOAE.js} +24 -16
  22. package/dist/{chunk-NRPK5GCJ.cjs → chunk-EFYAFXIS.cjs} +3 -3
  23. package/dist/{chunk-CBKJ3Y2I.js → chunk-EWZ7TGI7.js} +11 -1
  24. package/dist/{chunk-5XVHYPOC.js → chunk-FF5N7PTB.js} +1 -1
  25. package/dist/{chunk-NOT6VKXA.cjs → chunk-H6UZTS5O.cjs} +67 -23
  26. package/dist/{chunk-XFOUNOKO.cjs → chunk-KNG4OMS5.cjs} +8 -0
  27. package/dist/{chunk-ZAWZ3RB6.js → chunk-NNE42NMP.js} +1 -1
  28. package/dist/chunk-PN6KH5PX.cjs +661 -0
  29. package/dist/{chunk-QQHQTBAM.js → chunk-QSRVMOXT.js} +48 -6
  30. package/dist/{chunk-W6BDMNSU.js → chunk-QVO56X4E.js} +1 -1
  31. package/dist/{chunk-6LS5F4R3.cjs → chunk-SGJUMI3M.cjs} +11 -0
  32. package/dist/{chunk-YLLAP3H2.cjs → chunk-SGKLMS7W.cjs} +2 -2
  33. package/dist/{chunk-ZGMLOLTC.js → chunk-VRZRV2BR.js} +4 -1
  34. package/dist/{chunk-IVKJJLG7.cjs → chunk-WWJAPKRQ.cjs} +8 -8
  35. package/dist/{collections-CXgOv5_G.d.cts → collections-CKNFcE2d.d.cts} +1 -1
  36. package/dist/{collections-CNh2OGbl.d.ts → collections-CtRKsWVx.d.ts} +1 -1
  37. package/dist/components/address-form.cjs +6 -6
  38. package/dist/components/address-form.d.cts +10 -6
  39. package/dist/components/address-form.d.ts +10 -6
  40. package/dist/components/address-form.js +5 -5
  41. package/dist/components/digital-product-download-modal.d.cts +2 -2
  42. package/dist/components/digital-product-download-modal.d.ts +2 -2
  43. package/dist/components/index.cjs +8 -8
  44. package/dist/components/index.d.cts +6 -7
  45. package/dist/components/index.d.ts +6 -7
  46. package/dist/components/index.js +6 -6
  47. package/dist/components/search-dropdown.d.cts +4 -4
  48. package/dist/components/search-dropdown.d.ts +4 -4
  49. package/dist/components/share-button.cjs +3 -3
  50. package/dist/components/share-button.d.cts +1 -1
  51. package/dist/components/share-button.d.ts +1 -1
  52. package/dist/components/share-button.js +2 -2
  53. package/dist/components/theme-data-initializer.d.cts +4 -5
  54. package/dist/components/theme-data-initializer.d.ts +4 -5
  55. package/dist/hooks/index.cjs +672 -44
  56. package/dist/hooks/index.d.cts +239 -13
  57. package/dist/hooks/index.d.ts +239 -13
  58. package/dist/hooks/index.js +630 -11
  59. package/dist/{instagram-DalreBu6.d.cts → instagram-CSzrxk10.d.cts} +8 -2
  60. package/dist/{instagram-BADLnNQ3.d.ts → instagram-CagTLmyq.d.ts} +8 -2
  61. package/dist/models/index.d.cts +8 -8
  62. package/dist/models/index.d.ts +8 -8
  63. package/dist/orders-B6BmHCJN.d.ts +337 -0
  64. package/dist/orders-ZKP0lqRN.d.cts +337 -0
  65. package/dist/pincode-8u7yWLpQ.d.cts +29 -0
  66. package/dist/pincode-8u7yWLpQ.d.ts +29 -0
  67. package/dist/{pixelEvents-LsealscG.d.ts → pixelEvents-DqJ_CEEr.d.ts} +4 -4
  68. package/dist/{pixelEvents-BtEO5QAR.d.cts → pixelEvents-bahgVW4_.d.cts} +4 -4
  69. package/dist/{product-D9liEtl4.d.cts → product-D4kol-Z-.d.cts} +26 -2
  70. package/dist/{product-D9liEtl4.d.ts → product-D4kol-Z-.d.ts} +26 -2
  71. package/dist/store/index.cjs +20 -30
  72. package/dist/store/index.d.cts +21 -7
  73. package/dist/store/index.d.ts +21 -7
  74. package/dist/store/index.js +9 -26
  75. package/dist/{useAddressForm-DGbEn91-.d.cts → useAddressForm-fMOb5Z-a.d.ts} +6 -1
  76. package/dist/{useAddressForm-cO3Au33k.d.ts → useAddressForm-wleIo78M.d.cts} +6 -1
  77. package/dist/utils/index.cjs +60 -56
  78. package/dist/utils/index.d.cts +24 -9
  79. package/dist/utils/index.d.ts +24 -9
  80. package/dist/utils/index.js +4 -4
  81. package/dist/{wishlist-Cj0sQxiY.d.ts → wishlist-L3fM5-ie.d.ts} +1 -1
  82. package/dist/{wishlist-BakHvIFN.d.cts → wishlist-_0x0r1jt.d.cts} +1 -1
  83. package/package.json +1 -1
  84. package/dist/address-DwBZHzbI.d.cts +0 -19
  85. package/dist/address-DwBZHzbI.d.ts +0 -19
  86. package/dist/cart-DZq1ZEnE.d.ts +0 -153
  87. package/dist/cart-DwMFBmpC.d.cts +0 -153
  88. package/dist/chunk-34Y7Y5FU.cjs +0 -246
  89. package/dist/chunk-VPTN4YXD.js +0 -232
  90. package/dist/orders-B3G4CyhH.d.cts +0 -166
  91. package/dist/orders-Bl-Slh72.d.ts +0 -166
@@ -1,49 +1,14 @@
1
- export { applyCheckoutCoupon, fetchAppliedCoupon, fetchAvailableCoupons, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, openRazorpayCheckout, processPayment, removeCheckoutCoupon } from '../chunk-VPTN4YXD.js';
2
- import '../chunk-7M5CVYZJ.js';
1
+ export { DEFAULT_ADDRESS_SCHEMA_MESSAGES, INVALID_PINCODE, NO_POSTAL_CODE, PINCODE_DEBOUNCE_MS, PINCODE_MIN_LENGTH, PINCODE_VALIDATION_UNAVAILABLE, applyCheckoutCoupon, buildAddressFormat, buildAddressSchema, calculateCartTotals, clearPincodeCache, fetchAppliedCoupon, fetchAvailableCoupons, findStateByName, findSubdivision, getAreaOptions, getCustomizationPrice, getPincodeError, getPostcodeHint, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, isValidNumber, joinAddressLines, loadAddressFormat, lowerLabel, normalizePostcode, openRazorpayCheckout, processPayment, removeCheckoutCoupon, sanitizePhoneInput, sanitizePincode, usableEmail, validatePincode } from '../chunk-DZPK7GPG.js';
2
+ import '../chunk-A7EI7XLU.js';
3
3
  import { pixelEvents } from '../chunk-VAU5OL72.js';
4
- import { checkPhonepePaymentStatusPublic, checkPhonepePaymentStatus, getPublicOrderDetailsByNumber, getOrderDetailsByNumber, getStripePaymentStatusPublic, getStripePaymentStatus, verifyTabbyPayment } from '../chunk-KCLVR6G5.js';
4
+ import { checkPhonepePaymentStatusPublic, checkPhonepePaymentStatus, getPublicOrderDetailsByNumber, getOrderDetailsByNumber, getStripePaymentStatusPublic, getStripePaymentStatus, verifyTabbyPayment, tabbyPaymentFailure, publicPhonepeOrderFailure, phonepePaymentFailure } from '../chunk-KCLVR6G5.js';
5
5
  export { IP_API_CACHE_KEY, addressFormInitialValues, addressValidationSchema, buildAddressPayload, buildSubmitPayload, clearAddressFormSession, decodeAddress, encodeAddress, isValidPhoneNumber, loadAddressFormFromSession, parseEditAddress, sanitizePhoneNumber, saveAddressFormToSession } from '../chunk-ELP23UGF.js';
6
+ import '../chunk-OSM73ETC.js';
6
7
  import '../chunk-3SYYP3XV.js';
7
8
  import '../chunk-WEMNXIRS.js';
8
9
  import '../chunk-BQ256JKN.js';
9
10
  import '../chunk-JQMLHRWL.js';
10
11
 
11
- // src/checkout/cart-calculations.ts
12
- function calculateCartTotals(cart) {
13
- if (!cart) {
14
- return {
15
- totalSellingAmount: 0,
16
- discountAmount: 0,
17
- isCartEmpty: true,
18
- allInclusiveTax: true,
19
- exclusiveTaxAmount: 0
20
- };
21
- }
22
- let totalSellingAmount = 0;
23
- let discountAmount = 0;
24
- let exclusiveTaxAmount = 0;
25
- let allInclusiveTax = true;
26
- cart.product_variants?.forEach((item) => {
27
- const quantity = cart.products_quantity[item.id] || 0;
28
- const actualPrice = Number(item.actual_price);
29
- const sellingPrice = Number(item.selling_price);
30
- const variant = item;
31
- totalSellingAmount += actualPrice ? actualPrice * quantity : sellingPrice * quantity;
32
- discountAmount += actualPrice ? (actualPrice - sellingPrice) * quantity : 0;
33
- if (!variant.is_tax_inclusive_price) {
34
- allInclusiveTax = false;
35
- exclusiveTaxAmount += Number(variant.total_tax_price || 0) * quantity;
36
- }
37
- });
38
- return {
39
- totalSellingAmount,
40
- discountAmount,
41
- isCartEmpty: !cart.product_variants?.length,
42
- allInclusiveTax,
43
- exclusiveTaxAmount
44
- };
45
- }
46
-
47
12
  // src/checkout/placement-error.ts
48
13
  function describePlacementError(error) {
49
14
  const code = error?.response?.data?.error_code || error?.response?.data?.code;
@@ -86,57 +51,73 @@ function describePlacementError(error) {
86
51
  }
87
52
 
88
53
  // src/checkout/payment-status.ts
54
+ async function reportPhonepeFailure(transactionId, order, isPublic) {
55
+ try {
56
+ if (isPublic) {
57
+ await publicPhonepeOrderFailure({ id: transactionId, status: "REJECTED" });
58
+ } else if (order) {
59
+ await phonepePaymentFailure({ order_id: order.id, phonepe_transaction_id: transactionId });
60
+ }
61
+ } catch {
62
+ }
63
+ }
64
+ function isStripePaid(data) {
65
+ return data?.payment_status === "paid" || data?.status === "complete" || data?.order_status === "paid" || data?.success === true;
66
+ }
67
+ function isTabbyPaid(data) {
68
+ return data?.order_status === "paid" || data?.order_status === "confirmed" || data?.order_status === "success" || data?.status === "paid";
69
+ }
89
70
  async function checkPhonepeReturnStatus(transactionId, callbacks, options) {
90
71
  try {
91
72
  const checkStatus = options?.isPublic ? checkPhonepePaymentStatusPublic : checkPhonepePaymentStatus;
92
73
  const response = await checkStatus(transactionId);
93
74
  if (response.data.success) {
94
75
  callbacks.onSuccess(void 0);
95
- } else {
96
- callbacks.onFailure();
76
+ return;
97
77
  }
98
78
  } catch {
99
- callbacks.onFailure();
100
79
  }
80
+ if (options?.reportFailure) await reportPhonepeFailure(transactionId, null, options.isPublic);
81
+ callbacks.onFailure();
101
82
  }
102
83
  async function checkPhonepeReturnStatusWithOrder(transactionId, orderNumber, callbacks, options) {
84
+ const checkStatus = options?.isPublic ? checkPhonepePaymentStatusPublic : checkPhonepePaymentStatus;
85
+ const getOrder = options?.isPublic ? getPublicOrderDetailsByNumber : getOrderDetailsByNumber;
86
+ let order = null;
103
87
  try {
104
- const checkStatus = options?.isPublic ? checkPhonepePaymentStatusPublic : checkPhonepePaymentStatus;
105
- const getOrder = options?.isPublic ? getPublicOrderDetailsByNumber : getOrderDetailsByNumber;
106
88
  const [paymentResponse, orderResponse] = await Promise.all([
107
89
  checkStatus(transactionId),
108
90
  getOrder(orderNumber)
109
91
  ]);
110
- const order = orderResponse.data;
92
+ order = orderResponse.data;
111
93
  callbacks.onOrderLoaded?.(order);
112
94
  if (paymentResponse.data.success) {
113
95
  pixelEvents.purchase(order);
114
96
  pixelEvents.checkoutCompleted(order);
115
97
  callbacks.onSuccess(order);
116
- } else {
117
- callbacks.onFailure();
98
+ return;
118
99
  }
119
100
  } catch {
120
- callbacks.onFailure();
121
101
  }
102
+ if (options?.reportFailure) await reportPhonepeFailure(transactionId, order, options.isPublic);
103
+ callbacks.onFailure();
122
104
  }
123
105
  async function checkStripeReturnStatus(sessionId, orderNumber, paymentLinkUrl, callbacks, options) {
124
106
  try {
125
107
  const getStatus = options?.isPublic ? getStripePaymentStatusPublic : getStripePaymentStatus;
126
- const response = await getStatus(sessionId, orderNumber, paymentLinkUrl);
127
- const data = response.data;
128
- if (data.payment_status === "paid" || data.status === "complete") {
129
- try {
130
- const getOrder = options?.isPublic ? getPublicOrderDetailsByNumber : getOrderDetailsByNumber;
131
- const orderResponse = await getOrder(orderNumber);
132
- const order = orderResponse.data;
133
- callbacks.onOrderLoaded?.(order);
108
+ const getOrder = options?.isPublic ? getPublicOrderDetailsByNumber : getOrderDetailsByNumber;
109
+ const [response, orderResponse] = await Promise.all([
110
+ getStatus(sessionId, orderNumber, paymentLinkUrl),
111
+ getOrder(orderNumber).catch(() => null)
112
+ ]);
113
+ const order = orderResponse?.data;
114
+ if (order) callbacks.onOrderLoaded?.(order);
115
+ if (isStripePaid(response.data)) {
116
+ if (order) {
134
117
  pixelEvents.purchase(order);
135
118
  pixelEvents.checkoutCompleted(order);
136
- callbacks.onSuccess(order);
137
- } catch {
138
- callbacks.onSuccess(void 0);
139
119
  }
120
+ callbacks.onSuccess(order ?? void 0);
140
121
  } else {
141
122
  callbacks.onFailure();
142
123
  }
@@ -145,6 +126,7 @@ async function checkStripeReturnStatus(sessionId, orderNumber, paymentLinkUrl, c
145
126
  }
146
127
  }
147
128
  async function checkTabbyReturnStatus(orderNumber, callbacks, options) {
129
+ let tabbyPaymentId = options?.paymentId || void 0;
148
130
  try {
149
131
  const getOrder = options?.isPublic ? getPublicOrderDetailsByNumber : getOrderDetailsByNumber;
150
132
  const [response, orderResponse] = await Promise.all([
@@ -153,18 +135,22 @@ async function checkTabbyReturnStatus(orderNumber, callbacks, options) {
153
135
  ]);
154
136
  const order = orderResponse?.data;
155
137
  if (order) callbacks.onOrderLoaded?.(order);
156
- if (response.data.order_status === "paid" || response.data.order_status === "confirmed" || response.data.status === "paid") {
138
+ if (isTabbyPaid(response.data)) {
157
139
  if (order) {
158
140
  pixelEvents.purchase(order);
159
141
  pixelEvents.checkoutCompleted(order);
160
142
  }
161
143
  callbacks.onSuccess(order ?? void 0);
162
- } else {
163
- callbacks.onFailure();
144
+ return;
164
145
  }
146
+ tabbyPaymentId = tabbyPaymentId || response.data.payment_id;
165
147
  } catch {
166
- callbacks.onFailure();
167
148
  }
149
+ if (options?.reportFailure && tabbyPaymentId) {
150
+ await tabbyPaymentFailure(tabbyPaymentId).catch(() => {
151
+ });
152
+ }
153
+ callbacks.onFailure();
168
154
  }
169
155
 
170
- export { calculateCartTotals, checkPhonepeReturnStatus, checkPhonepeReturnStatusWithOrder, checkStripeReturnStatus, checkTabbyReturnStatus, describePlacementError };
156
+ export { checkPhonepeReturnStatus, checkPhonepeReturnStatusWithOrder, checkStripeReturnStatus, checkTabbyReturnStatus, describePlacementError, isStripePaid, isTabbyPaid };
@@ -0,0 +1,220 @@
1
+ import * as Yup from 'yup';
2
+ import { P as Pincode } from './pincode-8u7yWLpQ.cjs';
3
+ import { C as Cart } from './orders-ZKP0lqRN.cjs';
4
+
5
+ /** The fields we keep from Google's payload — the rest would only bloat localStorage. */
6
+ type RawAddressData = {
7
+ fmt?: string;
8
+ require?: string;
9
+ zip?: string;
10
+ zip_name_type?: string;
11
+ state_name_type?: string;
12
+ locality_name_type?: string;
13
+ };
14
+ type AddressFormat = {
15
+ countryCode: string;
16
+ hasPostal: boolean;
17
+ /** False when the metadata couldn't load: we can't tell if the country uses postcodes. */
18
+ postalRequired: boolean;
19
+ postalLabel: string;
20
+ postalPattern: RegExp | null;
21
+ /**
22
+ * Block submission when the postcode doesn't match. Only true where the
23
+ * pattern is known to be reliable; elsewhere a mismatch is just a hint, so an
24
+ * outdated regex can't stop a real order.
25
+ */
26
+ postalStrict: boolean;
27
+ postalInputMode: "numeric" | "text";
28
+ postalMaxLength: number;
29
+ postalUppercase: boolean;
30
+ regionLabel: string;
31
+ cityLabel: string;
32
+ line1Label: string;
33
+ line2Label: string;
34
+ /** State before city (Japan, UAE); city first everywhere else. */
35
+ stateFirst: boolean;
36
+ };
37
+ /**
38
+ * Turns Google's raw data into a form format. `raw` is null when the metadata
39
+ * could not be loaded; the overrides plus generic labels still give a usable form.
40
+ */
41
+ declare function buildAddressFormat(countryCode: string, raw: RawAddressData | null): AddressFormat;
42
+ /** Fetches (or reads from cache) and builds the format. Throws if Google is unreachable. */
43
+ declare function loadAddressFormat(countryCode: string): Promise<AddressFormat>;
44
+ /**
45
+ * Strips special characters from a pincode/postal-code entry, keeping only
46
+ * letters, digits and single spaces. Programmatic values like "N/A" are set via
47
+ * `setFieldValue` (not through an input handler) and are therefore untouched.
48
+ */
49
+ declare function sanitizePincode(value: string): string;
50
+ /**
51
+ * Keeps letters, digits and single spaces, capped per country. Japan (no
52
+ * override, Google's pattern allows `100-0001`) and the US (ZIP+4) keep the hyphen.
53
+ */
54
+ declare function normalizePostcode(format: AddressFormat, value: string): string;
55
+ /** A non-blocking warning for countries without a strict pattern. */
56
+ declare function getPostcodeHint(format: AddressFormat, value: string, message?: (postalLabel: string) => string): string | undefined;
57
+ declare function findStateByName(states: CountryModel.State1[], name: string): CountryModel.State1 | undefined;
58
+ /** The backend has one street field, so the optional second line is folded into it. */
59
+ declare function joinAddressLines(line1: string, line2: string): string;
60
+ declare const usableEmail: (value: unknown) => string;
61
+ /** "Town / city" → "town / city", but "PIN code" and "ZIP code" keep their capitals. */
62
+ declare const lowerLabel: (label: string) => string;
63
+ /**
64
+ * Validation messages for `buildAddressSchema`. Label-dependent messages get
65
+ * the country's label already lower-cased (e.g. "PIN code", "town / city").
66
+ */
67
+ type AddressSchemaMessages = {
68
+ nameRequired: string;
69
+ emailInvalid: string;
70
+ emailRequired: string;
71
+ phoneRequired: string;
72
+ phoneInvalid: string;
73
+ countryRequired: string;
74
+ line1Required: (label: string) => string;
75
+ cityRequired: (label: string) => string;
76
+ stateRequired: (label: string) => string;
77
+ postalRequired: (label: string) => string;
78
+ postalInvalid: (label: string) => string;
79
+ };
80
+ declare const DEFAULT_ADDRESS_SCHEMA_MESSAGES: AddressSchemaMessages;
81
+ /**
82
+ * The schema follows the country: no postcode rule where there is no
83
+ * postcode, no state rule where the backend has no states, and a strict
84
+ * postcode pattern only where we trust it.
85
+ */
86
+ declare function buildAddressSchema(format: AddressFormat, { requireState, messages }: {
87
+ requireState: boolean;
88
+ messages?: Partial<AddressSchemaMessages>;
89
+ }): Yup.ObjectSchema<{
90
+ customer_name: string;
91
+ customer_email: string;
92
+ customer_phone: string;
93
+ country_obj: string;
94
+ address: string;
95
+ address_line_2: string | undefined;
96
+ city: string;
97
+ state_obj: Yup.Maybe<string | undefined>;
98
+ pincode: Yup.Maybe<string | undefined>;
99
+ }, Yup.AnyObject, {
100
+ customer_name: undefined;
101
+ customer_email: undefined;
102
+ customer_phone: undefined;
103
+ country_obj: undefined;
104
+ address: undefined;
105
+ address_line_2: undefined;
106
+ city: undefined;
107
+ state_obj: undefined;
108
+ pincode: undefined;
109
+ }, "">;
110
+
111
+ /**
112
+ * Server-side pincode validation (ported from theme-aspen / theme-oak).
113
+ *
114
+ * The merchant opts in (`pincode_validation_enabled` on theme_data). When it's
115
+ * on, the backend checks pincodes against a postal-code database and returns
116
+ * the district and state, which prefill the form. When it's off, there is no
117
+ * lookup and no prefill; the format check in the form's schema still applies.
118
+ *
119
+ * Checking the flag is the caller's job (`usePincodeLookup` takes it as an
120
+ * option and falls back to the `useThemeData` store); nothing here reads it.
121
+ */
122
+ /** Pincode isn't real; the customer must correct it. */
123
+ declare const INVALID_PINCODE = "INVALID_PINCODE";
124
+ /** Provider down / quota exhausted. Transient, so invite a retry. */
125
+ declare const PINCODE_VALIDATION_UNAVAILABLE = "PINCODE_VALIDATION_UNAVAILABLE";
126
+ /** Placeholder the address forms use for countries with no postal code. */
127
+ declare const NO_POSTAL_CODE = "N/A";
128
+ /** Wait for a pause before looking up: the endpoint allows 20 req/min per IP. */
129
+ declare const PINCODE_DEBOUNCE_MS = 600;
130
+ /** Don't look up a half-typed value (countries without a strict format). */
131
+ declare const PINCODE_MIN_LENGTH = 4;
132
+ /** Location data from a recognised pincode, for prefilling the address. */
133
+ interface PincodeMatch {
134
+ /** The district, from the response's `province`. This fills City/District. */
135
+ district: string;
136
+ /** A locality inside the district; smaller than `district`. */
137
+ city: string;
138
+ state: string;
139
+ state_code: string;
140
+ /** Areas sharing this pincode; offered as suggestions when there's more than one. */
141
+ localities: Pincode.Locality[];
142
+ }
143
+ /**
144
+ * `invalid`: the backend says the pincode doesn't exist; blocks saving.
145
+ * `unknown`: feature off, outage, throttle or network error. Fails open,
146
+ * because the server validates again on save.
147
+ */
148
+ type PincodeCheck = {
149
+ status: "valid";
150
+ match: PincodeMatch;
151
+ } | {
152
+ status: "invalid";
153
+ match: null;
154
+ } | {
155
+ status: "unknown";
156
+ match: null;
157
+ };
158
+ /**
159
+ * Validate a pincode against `GET /utils/pincode/`. Never throws. Only call it
160
+ * for stores with `pincode_validation_enabled`.
161
+ *
162
+ * @param pincode The value to check.
163
+ * @param countryCode ISO2 of the selected country.
164
+ */
165
+ declare function validatePincode(pincode: string, countryCode?: string): Promise<PincodeCheck>;
166
+ /**
167
+ * Pull a pincode error out of a rejected `POST|PATCH /store/customer_address/`.
168
+ * Returns null for anything else, so callers fall through to their own handling.
169
+ *
170
+ * @param invalidMessage The wording for "doesn't exist", in the country's own label.
171
+ */
172
+ declare function getPincodeError(error: unknown, invalidMessage: string): string | null;
173
+ /** Test helper: forget cached answers. */
174
+ declare function clearPincodeCache(): void;
175
+ /** The subdivision matching a lookup result, for the State dropdown. */
176
+ declare function findSubdivision(states: CountryModel.State1[], match: PincodeMatch): CountryModel.State1 | undefined;
177
+ /** Distinct locality names inside the district, when the pincode covers more than one. */
178
+ declare function getAreaOptions(match: PincodeMatch | null): string[];
179
+
180
+ /**
181
+ * A customization input's price. The cart sends `effective_price` (what the
182
+ * backend charged) next to `customization_price`; other endpoints send only
183
+ * `additional_price` or `customization_price`.
184
+ */
185
+ declare function getCustomizationPrice(input: Cart.CustomizationInput | null | undefined): number;
186
+ /** Anything cart-shaped: the server cart, `LocalCart`, a buy-now or public preview. */
187
+ type CartLike = Pick<Cart.Root, "product_variants" | "products_quantity" | "customization_inputs"> | null | undefined;
188
+ interface CheckoutTotals {
189
+ /** Pre-discount line total: `actual_price` where one is set, else `selling_price`, × quantity. */
190
+ subtotal: number;
191
+ /** (`actual_price` − `selling_price`) × quantity, summed across the lines. */
192
+ discountAmount: number;
193
+ /** Tax already inside the prices (`total_tax_price` is a line total). */
194
+ totalInclusiveTax: number;
195
+ /** Tax added on top of the prices. */
196
+ totalExclusiveTax: number;
197
+ /** Customization charges for the whole cart: each line's per-unit charge × its quantity. */
198
+ totalCustomizationPrice: number;
199
+ /** Per-unit customization charge of each variant, keyed by variant id. */
200
+ customizationTotalsByVariant: Record<number, number>;
201
+ /** Customization inputs grouped by the variant they belong to. */
202
+ groupedCustomizeInputs: Record<number, Cart.CustomizationInput[]>;
203
+ }
204
+ /**
205
+ * The line-level money maths every checkout shows. The cart, buy-now and public
206
+ * one-time payloads are key-compatible, so all three use this.
207
+ *
208
+ * Shipping, coupon discount, tax total and the grand total are deliberately NOT
209
+ * derived here: read them off the payload (`total_shipping`,
210
+ * `total_coupon_discount`, `total_tax_amount`, `total_amount`). The backend is
211
+ * the only thing allowed to decide what the customer is charged.
212
+ *
213
+ * @param cart The cart / preview payload being rendered.
214
+ * @param customizationOverride Inputs to price instead of the cart's own: an
215
+ * already-placed order carries its own copy, which
216
+ * is the authoritative one.
217
+ */
218
+ declare function calculateCartTotals(cart: CartLike, customizationOverride?: Cart.CustomizationInput[] | null): CheckoutTotals;
219
+
220
+ export { type AddressFormat as A, type CartLike as C, DEFAULT_ADDRESS_SCHEMA_MESSAGES as D, INVALID_PINCODE as I, NO_POSTAL_CODE as N, PINCODE_DEBOUNCE_MS as P, type RawAddressData as R, type AddressSchemaMessages as a, type CheckoutTotals as b, PINCODE_MIN_LENGTH as c, PINCODE_VALIDATION_UNAVAILABLE as d, type PincodeCheck as e, type PincodeMatch as f, buildAddressFormat as g, buildAddressSchema as h, calculateCartTotals as i, clearPincodeCache as j, findStateByName as k, findSubdivision as l, getAreaOptions as m, getCustomizationPrice as n, getPincodeError as o, getPostcodeHint as p, joinAddressLines as q, loadAddressFormat as r, lowerLabel as s, normalizePostcode as t, sanitizePincode as u, usableEmail as v, validatePincode as w };
@@ -0,0 +1,220 @@
1
+ import * as Yup from 'yup';
2
+ import { P as Pincode } from './pincode-8u7yWLpQ.js';
3
+ import { C as Cart } from './orders-B6BmHCJN.js';
4
+
5
+ /** The fields we keep from Google's payload — the rest would only bloat localStorage. */
6
+ type RawAddressData = {
7
+ fmt?: string;
8
+ require?: string;
9
+ zip?: string;
10
+ zip_name_type?: string;
11
+ state_name_type?: string;
12
+ locality_name_type?: string;
13
+ };
14
+ type AddressFormat = {
15
+ countryCode: string;
16
+ hasPostal: boolean;
17
+ /** False when the metadata couldn't load: we can't tell if the country uses postcodes. */
18
+ postalRequired: boolean;
19
+ postalLabel: string;
20
+ postalPattern: RegExp | null;
21
+ /**
22
+ * Block submission when the postcode doesn't match. Only true where the
23
+ * pattern is known to be reliable; elsewhere a mismatch is just a hint, so an
24
+ * outdated regex can't stop a real order.
25
+ */
26
+ postalStrict: boolean;
27
+ postalInputMode: "numeric" | "text";
28
+ postalMaxLength: number;
29
+ postalUppercase: boolean;
30
+ regionLabel: string;
31
+ cityLabel: string;
32
+ line1Label: string;
33
+ line2Label: string;
34
+ /** State before city (Japan, UAE); city first everywhere else. */
35
+ stateFirst: boolean;
36
+ };
37
+ /**
38
+ * Turns Google's raw data into a form format. `raw` is null when the metadata
39
+ * could not be loaded; the overrides plus generic labels still give a usable form.
40
+ */
41
+ declare function buildAddressFormat(countryCode: string, raw: RawAddressData | null): AddressFormat;
42
+ /** Fetches (or reads from cache) and builds the format. Throws if Google is unreachable. */
43
+ declare function loadAddressFormat(countryCode: string): Promise<AddressFormat>;
44
+ /**
45
+ * Strips special characters from a pincode/postal-code entry, keeping only
46
+ * letters, digits and single spaces. Programmatic values like "N/A" are set via
47
+ * `setFieldValue` (not through an input handler) and are therefore untouched.
48
+ */
49
+ declare function sanitizePincode(value: string): string;
50
+ /**
51
+ * Keeps letters, digits and single spaces, capped per country. Japan (no
52
+ * override, Google's pattern allows `100-0001`) and the US (ZIP+4) keep the hyphen.
53
+ */
54
+ declare function normalizePostcode(format: AddressFormat, value: string): string;
55
+ /** A non-blocking warning for countries without a strict pattern. */
56
+ declare function getPostcodeHint(format: AddressFormat, value: string, message?: (postalLabel: string) => string): string | undefined;
57
+ declare function findStateByName(states: CountryModel.State1[], name: string): CountryModel.State1 | undefined;
58
+ /** The backend has one street field, so the optional second line is folded into it. */
59
+ declare function joinAddressLines(line1: string, line2: string): string;
60
+ declare const usableEmail: (value: unknown) => string;
61
+ /** "Town / city" → "town / city", but "PIN code" and "ZIP code" keep their capitals. */
62
+ declare const lowerLabel: (label: string) => string;
63
+ /**
64
+ * Validation messages for `buildAddressSchema`. Label-dependent messages get
65
+ * the country's label already lower-cased (e.g. "PIN code", "town / city").
66
+ */
67
+ type AddressSchemaMessages = {
68
+ nameRequired: string;
69
+ emailInvalid: string;
70
+ emailRequired: string;
71
+ phoneRequired: string;
72
+ phoneInvalid: string;
73
+ countryRequired: string;
74
+ line1Required: (label: string) => string;
75
+ cityRequired: (label: string) => string;
76
+ stateRequired: (label: string) => string;
77
+ postalRequired: (label: string) => string;
78
+ postalInvalid: (label: string) => string;
79
+ };
80
+ declare const DEFAULT_ADDRESS_SCHEMA_MESSAGES: AddressSchemaMessages;
81
+ /**
82
+ * The schema follows the country: no postcode rule where there is no
83
+ * postcode, no state rule where the backend has no states, and a strict
84
+ * postcode pattern only where we trust it.
85
+ */
86
+ declare function buildAddressSchema(format: AddressFormat, { requireState, messages }: {
87
+ requireState: boolean;
88
+ messages?: Partial<AddressSchemaMessages>;
89
+ }): Yup.ObjectSchema<{
90
+ customer_name: string;
91
+ customer_email: string;
92
+ customer_phone: string;
93
+ country_obj: string;
94
+ address: string;
95
+ address_line_2: string | undefined;
96
+ city: string;
97
+ state_obj: Yup.Maybe<string | undefined>;
98
+ pincode: Yup.Maybe<string | undefined>;
99
+ }, Yup.AnyObject, {
100
+ customer_name: undefined;
101
+ customer_email: undefined;
102
+ customer_phone: undefined;
103
+ country_obj: undefined;
104
+ address: undefined;
105
+ address_line_2: undefined;
106
+ city: undefined;
107
+ state_obj: undefined;
108
+ pincode: undefined;
109
+ }, "">;
110
+
111
+ /**
112
+ * Server-side pincode validation (ported from theme-aspen / theme-oak).
113
+ *
114
+ * The merchant opts in (`pincode_validation_enabled` on theme_data). When it's
115
+ * on, the backend checks pincodes against a postal-code database and returns
116
+ * the district and state, which prefill the form. When it's off, there is no
117
+ * lookup and no prefill; the format check in the form's schema still applies.
118
+ *
119
+ * Checking the flag is the caller's job (`usePincodeLookup` takes it as an
120
+ * option and falls back to the `useThemeData` store); nothing here reads it.
121
+ */
122
+ /** Pincode isn't real; the customer must correct it. */
123
+ declare const INVALID_PINCODE = "INVALID_PINCODE";
124
+ /** Provider down / quota exhausted. Transient, so invite a retry. */
125
+ declare const PINCODE_VALIDATION_UNAVAILABLE = "PINCODE_VALIDATION_UNAVAILABLE";
126
+ /** Placeholder the address forms use for countries with no postal code. */
127
+ declare const NO_POSTAL_CODE = "N/A";
128
+ /** Wait for a pause before looking up: the endpoint allows 20 req/min per IP. */
129
+ declare const PINCODE_DEBOUNCE_MS = 600;
130
+ /** Don't look up a half-typed value (countries without a strict format). */
131
+ declare const PINCODE_MIN_LENGTH = 4;
132
+ /** Location data from a recognised pincode, for prefilling the address. */
133
+ interface PincodeMatch {
134
+ /** The district, from the response's `province`. This fills City/District. */
135
+ district: string;
136
+ /** A locality inside the district; smaller than `district`. */
137
+ city: string;
138
+ state: string;
139
+ state_code: string;
140
+ /** Areas sharing this pincode; offered as suggestions when there's more than one. */
141
+ localities: Pincode.Locality[];
142
+ }
143
+ /**
144
+ * `invalid`: the backend says the pincode doesn't exist; blocks saving.
145
+ * `unknown`: feature off, outage, throttle or network error. Fails open,
146
+ * because the server validates again on save.
147
+ */
148
+ type PincodeCheck = {
149
+ status: "valid";
150
+ match: PincodeMatch;
151
+ } | {
152
+ status: "invalid";
153
+ match: null;
154
+ } | {
155
+ status: "unknown";
156
+ match: null;
157
+ };
158
+ /**
159
+ * Validate a pincode against `GET /utils/pincode/`. Never throws. Only call it
160
+ * for stores with `pincode_validation_enabled`.
161
+ *
162
+ * @param pincode The value to check.
163
+ * @param countryCode ISO2 of the selected country.
164
+ */
165
+ declare function validatePincode(pincode: string, countryCode?: string): Promise<PincodeCheck>;
166
+ /**
167
+ * Pull a pincode error out of a rejected `POST|PATCH /store/customer_address/`.
168
+ * Returns null for anything else, so callers fall through to their own handling.
169
+ *
170
+ * @param invalidMessage The wording for "doesn't exist", in the country's own label.
171
+ */
172
+ declare function getPincodeError(error: unknown, invalidMessage: string): string | null;
173
+ /** Test helper: forget cached answers. */
174
+ declare function clearPincodeCache(): void;
175
+ /** The subdivision matching a lookup result, for the State dropdown. */
176
+ declare function findSubdivision(states: CountryModel.State1[], match: PincodeMatch): CountryModel.State1 | undefined;
177
+ /** Distinct locality names inside the district, when the pincode covers more than one. */
178
+ declare function getAreaOptions(match: PincodeMatch | null): string[];
179
+
180
+ /**
181
+ * A customization input's price. The cart sends `effective_price` (what the
182
+ * backend charged) next to `customization_price`; other endpoints send only
183
+ * `additional_price` or `customization_price`.
184
+ */
185
+ declare function getCustomizationPrice(input: Cart.CustomizationInput | null | undefined): number;
186
+ /** Anything cart-shaped: the server cart, `LocalCart`, a buy-now or public preview. */
187
+ type CartLike = Pick<Cart.Root, "product_variants" | "products_quantity" | "customization_inputs"> | null | undefined;
188
+ interface CheckoutTotals {
189
+ /** Pre-discount line total: `actual_price` where one is set, else `selling_price`, × quantity. */
190
+ subtotal: number;
191
+ /** (`actual_price` − `selling_price`) × quantity, summed across the lines. */
192
+ discountAmount: number;
193
+ /** Tax already inside the prices (`total_tax_price` is a line total). */
194
+ totalInclusiveTax: number;
195
+ /** Tax added on top of the prices. */
196
+ totalExclusiveTax: number;
197
+ /** Customization charges for the whole cart: each line's per-unit charge × its quantity. */
198
+ totalCustomizationPrice: number;
199
+ /** Per-unit customization charge of each variant, keyed by variant id. */
200
+ customizationTotalsByVariant: Record<number, number>;
201
+ /** Customization inputs grouped by the variant they belong to. */
202
+ groupedCustomizeInputs: Record<number, Cart.CustomizationInput[]>;
203
+ }
204
+ /**
205
+ * The line-level money maths every checkout shows. The cart, buy-now and public
206
+ * one-time payloads are key-compatible, so all three use this.
207
+ *
208
+ * Shipping, coupon discount, tax total and the grand total are deliberately NOT
209
+ * derived here: read them off the payload (`total_shipping`,
210
+ * `total_coupon_discount`, `total_tax_amount`, `total_amount`). The backend is
211
+ * the only thing allowed to decide what the customer is charged.
212
+ *
213
+ * @param cart The cart / preview payload being rendered.
214
+ * @param customizationOverride Inputs to price instead of the cart's own: an
215
+ * already-placed order carries its own copy, which
216
+ * is the authoritative one.
217
+ */
218
+ declare function calculateCartTotals(cart: CartLike, customizationOverride?: Cart.CustomizationInput[] | null): CheckoutTotals;
219
+
220
+ export { type AddressFormat as A, type CartLike as C, DEFAULT_ADDRESS_SCHEMA_MESSAGES as D, INVALID_PINCODE as I, NO_POSTAL_CODE as N, PINCODE_DEBOUNCE_MS as P, type RawAddressData as R, type AddressSchemaMessages as a, type CheckoutTotals as b, PINCODE_MIN_LENGTH as c, PINCODE_VALIDATION_UNAVAILABLE as d, type PincodeCheck as e, type PincodeMatch as f, buildAddressFormat as g, buildAddressSchema as h, calculateCartTotals as i, clearPincodeCache as j, findStateByName as k, findSubdivision as l, getAreaOptions as m, getCustomizationPrice as n, getPincodeError as o, getPostcodeHint as p, joinAddressLines as q, loadAddressFormat as r, lowerLabel as s, normalizePostcode as t, sanitizePincode as u, usableEmail as v, validatePincode as w };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk3YRSHPM6_cjs = require('./chunk-3YRSHPM6.cjs');
4
- var chunk6LS5F4R3_cjs = require('./chunk-6LS5F4R3.cjs');
4
+ var chunkSGJUMI3M_cjs = require('./chunk-SGJUMI3M.cjs');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
 
7
7
  var ShareButton = ({
@@ -10,8 +10,8 @@ var ShareButton = ({
10
10
  iconSize = 22
11
11
  }) => {
12
12
  const _handleShare = () => {
13
- chunk6LS5F4R3_cjs.shareLink(
14
- `Buy ${product.name} at ${chunk6LS5F4R3_cjs.convertToCurrency(
13
+ chunkSGJUMI3M_cjs.shareLink(
14
+ `Buy ${product.name} at ${chunkSGJUMI3M_cjs.convertToCurrency(
15
15
  Number(product.selling_price)
16
16
  )}`,
17
17
  product.name