@nextblock-cms/ecom 0.8.0 → 0.8.6
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/AddToCartButton-DsSEH9yp.cjs +1 -0
- package/AddToCartButton-ffE0DhHu.js +59 -0
- package/CouponForm-BI_5SBHQ.js +152 -0
- package/CouponForm-D_uu2bLP.cjs +1 -0
- package/CurrencyProvider-Cg-Q6ucj.cjs +1 -0
- package/CurrencyProvider-OzlRN96V.js +120 -0
- package/CurrencyProvider.cjs.js +1 -0
- package/CurrencyProvider.es.js +10 -0
- package/ProductDetailsLayout-BxJH_BxR.cjs +1 -0
- package/ProductDetailsLayout-Dg8dRTYp.js +530 -0
- package/ProductGrid-BdL7iglO.cjs +1 -0
- package/ProductGrid-D3AWM8sr.js +130 -0
- package/actions-AHmBrS5e.cjs +48 -0
- package/actions-j5fuSZX-.js +820 -0
- package/cart-store.cjs.js +1 -0
- package/cart-store.es.js +116 -0
- package/components/Cart.cjs.js +1 -0
- package/components/Cart.es.js +259 -0
- package/components/CartDrawer.cjs.js +1 -0
- package/components/CartDrawer.es.js +118 -0
- package/components/CartIcon.cjs.js +1 -0
- package/components/CartIcon.es.js +33 -0
- package/components/Checkout.cjs.js +1 -0
- package/components/Checkout.es.js +1020 -0
- package/components/CurrencySwitcher.cjs.js +1 -0
- package/components/CurrencySwitcher.es.js +17 -0
- package/components/FeaturedProduct.cjs.js +1 -0
- package/components/FeaturedProduct.es.js +71 -0
- package/components/ProductDetailsLayout.cjs.js +1 -0
- package/components/ProductDetailsLayout.es.js +19 -0
- package/components/ProductGrid.cjs.js +1 -0
- package/components/ProductGrid.es.js +6 -0
- package/components/SimpleTiptapRenderer.cjs.js +1 -0
- package/components/SimpleTiptapRenderer.es.js +187 -0
- package/coupon-server-C9ySm3I5.cjs +1 -0
- package/coupon-server-DUKVtyYs.js +248 -0
- package/currency-constants.cjs.js +1 -0
- package/currency-constants.es.js +4 -0
- package/currency.cjs.js +1 -0
- package/currency.es.js +312 -0
- package/customer-C-UPvrYN.cjs +1 -0
- package/customer-C3xccjUg.js +57 -0
- package/index.cjs.js +1 -1
- package/index.es.js +414 -3105
- package/invoice-ui-CAnJPu6n.cjs +29 -0
- package/invoice-ui-DtpbTJE1.js +2886 -0
- package/package.json +10 -5
- package/product-actions-CONBF8i6.cjs +251 -0
- package/product-actions-DjlIWCMH.js +691 -0
- package/resolver-Fz_FKsfX.cjs +7 -0
- package/resolver-cfrCaHpE.js +128 -0
- package/server-actions/product-actions.cjs.js +1 -0
- package/server-actions/product-actions.es.js +15 -0
- package/server.cjs.js +27 -27
- package/server.es.js +478 -463
- package/shipping-actions-BnHjlo2q.js +25 -0
- package/shipping-actions-D6zt20gg.cjs +1 -0
- package/states-CWYRxV4B.cjs +1 -0
- package/states-DlHJezQ1.js +200 -0
- package/tax-calculation-Dab89aHd.js +181 -0
- package/tax-calculation-MkDKOEkL.cjs +1 -0
- package/trials-DvZaOtNy.cjs +1 -0
- package/trials-RDcRAZKx.js +29 -0
- package/types.cjs.js +1 -0
- package/types.es.js +33 -0
- package/use-cart.cjs.js +1 -0
- package/use-cart.es.js +43 -0
- package/variation-utils.cjs.js +1 -0
- package/variation-utils.es.js +246 -0
- package/invoice-ui-BJZfedDd.cjs +0 -332
- package/invoice-ui-GJ1ADAjn.js +0 -5759
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { r as t } from "./resolver-cfrCaHpE.js";
|
|
2
|
+
import { n, b as c } from "./states-DlHJezQ1.js";
|
|
3
|
+
async function l(o, e, s, i) {
|
|
4
|
+
try {
|
|
5
|
+
const r = n(e.country);
|
|
6
|
+
return r ? { success: !0, methods: await t(o, {
|
|
7
|
+
...e,
|
|
8
|
+
country: r,
|
|
9
|
+
state: c(r, e.state) || void 0
|
|
10
|
+
}, s, i) } : {
|
|
11
|
+
success: !1,
|
|
12
|
+
error: "Country is required for shipping calculation",
|
|
13
|
+
errorKey: "ecommerce.shipping_country_required"
|
|
14
|
+
};
|
|
15
|
+
} catch (r) {
|
|
16
|
+
return console.error("Failed to resolve shipping options:", r), {
|
|
17
|
+
success: !1,
|
|
18
|
+
error: r.message || "Failed to calculate shipping",
|
|
19
|
+
errorKey: "ecommerce.shipping_calculation_failed"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
l as g
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const c=require("./resolver-Fz_FKsfX.cjs"),s=require("./states-CWYRxV4B.cjs");async function n(o,r,i,t){try{const e=s.normalizeCountryCode(r.country);return e?{success:!0,methods:await c.resolveShippingOptions(o,{...r,country:e,state:s.normalizeSubdivisionCode(e,r.state)||void 0},i,t)}:{success:!1,error:"Country is required for shipping calculation",errorKey:"ecommerce.shipping_country_required"}}catch(e){return console.error("Failed to resolve shipping options:",e),{success:!1,error:e.message||"Failed to calculate shipping",errorKey:"ecommerce.shipping_calculation_failed"}}}exports.getShippingEstimates=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const r=[{code:"US",name:"United States"},{code:"CA",name:"Canada"},{code:"GB",name:"United Kingdom"},{code:"AU",name:"Australia"},{code:"NZ",name:"New Zealand"},{code:"IE",name:"Ireland"},{code:"FR",name:"France"},{code:"DE",name:"Germany"},{code:"IT",name:"Italy"},{code:"ES",name:"Spain"},{code:"MX",name:"Mexico"},{code:"BR",name:"Brazil"},{code:"AR",name:"Argentina"},{code:"CL",name:"Chile"},{code:"CO",name:"Colombia"},{code:"PE",name:"Peru"},{code:"ZA",name:"South Africa"},{code:"NG",name:"Nigeria"},{code:"KE",name:"Kenya"},{code:"IN",name:"India"},{code:"JP",name:"Japan"},{code:"KR",name:"South Korea"},{code:"CN",name:"China"},{code:"SG",name:"Singapore"},{code:"MY",name:"Malaysia"},{code:"PH",name:"Philippines"},{code:"TH",name:"Thailand"},{code:"VN",name:"Vietnam"},{code:"ID",name:"Indonesia"},{code:"AE",name:"United Arab Emirates"},{code:"SA",name:"Saudi Arabia"},{code:"EG",name:"Egypt"},{code:"MA",name:"Morocco"},{code:"DZ",name:"Algeria"},{code:"TN",name:"Tunisia"},{code:"PT",name:"Portugal"},{code:"NL",name:"Netherlands"},{code:"BE",name:"Belgium"},{code:"CH",name:"Switzerland"},{code:"AT",name:"Austria"},{code:"SE",name:"Sweden"},{code:"NO",name:"Norway"},{code:"DK",name:"Denmark"},{code:"FI",name:"Finland"},{code:"PL",name:"Poland"},{code:"CZ",name:"Czech Republic"},{code:"HU",name:"Hungary"},{code:"RO",name:"Romania"},{code:"BG",name:"Bulgaria"},{code:"GR",name:"Greece"},{code:"TR",name:"Turkey"},{code:"IL",name:"Israel"},{code:"CY",name:"Cyprus"},{code:"MT",name:"Malta"}],S={USA:"US","UNITED STATES OF AMERICA":"US",UK:"GB","GREAT BRITAIN":"GB"};function i(n){const o=n?.trim();if(!o)return null;const e=o.toUpperCase(),a=S[e];if(a)return a;const d=r.find(m=>m.code===e);return d?d.code:r.find(m=>m.name.toUpperCase()===e)?.code??null}const I=[{code:"AL",name:"Alabama"},{code:"AK",name:"Alaska"},{code:"AZ",name:"Arizona"},{code:"AR",name:"Arkansas"},{code:"CA",name:"California"},{code:"CO",name:"Colorado"},{code:"CT",name:"Connecticut"},{code:"DE",name:"Delaware"},{code:"DC",name:"District of Columbia"},{code:"FL",name:"Florida"},{code:"GA",name:"Georgia"},{code:"HI",name:"Hawaii"},{code:"ID",name:"Idaho"},{code:"IL",name:"Illinois"},{code:"IN",name:"Indiana"},{code:"IA",name:"Iowa"},{code:"KS",name:"Kansas"},{code:"KY",name:"Kentucky"},{code:"LA",name:"Louisiana"},{code:"ME",name:"Maine"},{code:"MD",name:"Maryland"},{code:"MA",name:"Massachusetts"},{code:"MI",name:"Michigan"},{code:"MN",name:"Minnesota"},{code:"MS",name:"Mississippi"},{code:"MO",name:"Missouri"},{code:"MT",name:"Montana"},{code:"NE",name:"Nebraska"},{code:"NV",name:"Nevada"},{code:"NH",name:"New Hampshire"},{code:"NJ",name:"New Jersey"},{code:"NM",name:"New Mexico"},{code:"NY",name:"New York"},{code:"NC",name:"North Carolina"},{code:"ND",name:"North Dakota"},{code:"OH",name:"Ohio"},{code:"OK",name:"Oklahoma"},{code:"OR",name:"Oregon"},{code:"PA",name:"Pennsylvania"},{code:"RI",name:"Rhode Island"},{code:"SC",name:"South Carolina"},{code:"SD",name:"South Dakota"},{code:"TN",name:"Tennessee"},{code:"TX",name:"Texas"},{code:"UT",name:"Utah"},{code:"VT",name:"Vermont"},{code:"VA",name:"Virginia"},{code:"WA",name:"Washington"},{code:"WV",name:"West Virginia"},{code:"WI",name:"Wisconsin"},{code:"WY",name:"Wyoming"}],T=[{code:"AB",name:"Alberta"},{code:"BC",name:"British Columbia"},{code:"MB",name:"Manitoba"},{code:"NB",name:"New Brunswick"},{code:"NL",name:"Newfoundland and Labrador"},{code:"NS",name:"Nova Scotia"},{code:"NT",name:"Northwest Territories"},{code:"NU",name:"Nunavut"},{code:"ON",name:"Ontario"},{code:"PE",name:"Prince Edward Island"},{code:"QC",name:"Quebec"},{code:"SK",name:"Saskatchewan"},{code:"YT",name:"Yukon"}],s={US:I,CA:T},N={US:{CALIFORNIA:"CA",NEWYORK:"NY","NEW YORK":"NY",DISTRICTOFCOLUMBIA:"DC","DISTRICT OF COLUMBIA":"DC"},CA:{QUEBEC:"QC",ONTARIO:"ON","BRITISH COLUMBIA":"BC",BRITISHCOLUMBIA:"BC","NEWFOUNDLAND AND LABRADOR":"NL",NEWFOUNDLANDANDLABRADOR:"NL","NORTHWEST TERRITORIES":"NT",NORTHWESTTERRITORIES:"NT","PRINCE EDWARD ISLAND":"PE",PRINCEEDWARDISLAND:"PE"}};function l(n){const o=i(n);return o?s[o]??[]:[]}function R(n){return l(n).length>0}function A(n,o){const e=i(n),a=o?.trim();if(!e||!a)return a||null;const d=s[e];if(!d?.length)return a.toUpperCase();const c=a.toUpperCase(),m=d.find(t=>t.code===c);if(m)return m.code;const u=d.find(t=>t.name.toUpperCase()===c);if(u)return u.code;const C=c.replace(/\s+/g,"");return N[e]?.[c]??N[e]?.[C]??c}function E(n,o){const e=i(n),a=A(n,o);return!e||!a?o??null:s[e]?.find(c=>c.code===a)?.name??a}exports.countries=r;exports.countryUsesStructuredStates=R;exports.getStatesForCountry=l;exports.normalizeCountryCode=i;exports.normalizeSubdivisionCode=A;exports.resolveSubdivisionName=E;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
const N = [
|
|
2
|
+
{ code: "US", name: "United States" },
|
|
3
|
+
{ code: "CA", name: "Canada" },
|
|
4
|
+
{ code: "GB", name: "United Kingdom" },
|
|
5
|
+
{ code: "AU", name: "Australia" },
|
|
6
|
+
{ code: "NZ", name: "New Zealand" },
|
|
7
|
+
{ code: "IE", name: "Ireland" },
|
|
8
|
+
{ code: "FR", name: "France" },
|
|
9
|
+
{ code: "DE", name: "Germany" },
|
|
10
|
+
{ code: "IT", name: "Italy" },
|
|
11
|
+
{ code: "ES", name: "Spain" },
|
|
12
|
+
{ code: "MX", name: "Mexico" },
|
|
13
|
+
{ code: "BR", name: "Brazil" },
|
|
14
|
+
{ code: "AR", name: "Argentina" },
|
|
15
|
+
{ code: "CL", name: "Chile" },
|
|
16
|
+
{ code: "CO", name: "Colombia" },
|
|
17
|
+
{ code: "PE", name: "Peru" },
|
|
18
|
+
{ code: "ZA", name: "South Africa" },
|
|
19
|
+
{ code: "NG", name: "Nigeria" },
|
|
20
|
+
{ code: "KE", name: "Kenya" },
|
|
21
|
+
{ code: "IN", name: "India" },
|
|
22
|
+
{ code: "JP", name: "Japan" },
|
|
23
|
+
{ code: "KR", name: "South Korea" },
|
|
24
|
+
{ code: "CN", name: "China" },
|
|
25
|
+
{ code: "SG", name: "Singapore" },
|
|
26
|
+
{ code: "MY", name: "Malaysia" },
|
|
27
|
+
{ code: "PH", name: "Philippines" },
|
|
28
|
+
{ code: "TH", name: "Thailand" },
|
|
29
|
+
{ code: "VN", name: "Vietnam" },
|
|
30
|
+
{ code: "ID", name: "Indonesia" },
|
|
31
|
+
{ code: "AE", name: "United Arab Emirates" },
|
|
32
|
+
{ code: "SA", name: "Saudi Arabia" },
|
|
33
|
+
{ code: "EG", name: "Egypt" },
|
|
34
|
+
{ code: "MA", name: "Morocco" },
|
|
35
|
+
{ code: "DZ", name: "Algeria" },
|
|
36
|
+
{ code: "TN", name: "Tunisia" },
|
|
37
|
+
{ code: "PT", name: "Portugal" },
|
|
38
|
+
{ code: "NL", name: "Netherlands" },
|
|
39
|
+
{ code: "BE", name: "Belgium" },
|
|
40
|
+
{ code: "CH", name: "Switzerland" },
|
|
41
|
+
{ code: "AT", name: "Austria" },
|
|
42
|
+
{ code: "SE", name: "Sweden" },
|
|
43
|
+
{ code: "NO", name: "Norway" },
|
|
44
|
+
{ code: "DK", name: "Denmark" },
|
|
45
|
+
{ code: "FI", name: "Finland" },
|
|
46
|
+
{ code: "PL", name: "Poland" },
|
|
47
|
+
{ code: "CZ", name: "Czech Republic" },
|
|
48
|
+
{ code: "HU", name: "Hungary" },
|
|
49
|
+
{ code: "RO", name: "Romania" },
|
|
50
|
+
{ code: "BG", name: "Bulgaria" },
|
|
51
|
+
{ code: "GR", name: "Greece" },
|
|
52
|
+
{ code: "TR", name: "Turkey" },
|
|
53
|
+
{ code: "IL", name: "Israel" },
|
|
54
|
+
{ code: "CY", name: "Cyprus" },
|
|
55
|
+
{ code: "MT", name: "Malta" }
|
|
56
|
+
], l = {
|
|
57
|
+
USA: "US",
|
|
58
|
+
"UNITED STATES OF AMERICA": "US",
|
|
59
|
+
UK: "GB",
|
|
60
|
+
"GREAT BRITAIN": "GB"
|
|
61
|
+
};
|
|
62
|
+
function t(n) {
|
|
63
|
+
const o = n?.trim();
|
|
64
|
+
if (!o)
|
|
65
|
+
return null;
|
|
66
|
+
const e = o.toUpperCase(), a = l[e];
|
|
67
|
+
if (a)
|
|
68
|
+
return a;
|
|
69
|
+
const d = N.find((m) => m.code === e);
|
|
70
|
+
return d ? d.code : N.find(
|
|
71
|
+
(m) => m.name.toUpperCase() === e
|
|
72
|
+
)?.code ?? null;
|
|
73
|
+
}
|
|
74
|
+
const C = [
|
|
75
|
+
{ code: "AL", name: "Alabama" },
|
|
76
|
+
{ code: "AK", name: "Alaska" },
|
|
77
|
+
{ code: "AZ", name: "Arizona" },
|
|
78
|
+
{ code: "AR", name: "Arkansas" },
|
|
79
|
+
{ code: "CA", name: "California" },
|
|
80
|
+
{ code: "CO", name: "Colorado" },
|
|
81
|
+
{ code: "CT", name: "Connecticut" },
|
|
82
|
+
{ code: "DE", name: "Delaware" },
|
|
83
|
+
{ code: "DC", name: "District of Columbia" },
|
|
84
|
+
{ code: "FL", name: "Florida" },
|
|
85
|
+
{ code: "GA", name: "Georgia" },
|
|
86
|
+
{ code: "HI", name: "Hawaii" },
|
|
87
|
+
{ code: "ID", name: "Idaho" },
|
|
88
|
+
{ code: "IL", name: "Illinois" },
|
|
89
|
+
{ code: "IN", name: "Indiana" },
|
|
90
|
+
{ code: "IA", name: "Iowa" },
|
|
91
|
+
{ code: "KS", name: "Kansas" },
|
|
92
|
+
{ code: "KY", name: "Kentucky" },
|
|
93
|
+
{ code: "LA", name: "Louisiana" },
|
|
94
|
+
{ code: "ME", name: "Maine" },
|
|
95
|
+
{ code: "MD", name: "Maryland" },
|
|
96
|
+
{ code: "MA", name: "Massachusetts" },
|
|
97
|
+
{ code: "MI", name: "Michigan" },
|
|
98
|
+
{ code: "MN", name: "Minnesota" },
|
|
99
|
+
{ code: "MS", name: "Mississippi" },
|
|
100
|
+
{ code: "MO", name: "Missouri" },
|
|
101
|
+
{ code: "MT", name: "Montana" },
|
|
102
|
+
{ code: "NE", name: "Nebraska" },
|
|
103
|
+
{ code: "NV", name: "Nevada" },
|
|
104
|
+
{ code: "NH", name: "New Hampshire" },
|
|
105
|
+
{ code: "NJ", name: "New Jersey" },
|
|
106
|
+
{ code: "NM", name: "New Mexico" },
|
|
107
|
+
{ code: "NY", name: "New York" },
|
|
108
|
+
{ code: "NC", name: "North Carolina" },
|
|
109
|
+
{ code: "ND", name: "North Dakota" },
|
|
110
|
+
{ code: "OH", name: "Ohio" },
|
|
111
|
+
{ code: "OK", name: "Oklahoma" },
|
|
112
|
+
{ code: "OR", name: "Oregon" },
|
|
113
|
+
{ code: "PA", name: "Pennsylvania" },
|
|
114
|
+
{ code: "RI", name: "Rhode Island" },
|
|
115
|
+
{ code: "SC", name: "South Carolina" },
|
|
116
|
+
{ code: "SD", name: "South Dakota" },
|
|
117
|
+
{ code: "TN", name: "Tennessee" },
|
|
118
|
+
{ code: "TX", name: "Texas" },
|
|
119
|
+
{ code: "UT", name: "Utah" },
|
|
120
|
+
{ code: "VT", name: "Vermont" },
|
|
121
|
+
{ code: "VA", name: "Virginia" },
|
|
122
|
+
{ code: "WA", name: "Washington" },
|
|
123
|
+
{ code: "WV", name: "West Virginia" },
|
|
124
|
+
{ code: "WI", name: "Wisconsin" },
|
|
125
|
+
{ code: "WY", name: "Wyoming" }
|
|
126
|
+
], I = [
|
|
127
|
+
{ code: "AB", name: "Alberta" },
|
|
128
|
+
{ code: "BC", name: "British Columbia" },
|
|
129
|
+
{ code: "MB", name: "Manitoba" },
|
|
130
|
+
{ code: "NB", name: "New Brunswick" },
|
|
131
|
+
{ code: "NL", name: "Newfoundland and Labrador" },
|
|
132
|
+
{ code: "NS", name: "Nova Scotia" },
|
|
133
|
+
{ code: "NT", name: "Northwest Territories" },
|
|
134
|
+
{ code: "NU", name: "Nunavut" },
|
|
135
|
+
{ code: "ON", name: "Ontario" },
|
|
136
|
+
{ code: "PE", name: "Prince Edward Island" },
|
|
137
|
+
{ code: "QC", name: "Quebec" },
|
|
138
|
+
{ code: "SK", name: "Saskatchewan" },
|
|
139
|
+
{ code: "YT", name: "Yukon" }
|
|
140
|
+
], r = {
|
|
141
|
+
US: C,
|
|
142
|
+
CA: I
|
|
143
|
+
}, u = {
|
|
144
|
+
US: {
|
|
145
|
+
CALIFORNIA: "CA",
|
|
146
|
+
NEWYORK: "NY",
|
|
147
|
+
"NEW YORK": "NY",
|
|
148
|
+
DISTRICTOFCOLUMBIA: "DC",
|
|
149
|
+
"DISTRICT OF COLUMBIA": "DC"
|
|
150
|
+
},
|
|
151
|
+
CA: {
|
|
152
|
+
QUEBEC: "QC",
|
|
153
|
+
ONTARIO: "ON",
|
|
154
|
+
"BRITISH COLUMBIA": "BC",
|
|
155
|
+
BRITISHCOLUMBIA: "BC",
|
|
156
|
+
"NEWFOUNDLAND AND LABRADOR": "NL",
|
|
157
|
+
NEWFOUNDLANDANDLABRADOR: "NL",
|
|
158
|
+
"NORTHWEST TERRITORIES": "NT",
|
|
159
|
+
NORTHWESTTERRITORIES: "NT",
|
|
160
|
+
"PRINCE EDWARD ISLAND": "PE",
|
|
161
|
+
PRINCEEDWARDISLAND: "PE"
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
function S(n) {
|
|
165
|
+
const o = t(n);
|
|
166
|
+
return o ? r[o] ?? [] : [];
|
|
167
|
+
}
|
|
168
|
+
function E(n) {
|
|
169
|
+
return S(n).length > 0;
|
|
170
|
+
}
|
|
171
|
+
function T(n, o) {
|
|
172
|
+
const e = t(n), a = o?.trim();
|
|
173
|
+
if (!e || !a)
|
|
174
|
+
return a || null;
|
|
175
|
+
const d = r[e];
|
|
176
|
+
if (!d?.length)
|
|
177
|
+
return a.toUpperCase();
|
|
178
|
+
const c = a.toUpperCase(), m = d.find((i) => i.code === c);
|
|
179
|
+
if (m)
|
|
180
|
+
return m.code;
|
|
181
|
+
const s = d.find((i) => i.name.toUpperCase() === c);
|
|
182
|
+
if (s)
|
|
183
|
+
return s.code;
|
|
184
|
+
const A = c.replace(/\s+/g, "");
|
|
185
|
+
return u[e]?.[c] ?? u[e]?.[A] ?? c;
|
|
186
|
+
}
|
|
187
|
+
function M(n, o) {
|
|
188
|
+
const e = t(n), a = T(n, o);
|
|
189
|
+
return !e || !a ? o ?? null : r[e]?.find(
|
|
190
|
+
(c) => c.code === a
|
|
191
|
+
)?.name ?? a;
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
E as a,
|
|
195
|
+
T as b,
|
|
196
|
+
N as c,
|
|
197
|
+
S as g,
|
|
198
|
+
t as n,
|
|
199
|
+
M as r
|
|
200
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { n as y, b } from "./states-DlHJezQ1.js";
|
|
2
|
+
import { resolveEffectivePriceForCurrency as p } from "./currency.es.js";
|
|
3
|
+
import { g as C } from "./coupon-server-DUKVtyYs.js";
|
|
4
|
+
const x = "ecommerce_inventory_settings", c = {
|
|
5
|
+
trackQuantities: !0,
|
|
6
|
+
enableTaxes: !1,
|
|
7
|
+
taxCalculationMode: "manual"
|
|
8
|
+
};
|
|
9
|
+
function m(e, t = !0) {
|
|
10
|
+
if (typeof e == "boolean")
|
|
11
|
+
return e;
|
|
12
|
+
if (typeof e == "string") {
|
|
13
|
+
const r = e.trim().toLowerCase();
|
|
14
|
+
if (["true", "1", "yes", "on"].includes(r))
|
|
15
|
+
return !0;
|
|
16
|
+
if (["false", "0", "no", "off"].includes(r))
|
|
17
|
+
return !1;
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
}
|
|
21
|
+
function E(e, t = c.taxCalculationMode) {
|
|
22
|
+
return e === "automatic" ? "automatic" : e === "manual" ? "manual" : t;
|
|
23
|
+
}
|
|
24
|
+
function T(e) {
|
|
25
|
+
if (e && typeof e == "object" && !Array.isArray(e)) {
|
|
26
|
+
const t = e;
|
|
27
|
+
return {
|
|
28
|
+
trackQuantities: m(
|
|
29
|
+
t.trackQuantities ?? t.track_quantities,
|
|
30
|
+
c.trackQuantities
|
|
31
|
+
),
|
|
32
|
+
enableTaxes: m(
|
|
33
|
+
t.enableTaxes ?? t.enable_taxes,
|
|
34
|
+
c.enableTaxes
|
|
35
|
+
),
|
|
36
|
+
taxCalculationMode: E(
|
|
37
|
+
t.taxCalculationMode ?? t.tax_calculation_mode,
|
|
38
|
+
c.taxCalculationMode
|
|
39
|
+
)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
trackQuantities: m(
|
|
44
|
+
e,
|
|
45
|
+
c.trackQuantities
|
|
46
|
+
),
|
|
47
|
+
enableTaxes: c.enableTaxes,
|
|
48
|
+
taxCalculationMode: c.taxCalculationMode
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async function S(e) {
|
|
52
|
+
const { data: t, error: r } = await e.from("site_settings").select("value").eq("key", x).maybeSingle();
|
|
53
|
+
return r || !t ? c : T(t.value);
|
|
54
|
+
}
|
|
55
|
+
async function A(e, t) {
|
|
56
|
+
return e.from("site_settings").upsert({
|
|
57
|
+
key: x,
|
|
58
|
+
value: {
|
|
59
|
+
track_quantities: t.trackQuantities,
|
|
60
|
+
enable_taxes: t.enableTaxes,
|
|
61
|
+
tax_calculation_mode: t.taxCalculationMode
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function w(e) {
|
|
66
|
+
return {
|
|
67
|
+
error: `${e} is no longer available.`,
|
|
68
|
+
errorKey: "ecommerce.inventory_item_unavailable",
|
|
69
|
+
errorParams: { item: e },
|
|
70
|
+
errorStatus: 409
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function N(e, t) {
|
|
74
|
+
return {
|
|
75
|
+
error: `Only ${t} units remain for ${e}.`,
|
|
76
|
+
errorKey: "ecommerce.inventory_insufficient",
|
|
77
|
+
errorParams: { item: e, count: t },
|
|
78
|
+
errorStatus: 409
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const g = "txcd_99999999", M = "txcd_00000000", O = "txcd_92010001";
|
|
82
|
+
function v(e) {
|
|
83
|
+
return e ? g : M;
|
|
84
|
+
}
|
|
85
|
+
async function q(e, t, r, s, l) {
|
|
86
|
+
if (!t.length)
|
|
87
|
+
return [];
|
|
88
|
+
const d = [...new Set(t.map((o) => o.product_id))], { data: u, error: _ } = await e.from("products").select("id, is_taxable").in("id", d);
|
|
89
|
+
if (_)
|
|
90
|
+
throw new Error(_.message);
|
|
91
|
+
const f = new Map(
|
|
92
|
+
(u || []).map((o) => [o.id, o])
|
|
93
|
+
);
|
|
94
|
+
return t.reduce((o, a) => {
|
|
95
|
+
const n = f.get(a.product_id);
|
|
96
|
+
if (!n)
|
|
97
|
+
return o;
|
|
98
|
+
const i = p({
|
|
99
|
+
prices: a.prices,
|
|
100
|
+
salePrices: a.sale_prices,
|
|
101
|
+
fallbackPrice: a.price,
|
|
102
|
+
fallbackSalePrice: a.sale_price,
|
|
103
|
+
saleStartAt: a.sale_start_at,
|
|
104
|
+
saleEndAt: a.sale_end_at,
|
|
105
|
+
scheduledPrice: a.scheduled_price,
|
|
106
|
+
scheduledPrices: a.scheduled_prices,
|
|
107
|
+
scheduledPriceAt: a.scheduled_price_at,
|
|
108
|
+
currencyCode: r,
|
|
109
|
+
currencies: s
|
|
110
|
+
});
|
|
111
|
+
return o.push({
|
|
112
|
+
product_id: n.id,
|
|
113
|
+
quantity: a.quantity,
|
|
114
|
+
unit_amount: i.sale_price ?? i.price,
|
|
115
|
+
discount_amount: l?.get(C(a)) ?? 0,
|
|
116
|
+
is_taxable: n.is_taxable ?? !0
|
|
117
|
+
}), o;
|
|
118
|
+
}, []);
|
|
119
|
+
}
|
|
120
|
+
async function R(e, t) {
|
|
121
|
+
const r = await S(e), s = t.items.reduce((n, i) => i.is_taxable ? n + Math.max(0, i.unit_amount * i.quantity - (i.discount_amount ?? 0)) : n, 0);
|
|
122
|
+
if (!r.enableTaxes || s <= 0)
|
|
123
|
+
return {
|
|
124
|
+
enabled: !1,
|
|
125
|
+
mode: r.taxCalculationMode,
|
|
126
|
+
amount: 0,
|
|
127
|
+
taxableSubtotal: s,
|
|
128
|
+
lines: []
|
|
129
|
+
};
|
|
130
|
+
if (r.taxCalculationMode === "automatic")
|
|
131
|
+
return {
|
|
132
|
+
enabled: !0,
|
|
133
|
+
mode: "automatic",
|
|
134
|
+
amount: 0,
|
|
135
|
+
taxableSubtotal: s,
|
|
136
|
+
lines: [],
|
|
137
|
+
isPendingExternalCalculation: !0
|
|
138
|
+
};
|
|
139
|
+
const l = y(t.destination?.country_code), d = b(l, t.destination?.state) || null;
|
|
140
|
+
if (!l)
|
|
141
|
+
return {
|
|
142
|
+
enabled: !0,
|
|
143
|
+
mode: "manual",
|
|
144
|
+
amount: 0,
|
|
145
|
+
taxableSubtotal: s,
|
|
146
|
+
lines: []
|
|
147
|
+
};
|
|
148
|
+
let u = e.from("tax_rates").select("id, country_code, state_code, tax_name, tax_rate, created_at, updated_at").eq("country_code", l);
|
|
149
|
+
u = d ? u.or(`state_code.is.null,state_code.eq.${d}`) : u.is("state_code", null);
|
|
150
|
+
const { data: _, error: f } = await u;
|
|
151
|
+
if (f)
|
|
152
|
+
throw new Error(f.message);
|
|
153
|
+
const a = (_ || []).map((n) => ({
|
|
154
|
+
id: n.id,
|
|
155
|
+
name: n.tax_name,
|
|
156
|
+
rate: Number(n.tax_rate),
|
|
157
|
+
amount: Math.round(s * Number(n.tax_rate) / 100),
|
|
158
|
+
country_code: n.country_code,
|
|
159
|
+
state_code: n.state_code ?? null
|
|
160
|
+
}));
|
|
161
|
+
return {
|
|
162
|
+
enabled: !0,
|
|
163
|
+
mode: "manual",
|
|
164
|
+
amount: a.reduce((n, i) => n + i.amount, 0),
|
|
165
|
+
taxableSubtotal: s,
|
|
166
|
+
lines: a
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export {
|
|
170
|
+
x as E,
|
|
171
|
+
O as S,
|
|
172
|
+
w as a,
|
|
173
|
+
q as b,
|
|
174
|
+
R as c,
|
|
175
|
+
N as d,
|
|
176
|
+
M as e,
|
|
177
|
+
v as f,
|
|
178
|
+
S as g,
|
|
179
|
+
T as n,
|
|
180
|
+
A as u
|
|
181
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const x=require("./states-CWYRxV4B.cjs"),b=require("./currency.cjs.js"),p=require("./coupon-server-C9ySm3I5.cjs"),E="ecommerce_inventory_settings",s={trackQuantities:!0,enableTaxes:!1,taxCalculationMode:"manual"};function f(e,t=!0){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.trim().toLowerCase();if(["true","1","yes","on"].includes(n))return!0;if(["false","0","no","off"].includes(n))return!1}return t}function S(e,t=s.taxCalculationMode){return e==="automatic"?"automatic":e==="manual"?"manual":t}function y(e){if(e&&typeof e=="object"&&!Array.isArray(e)){const t=e;return{trackQuantities:f(t.trackQuantities??t.track_quantities,s.trackQuantities),enableTaxes:f(t.enableTaxes??t.enable_taxes,s.enableTaxes),taxCalculationMode:S(t.taxCalculationMode??t.tax_calculation_mode,s.taxCalculationMode)}}return{trackQuantities:f(e,s.trackQuantities),enableTaxes:s.enableTaxes,taxCalculationMode:s.taxCalculationMode}}async function C(e){const{data:t,error:n}=await e.from("site_settings").select("value").eq("key",E).maybeSingle();return n||!t?s:y(t.value)}async function g(e,t){return e.from("site_settings").upsert({key:E,value:{track_quantities:t.trackQuantities,enable_taxes:t.enableTaxes,tax_calculation_mode:t.taxCalculationMode}})}function P(e){return{error:`${e} is no longer available.`,errorKey:"ecommerce.inventory_item_unavailable",errorParams:{item:e},errorStatus:409}}function M(e,t){return{error:`Only ${t} units remain for ${e}.`,errorKey:"ecommerce.inventory_insufficient",errorParams:{item:e,count:t},errorStatus:409}}const k="txcd_99999999",T="txcd_00000000",v="txcd_92010001";function A(e){return e?k:T}async function I(e,t,n,c,l){if(!t.length)return[];const d=[...new Set(t.map(o=>o.product_id))],{data:u,error:_}=await e.from("products").select("id, is_taxable").in("id",d);if(_)throw new Error(_.message);const m=new Map((u||[]).map(o=>[o.id,o]));return t.reduce((o,r)=>{const a=m.get(r.product_id);if(!a)return o;const i=b.resolveEffectivePriceForCurrency({prices:r.prices,salePrices:r.sale_prices,fallbackPrice:r.price,fallbackSalePrice:r.sale_price,saleStartAt:r.sale_start_at,saleEndAt:r.sale_end_at,scheduledPrice:r.scheduled_price,scheduledPrices:r.scheduled_prices,scheduledPriceAt:r.scheduled_price_at,currencyCode:n,currencies:c});return o.push({product_id:a.id,quantity:r.quantity,unit_amount:i.sale_price??i.price,discount_amount:l?.get(p.getCartLineCouponKey(r))??0,is_taxable:a.is_taxable??!0}),o},[])}async function N(e,t){const n=await C(e),c=t.items.reduce((a,i)=>i.is_taxable?a+Math.max(0,i.unit_amount*i.quantity-(i.discount_amount??0)):a,0);if(!n.enableTaxes||c<=0)return{enabled:!1,mode:n.taxCalculationMode,amount:0,taxableSubtotal:c,lines:[]};if(n.taxCalculationMode==="automatic")return{enabled:!0,mode:"automatic",amount:0,taxableSubtotal:c,lines:[],isPendingExternalCalculation:!0};const l=x.normalizeCountryCode(t.destination?.country_code),d=x.normalizeSubdivisionCode(l,t.destination?.state)||null;if(!l)return{enabled:!0,mode:"manual",amount:0,taxableSubtotal:c,lines:[]};let u=e.from("tax_rates").select("id, country_code, state_code, tax_name, tax_rate, created_at, updated_at").eq("country_code",l);u=d?u.or(`state_code.is.null,state_code.eq.${d}`):u.is("state_code",null);const{data:_,error:m}=await u;if(m)throw new Error(m.message);const r=(_||[]).map(a=>({id:a.id,name:a.tax_name,rate:Number(a.tax_rate),amount:Math.round(c*Number(a.tax_rate)/100),country_code:a.country_code,state_code:a.state_code??null}));return{enabled:!0,mode:"manual",amount:r.reduce((a,i)=>a+i.amount,0),taxableSubtotal:c,lines:r}}exports.ECOMMERCE_INVENTORY_SETTINGS_KEY=E;exports.STRIPE_TAX_CODE_NONTAXABLE=T;exports.STRIPE_TAX_CODE_SHIPPING=v;exports.buildCheckoutTaxableItemsFromCart=I;exports.calculateCheckoutTaxes=N;exports.createInventoryInsufficientError=M;exports.createInventoryUnavailableError=P;exports.getEcommerceInventorySettings=C;exports.getStripeTaxCodeForProduct=A;exports.normalizeEcommerceInventorySettings=y;exports.upsertEcommerceInventorySettings=g;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function t(e){const r=Number(e?.trial_period_days??0);return!Number.isFinite(r)||r<=0?0:Math.round(r)}function i(e){return t(e)===0?null:e?.trial_requires_payment_method?"paid":"free"}function a(e){const r=t(typeof e=="number"?{trial_period_days:e}:e);return r>0?`${r}-day free trial`:null}function n(e){return e?.trial_requires_payment_method?"Payment method required":"No credit card required"}function l(e){const r=a(e);return r?{label:r,paymentRequirementLabel:n(e),checkoutMode:i(e)}:null}exports.getTrialCheckoutMode=i;exports.getTrialLabel=a;exports.getTrialPaymentRequirementLabel=n;exports.getTrialPeriodDays=t;exports.getTrialSummary=l;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function t(e) {
|
|
2
|
+
const r = Number(e?.trial_period_days ?? 0);
|
|
3
|
+
return !Number.isFinite(r) || r <= 0 ? 0 : Math.round(r);
|
|
4
|
+
}
|
|
5
|
+
function i(e) {
|
|
6
|
+
return t(e) === 0 ? null : e?.trial_requires_payment_method ? "paid" : "free";
|
|
7
|
+
}
|
|
8
|
+
function a(e) {
|
|
9
|
+
const r = t(typeof e == "number" ? { trial_period_days: e } : e);
|
|
10
|
+
return r > 0 ? `${r}-day free trial` : null;
|
|
11
|
+
}
|
|
12
|
+
function n(e) {
|
|
13
|
+
return e?.trial_requires_payment_method ? "Payment method required" : "No credit card required";
|
|
14
|
+
}
|
|
15
|
+
function o(e) {
|
|
16
|
+
const r = a(e);
|
|
17
|
+
return r ? {
|
|
18
|
+
label: r,
|
|
19
|
+
paymentRequirementLabel: n(e),
|
|
20
|
+
checkoutMode: i(e)
|
|
21
|
+
} : null;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
a,
|
|
25
|
+
n as b,
|
|
26
|
+
t as c,
|
|
27
|
+
o as d,
|
|
28
|
+
i as g
|
|
29
|
+
};
|
package/types.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={stripe:!1,freemius:!1};function d(r){if(!r||typeof r!="object"||Array.isArray(r))return{...t};const e=r;return{stripe:e.stripe===!0,freemius:e.freemius===!0}}function i(r){return r==="digital"?"freemius":"stripe"}function n(r){return r?"provider"in r&&r.provider?r.provider:r.payment_provider?r.payment_provider:r.product_type?i(r.product_type):"freemius_product_id"in r&&r.freemius_product_id?"freemius":null:null}function o(r){return n(r)==="freemius"}function u(r){return o(r)}exports.DEFAULT_ENABLED_PAYMENT_PROVIDERS=t;exports.derivePaymentProviderFromProductType=i;exports.getProductPaymentProvider=n;exports.isDigitalItem=u;exports.isDigitalProduct=o;exports.normalizeEnabledPaymentProviders=d;
|
package/types.es.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const i = {
|
|
2
|
+
stripe: !1,
|
|
3
|
+
freemius: !1
|
|
4
|
+
};
|
|
5
|
+
function u(r) {
|
|
6
|
+
if (!r || typeof r != "object" || Array.isArray(r))
|
|
7
|
+
return { ...i };
|
|
8
|
+
const e = r;
|
|
9
|
+
return {
|
|
10
|
+
stripe: e.stripe === !0,
|
|
11
|
+
freemius: e.freemius === !0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function t(r) {
|
|
15
|
+
return r === "digital" ? "freemius" : "stripe";
|
|
16
|
+
}
|
|
17
|
+
function n(r) {
|
|
18
|
+
return r ? "provider" in r && r.provider ? r.provider : r.payment_provider ? r.payment_provider : r.product_type ? t(r.product_type) : "freemius_product_id" in r && r.freemius_product_id ? "freemius" : null : null;
|
|
19
|
+
}
|
|
20
|
+
function o(r) {
|
|
21
|
+
return n(r) === "freemius";
|
|
22
|
+
}
|
|
23
|
+
function d(r) {
|
|
24
|
+
return o(r);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
i as DEFAULT_ENABLED_PAYMENT_PROVIDERS,
|
|
28
|
+
t as derivePaymentProviderFromProductType,
|
|
29
|
+
n as getProductPaymentProvider,
|
|
30
|
+
d as isDigitalItem,
|
|
31
|
+
o as isDigitalProduct,
|
|
32
|
+
u as normalizeEnabledPaymentProviders
|
|
33
|
+
};
|
package/use-cart.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),a=require("./cart-store.cjs.js");let s=null;function i(){return a.useCartStore.persist}function o(){return i()?.hasHydrated?.()??!1}function d(){if(typeof window>"u")return Promise.resolve();const e=i();return!e||e.hasHydrated()?Promise.resolve():(s||(s=Promise.resolve().then(()=>e.rehydrate()).finally(()=>{s=null})),s)}const l=e=>{const t=a.useCartStore(e),[u,r]=n.useState(!1);return n.useEffect(()=>{const c=i();if(o()){r(!0);return}const f=c?.onFinishHydration(()=>r(!0));return d(),()=>{f?.()}},[]),u?t:void 0},y=()=>{const[e,t]=n.useState(!1);return n.useEffect(()=>{const r=i()?.onFinishHydration(()=>t(!0));return t(o()),o()||d(),()=>{r?.()}},[]),e};exports.useCart=l;exports.useIsCartHydrated=y;
|
package/use-cart.es.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState as u, useEffect as a } from "react";
|
|
2
|
+
import { useCartStore as d } from "./cart-store.es.js";
|
|
3
|
+
let s = null;
|
|
4
|
+
function n() {
|
|
5
|
+
return d.persist;
|
|
6
|
+
}
|
|
7
|
+
function i() {
|
|
8
|
+
return n()?.hasHydrated?.() ?? !1;
|
|
9
|
+
}
|
|
10
|
+
function f() {
|
|
11
|
+
if (typeof window > "u")
|
|
12
|
+
return Promise.resolve();
|
|
13
|
+
const t = n();
|
|
14
|
+
return !t || t.hasHydrated() ? Promise.resolve() : (s || (s = Promise.resolve().then(() => t.rehydrate()).finally(() => {
|
|
15
|
+
s = null;
|
|
16
|
+
})), s);
|
|
17
|
+
}
|
|
18
|
+
const m = (t) => {
|
|
19
|
+
const r = d(t), [o, e] = u(!1);
|
|
20
|
+
return a(() => {
|
|
21
|
+
const c = n();
|
|
22
|
+
if (i()) {
|
|
23
|
+
e(!0);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const l = c?.onFinishHydration(() => e(!0));
|
|
27
|
+
return f(), () => {
|
|
28
|
+
l?.();
|
|
29
|
+
};
|
|
30
|
+
}, []), o ? r : void 0;
|
|
31
|
+
}, H = () => {
|
|
32
|
+
const [t, r] = u(!1);
|
|
33
|
+
return a(() => {
|
|
34
|
+
const e = n()?.onFinishHydration(() => r(!0));
|
|
35
|
+
return r(i()), i() || f(), () => {
|
|
36
|
+
e?.();
|
|
37
|
+
};
|
|
38
|
+
}, []), t;
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
m as useCart,
|
|
42
|
+
H as useIsCartHydrated
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./currency.cjs.js");function f(e){return!e||typeof e!="object"||Array.isArray(e)?null:Object.entries(e).reduce((r,[n,t])=>(typeof t=="string"&&t.trim()&&(r[n]=t.trim()),r),{})}function p(e,r,n){return!n||!r?e:r[n]?.trim()||e}function k(e,r){return p(e.name,e.name_translations,r)}function E(e,r){return p(e.value,e.value_translations,r)}function V(e){return e?e.startsWith("http")?e:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}`:e:null}function I(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}function A(e){return[...e].sort().join("__")}function S(e){return e.map(r=>r.term_value).join(" / ")}function P(e){return e.length===0?[]:e.reduce((r,n)=>r.flatMap(t=>n.map(s=>[...t,s])),[[]])}function B(e){const{baseSku:r,basePrice:n,basePrices:t={},baseSalePrice:s=null,baseSalePrices:i={},selectedAttributes:o,previousVariants:c=[]}=e;if(o.length===0||o.some(l=>l.terms.length===0))return[];const u=new Map(c.map(l=>[l.combination_key,l])),a=o.map(l=>l.terms.map(d=>({attribute_id:l.attribute_id,attribute_name:l.attribute_name,term:d})));return P(a).map(l=>{const d=l.map(({attribute_id:m,attribute_name:M,term:g})=>({attribute_id:m,attribute_name:M,term_id:g.id,term_value:g.value,term_slug:g.slug})),T=d.map(m=>m.term_id),h=A(T),_=u.get(h),y=d.map(m=>(m.term_slug?m.term_slug:I(m.term_value)).toUpperCase()).filter(Boolean).join("-");return{id:_?.id,combination_key:h,sku:_?.sku||[r.trim(),y].filter(Boolean).join("-"),upc:_?.upc??null,price:_?.price??n,prices:_?.prices??b.normalizePriceMap(t),sale_price:_?.sale_price??s,sale_prices:_?.sale_prices??b.normalizeSalePriceMap(i),sale_start_at:_?.sale_start_at??null,sale_end_at:_?.sale_end_at??null,stock_quantity:_?.stock_quantity??0,main_media_id:_?.main_media_id??null,main_image_url:_?.main_image_url??null,attribute_term_ids:T,selected_options:d,label:S(d)}})}function R(e){const r={};for(const n of e)for(const t of n.selected_options??[]){const s=new Set(r[t.attribute_id]??[]);s.add(t.term_id),r[t.attribute_id]=[...s]}return r}function U(e,r){const n=Object.values(r).filter(Boolean);return n.length===0?null:e.find(t=>t.attribute_term_ids.length===n.length&&n.every(s=>t.attribute_term_ids.includes(s)))??null}function v(e,r,n){const t=new Set;for(const s of e){if(!Object.entries(n).every(([c,u])=>!u||c===r?!0:s.attribute_term_ids.includes(u)))continue;const o=s.selected_options.find(c=>c.attribute_id===r);o&&t.add(o.term_id)}return t}function j(e,r){const n=r.find(t=>t.stock_quantity>0)??r[0]??null;return n?n.selected_options.reduce((t,s)=>(t[s.attribute_id]=s.term_id,t),{}):e.reduce((t,s)=>{const i=s.terms[0];return i&&(t[s.id]=i.id),t},{})}function z(e,r,n){const t={...n};for(const s of e){const i=v(r,s.id,t);if(i.size===0){delete t[s.id];continue}const o=t[s.id];if(o&&i.has(o))continue;const c=s.terms.find(u=>i.has(u.id));c&&(t[s.id]=c.id)}return t}function L(e=[],r){const n=new Map,t=e.map(i=>{const o=(i.variant_attribute_mapping||[]).map(u=>{const a=u.product_attribute_terms,l=a?.product_attributes;if(!a||!l)return null;const d=n.get(l.id)||{id:l.id,name:p(l.name,f(l.name_translations),r),slug:l.slug,name_translations:f(l.name_translations),terms:[],_termIds:new Set};return d._termIds.has(a.id)||(d.terms.push({id:a.id,attribute_id:a.attribute_id,value:p(a.value,f(a.value_translations),r),slug:a.slug,sort_order:a.sort_order??null,value_translations:f(a.value_translations)}),d._termIds.add(a.id)),n.set(l.id,d),{attribute_id:l.id,attribute_name:p(l.name,f(l.name_translations),r),term_id:a.id,term_value:p(a.value,f(a.value_translations),r),term_slug:a.slug}}).filter(u=>u!==null).sort((u,a)=>u.attribute_name.localeCompare(a.attribute_name)),c=o.map(u=>u.term_id);return{id:i.id,combination_key:A(c),sku:i.sku,upc:i.upc??null,price:i.price??0,prices:b.normalizePriceMap(i.prices),sale_price:i.sale_price??null,sale_prices:b.normalizeSalePriceMap(i.sale_prices),sale_start_at:i.sale_start_at??null,sale_end_at:i.sale_end_at??null,scheduled_price:i.scheduled_price??null,scheduled_prices:b.normalizePriceMap(i.scheduled_prices),scheduled_price_at:i.scheduled_price_at??null,stock_quantity:i.stock_quantity??0,main_media_id:i.main_media_id??null,image_url:V(i.media?.file_path??i.media?.object_key??null),attribute_term_ids:c,selected_options:o,label:S(o)}});return{attributes:[...n.values()].map(i=>({id:i.id,name:i.name,slug:i.slug,name_translations:i.name_translations,terms:[...i.terms].sort((o,c)=>{const u=o.sort_order??Number.MAX_SAFE_INTEGER,a=c.sort_order??Number.MAX_SAFE_INTEGER;return u!==a?u-a:o.value.localeCompare(c.value)})})).sort((i,o)=>i.name.localeCompare(o.name)),variants:t}}function N(e,r){if(!e.length)return null;const n=e.map(t=>b.isSaleWindowActive({saleStartAt:t.sale_start_at,saleEndAt:t.sale_end_at,now:r})&&typeof t.sale_price=="number"?t.sale_price:t.price);return{min:Math.min(...n),max:Math.max(...n)}}exports.buildCombinationKey=A;exports.buildVariantLabel=S;exports.chooseInitialVariantSelections=j;exports.extractSelectedTermsByAttribute=R;exports.findMatchingVariant=U;exports.generateVariantDrafts=B;exports.getAvailableTermIdsForAttribute=v;exports.getVariantEffectivePriceRange=N;exports.mapRawVariantRelations=L;exports.normalizeSelectionsToAvailableVariants=z;exports.resolveAttributeName=k;exports.resolveTermValue=E;exports.resolveTranslatedText=p;
|