@betterstore/react 0.2.37 → 0.2.38
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/CHANGELOG.md +6 -0
- package/dist/components/checkout-embed/checkout-form.d.ts +2 -1
- package/dist/components/checkout-embed/checkout-schema.d.ts +36 -16
- package/dist/components/checkout-embed/steps/shipping/form.d.ts +5 -1
- package/dist/components/checkout-embed/steps/shipping/providers/zasilkovna.d.ts +13 -0
- package/dist/components/checkout-embed/steps/shipping/shipping-option-wrapper.d.ts +9 -0
- package/dist/index.cjs.js +136 -68
- package/dist/index.mjs +136 -68
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,7 @@ interface CheckoutFormProps {
|
|
|
15
15
|
fonts?: StripeElementsOptions["fonts"];
|
|
16
16
|
locale?: StripeElementLocale;
|
|
17
17
|
setShippingCost: (cost: number) => void;
|
|
18
|
+
exchangeRate: number;
|
|
18
19
|
}
|
|
19
|
-
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }: CheckoutFormProps): React.JSX.Element;
|
|
20
|
+
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }: CheckoutFormProps): React.JSX.Element;
|
|
20
21
|
export {};
|
|
@@ -10,11 +10,13 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
10
10
|
state: z.ZodOptional<z.ZodString>;
|
|
11
11
|
zipCode: z.ZodString;
|
|
12
12
|
country: z.ZodString;
|
|
13
|
+
countryCode: z.ZodString;
|
|
13
14
|
}, "strip", z.ZodTypeAny, {
|
|
14
15
|
line1: string;
|
|
15
16
|
city: string;
|
|
16
17
|
zipCode: string;
|
|
17
18
|
country: string;
|
|
19
|
+
countryCode: string;
|
|
18
20
|
line2?: string | undefined;
|
|
19
21
|
state?: string | undefined;
|
|
20
22
|
}, {
|
|
@@ -22,6 +24,7 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
22
24
|
city: string;
|
|
23
25
|
zipCode: string;
|
|
24
26
|
country: string;
|
|
27
|
+
countryCode: string;
|
|
25
28
|
line2?: string | undefined;
|
|
26
29
|
state?: string | undefined;
|
|
27
30
|
}>;
|
|
@@ -36,6 +39,7 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
36
39
|
city: string;
|
|
37
40
|
zipCode: string;
|
|
38
41
|
country: string;
|
|
42
|
+
countryCode: string;
|
|
39
43
|
line2?: string | undefined;
|
|
40
44
|
state?: string | undefined;
|
|
41
45
|
};
|
|
@@ -50,6 +54,7 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
50
54
|
city: string;
|
|
51
55
|
zipCode: string;
|
|
52
56
|
country: string;
|
|
57
|
+
countryCode: string;
|
|
53
58
|
line2?: string | undefined;
|
|
54
59
|
state?: string | undefined;
|
|
55
60
|
};
|
|
@@ -58,19 +63,22 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
58
63
|
}>;
|
|
59
64
|
export declare const shippingMethodSchema: z.ZodObject<{
|
|
60
65
|
rateId: z.ZodString;
|
|
61
|
-
name: z.ZodString;
|
|
62
66
|
provider: z.ZodString;
|
|
63
|
-
|
|
67
|
+
price: z.ZodNumber;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
pickupPointId: z.ZodOptional<z.ZodString>;
|
|
64
70
|
}, "strip", z.ZodTypeAny, {
|
|
65
71
|
rateId: string;
|
|
66
|
-
name: string;
|
|
67
72
|
provider: string;
|
|
68
|
-
|
|
73
|
+
price: number;
|
|
74
|
+
name: string;
|
|
75
|
+
pickupPointId?: string | undefined;
|
|
69
76
|
}, {
|
|
70
77
|
rateId: string;
|
|
71
|
-
name: string;
|
|
72
78
|
provider: string;
|
|
73
|
-
|
|
79
|
+
price: number;
|
|
80
|
+
name: string;
|
|
81
|
+
pickupPointId?: string | undefined;
|
|
74
82
|
}>;
|
|
75
83
|
export declare const checkoutSchema: z.ZodObject<{
|
|
76
84
|
customer: z.ZodObject<{
|
|
@@ -84,11 +92,13 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
84
92
|
state: z.ZodOptional<z.ZodString>;
|
|
85
93
|
zipCode: z.ZodString;
|
|
86
94
|
country: z.ZodString;
|
|
95
|
+
countryCode: z.ZodString;
|
|
87
96
|
}, "strip", z.ZodTypeAny, {
|
|
88
97
|
line1: string;
|
|
89
98
|
city: string;
|
|
90
99
|
zipCode: string;
|
|
91
100
|
country: string;
|
|
101
|
+
countryCode: string;
|
|
92
102
|
line2?: string | undefined;
|
|
93
103
|
state?: string | undefined;
|
|
94
104
|
}, {
|
|
@@ -96,6 +106,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
96
106
|
city: string;
|
|
97
107
|
zipCode: string;
|
|
98
108
|
country: string;
|
|
109
|
+
countryCode: string;
|
|
99
110
|
line2?: string | undefined;
|
|
100
111
|
state?: string | undefined;
|
|
101
112
|
}>;
|
|
@@ -110,6 +121,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
110
121
|
city: string;
|
|
111
122
|
zipCode: string;
|
|
112
123
|
country: string;
|
|
124
|
+
countryCode: string;
|
|
113
125
|
line2?: string | undefined;
|
|
114
126
|
state?: string | undefined;
|
|
115
127
|
};
|
|
@@ -124,6 +136,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
124
136
|
city: string;
|
|
125
137
|
zipCode: string;
|
|
126
138
|
country: string;
|
|
139
|
+
countryCode: string;
|
|
127
140
|
line2?: string | undefined;
|
|
128
141
|
state?: string | undefined;
|
|
129
142
|
};
|
|
@@ -132,19 +145,22 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
132
145
|
}>;
|
|
133
146
|
shipping: z.ZodObject<{
|
|
134
147
|
rateId: z.ZodString;
|
|
135
|
-
name: z.ZodString;
|
|
136
148
|
provider: z.ZodString;
|
|
137
|
-
|
|
149
|
+
price: z.ZodNumber;
|
|
150
|
+
name: z.ZodString;
|
|
151
|
+
pickupPointId: z.ZodOptional<z.ZodString>;
|
|
138
152
|
}, "strip", z.ZodTypeAny, {
|
|
139
153
|
rateId: string;
|
|
140
|
-
name: string;
|
|
141
154
|
provider: string;
|
|
142
|
-
|
|
155
|
+
price: number;
|
|
156
|
+
name: string;
|
|
157
|
+
pickupPointId?: string | undefined;
|
|
143
158
|
}, {
|
|
144
159
|
rateId: string;
|
|
145
|
-
name: string;
|
|
146
160
|
provider: string;
|
|
147
|
-
|
|
161
|
+
price: number;
|
|
162
|
+
name: string;
|
|
163
|
+
pickupPointId?: string | undefined;
|
|
148
164
|
}>;
|
|
149
165
|
customerId: z.ZodOptional<z.ZodString>;
|
|
150
166
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -157,6 +173,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
157
173
|
city: string;
|
|
158
174
|
zipCode: string;
|
|
159
175
|
country: string;
|
|
176
|
+
countryCode: string;
|
|
160
177
|
line2?: string | undefined;
|
|
161
178
|
state?: string | undefined;
|
|
162
179
|
};
|
|
@@ -165,9 +182,10 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
165
182
|
};
|
|
166
183
|
shipping: {
|
|
167
184
|
rateId: string;
|
|
168
|
-
name: string;
|
|
169
185
|
provider: string;
|
|
170
|
-
|
|
186
|
+
price: number;
|
|
187
|
+
name: string;
|
|
188
|
+
pickupPointId?: string | undefined;
|
|
171
189
|
};
|
|
172
190
|
customerId?: string | undefined;
|
|
173
191
|
}, {
|
|
@@ -180,6 +198,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
180
198
|
city: string;
|
|
181
199
|
zipCode: string;
|
|
182
200
|
country: string;
|
|
201
|
+
countryCode: string;
|
|
183
202
|
line2?: string | undefined;
|
|
184
203
|
state?: string | undefined;
|
|
185
204
|
};
|
|
@@ -188,9 +207,10 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
188
207
|
};
|
|
189
208
|
shipping: {
|
|
190
209
|
rateId: string;
|
|
191
|
-
name: string;
|
|
192
210
|
provider: string;
|
|
193
|
-
|
|
211
|
+
price: number;
|
|
212
|
+
name: string;
|
|
213
|
+
pickupPointId?: string | undefined;
|
|
194
214
|
};
|
|
195
215
|
customerId?: string | undefined;
|
|
196
216
|
}>;
|
|
@@ -8,6 +8,10 @@ interface ShippingMethodFormProps {
|
|
|
8
8
|
onBack: () => void;
|
|
9
9
|
contactEmail: string;
|
|
10
10
|
shippingAddress: string;
|
|
11
|
+
currency: string;
|
|
12
|
+
exchangeRate: number;
|
|
13
|
+
locale?: string;
|
|
14
|
+
countryCode?: string;
|
|
11
15
|
}
|
|
12
|
-
export default function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, }: ShippingMethodFormProps): React.JSX.Element;
|
|
16
|
+
export default function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, currency, exchangeRate, locale, countryCode, }: ShippingMethodFormProps): React.JSX.Element;
|
|
13
17
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
Packeta: any;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export default function ZasilkovnaShippingOption({ children, onPickupPointSelected, locale, countryCode, apiKey, }: {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
onPickupPointSelected?: (pickupPointId: string) => void;
|
|
10
|
+
locale?: string;
|
|
11
|
+
countryCode?: string;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ShippingRate } from "@betterstore/sdk";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export default function ShippingOptionWrapper({ rate, children, onPickupPointSelected, locale, countryCode, }: {
|
|
4
|
+
rate: ShippingRate;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
onPickupPointSelected?: (pickupPointId: string) => void;
|
|
7
|
+
locale?: string;
|
|
8
|
+
countryCode?: string;
|
|
9
|
+
}): React.JSX.Element | undefined;
|
package/dist/index.cjs.js
CHANGED
|
@@ -2593,6 +2593,13 @@ function defaults(obj) {
|
|
|
2593
2593
|
});
|
|
2594
2594
|
return obj;
|
|
2595
2595
|
}
|
|
2596
|
+
function hasXSS(input) {
|
|
2597
|
+
if (typeof input !== 'string') return false;
|
|
2598
|
+
|
|
2599
|
+
// Common XSS attack patterns
|
|
2600
|
+
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
|
|
2601
|
+
return xssPatterns.some(pattern => pattern.test(input));
|
|
2602
|
+
}
|
|
2596
2603
|
|
|
2597
2604
|
// eslint-disable-next-line no-control-regex
|
|
2598
2605
|
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
@@ -2956,7 +2963,7 @@ class Browser {
|
|
|
2956
2963
|
if (lookup) detected = detected.concat(lookup);
|
|
2957
2964
|
}
|
|
2958
2965
|
});
|
|
2959
|
-
detected = detected.map(d => this.options.convertDetectedLanguage(d));
|
|
2966
|
+
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
|
|
2960
2967
|
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
|
2961
2968
|
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
|
2962
2969
|
}
|
|
@@ -3269,7 +3276,11 @@ const CheckoutEmbed$2 = {
|
|
|
3269
3276
|
estimatedDeliveryDate: "Odhadované datum dodání:",
|
|
3270
3277
|
shipTo: "Ship to:",
|
|
3271
3278
|
shipping: "Doprava:",
|
|
3272
|
-
title: "Přeprava"
|
|
3279
|
+
title: "Přeprava",
|
|
3280
|
+
description: {
|
|
3281
|
+
other: "Váš balíček bude doručen kurýrem.",
|
|
3282
|
+
zasilkovna: "Váš balíček bude doručen do bodu vyzvednutí."
|
|
3283
|
+
}
|
|
3273
3284
|
}
|
|
3274
3285
|
};
|
|
3275
3286
|
const Errors$1 = {
|
|
@@ -3337,7 +3348,11 @@ const CheckoutEmbed$1 = {
|
|
|
3337
3348
|
shipping: "Shipping:",
|
|
3338
3349
|
estimatedDeliveryDate: "Estimated delivery date: ",
|
|
3339
3350
|
day: "day",
|
|
3340
|
-
days: "days"
|
|
3351
|
+
days: "days",
|
|
3352
|
+
description: {
|
|
3353
|
+
other: "Your package will be delivered by a courier.",
|
|
3354
|
+
zasilkovna: "Your package will be delivered to a pickup point."
|
|
3355
|
+
}
|
|
3341
3356
|
},
|
|
3342
3357
|
Payment: {
|
|
3343
3358
|
title: "Payment",
|
|
@@ -3552,6 +3567,8 @@ const convertCheckoutAppearanceToStripeAppearance = (appearance$1, fonts) => {
|
|
|
3552
3567
|
return newAppearance;
|
|
3553
3568
|
};
|
|
3554
3569
|
|
|
3570
|
+
const storeHelpers = sdk.createStoreHelpers();
|
|
3571
|
+
|
|
3555
3572
|
const LayoutGroupContext = React.createContext({});
|
|
3556
3573
|
|
|
3557
3574
|
/**
|
|
@@ -3666,33 +3683,36 @@ function PopChild({ children, isPresent, anchorX }) {
|
|
|
3666
3683
|
const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, mode, anchorX, }) => {
|
|
3667
3684
|
const presenceChildren = useConstant(newChildrenMap);
|
|
3668
3685
|
const id = React.useId();
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3686
|
+
let isReusedContext = true;
|
|
3687
|
+
let context = React.useMemo(() => {
|
|
3688
|
+
isReusedContext = false;
|
|
3689
|
+
return {
|
|
3690
|
+
id,
|
|
3691
|
+
initial,
|
|
3692
|
+
isPresent,
|
|
3693
|
+
custom,
|
|
3694
|
+
onExitComplete: (childId) => {
|
|
3695
|
+
presenceChildren.set(childId, true);
|
|
3696
|
+
for (const isComplete of presenceChildren.values()) {
|
|
3697
|
+
if (!isComplete)
|
|
3698
|
+
return; // can stop searching when any is incomplete
|
|
3699
|
+
}
|
|
3700
|
+
onExitComplete && onExitComplete();
|
|
3701
|
+
},
|
|
3702
|
+
register: (childId) => {
|
|
3703
|
+
presenceChildren.set(childId, false);
|
|
3704
|
+
return () => presenceChildren.delete(childId);
|
|
3705
|
+
},
|
|
3706
|
+
};
|
|
3707
|
+
}, [isPresent, presenceChildren, onExitComplete]);
|
|
3688
3708
|
/**
|
|
3689
3709
|
* If the presence of a child affects the layout of the components around it,
|
|
3690
3710
|
* we want to make a new context value to ensure they get re-rendered
|
|
3691
3711
|
* so they can detect that layout change.
|
|
3692
3712
|
*/
|
|
3693
|
-
presenceAffectsLayout
|
|
3694
|
-
|
|
3695
|
-
|
|
3713
|
+
if (presenceAffectsLayout && isReusedContext) {
|
|
3714
|
+
context = { ...context };
|
|
3715
|
+
}
|
|
3696
3716
|
React.useMemo(() => {
|
|
3697
3717
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
3698
3718
|
}, [isPresent]);
|
|
@@ -5599,7 +5619,7 @@ class MotionValue {
|
|
|
5599
5619
|
* This will be replaced by the build step with the latest version number.
|
|
5600
5620
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
5601
5621
|
*/
|
|
5602
|
-
this.version = "12.7.
|
|
5622
|
+
this.version = "12.7.4";
|
|
5603
5623
|
/**
|
|
5604
5624
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
5605
5625
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -13201,7 +13221,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
13201
13221
|
* and warn against mismatches.
|
|
13202
13222
|
*/
|
|
13203
13223
|
if (process.env.NODE_ENV === "development") {
|
|
13204
|
-
warnOnce(nextValue.version === "12.7.
|
|
13224
|
+
warnOnce(nextValue.version === "12.7.4", `Attempting to mix Motion versions ${nextValue.version} with 12.7.4 may not work as expected.`);
|
|
13205
13225
|
}
|
|
13206
13226
|
}
|
|
13207
13227
|
else if (isMotionValue(prevValue)) {
|
|
@@ -18241,6 +18261,7 @@ const customerSchema = z.object({
|
|
|
18241
18261
|
state: z.string().optional(),
|
|
18242
18262
|
zipCode: z.string().min(5, "invalid_zipCode"),
|
|
18243
18263
|
country: z.string().min(1, "required_error"),
|
|
18264
|
+
countryCode: z.string().min(1, "required_error"),
|
|
18244
18265
|
}),
|
|
18245
18266
|
saveInfo: z.boolean().optional(),
|
|
18246
18267
|
phone: z.string().regex(phoneRegex, "invalid_phone"),
|
|
@@ -18248,9 +18269,10 @@ const customerSchema = z.object({
|
|
|
18248
18269
|
// Shipping method schema
|
|
18249
18270
|
const shippingMethodSchema = z.object({
|
|
18250
18271
|
rateId: z.string().min(1, "required_error"),
|
|
18251
|
-
name: z.string().min(1, "required_error"),
|
|
18252
18272
|
provider: z.string().min(1, "required_error"),
|
|
18253
|
-
|
|
18273
|
+
price: z.number().min(1, "required_error"),
|
|
18274
|
+
name: z.string().min(1, "required_error"),
|
|
18275
|
+
pickupPointId: z.string().optional(),
|
|
18254
18276
|
});
|
|
18255
18277
|
// Combined checkout schema
|
|
18256
18278
|
z.object({
|
|
@@ -32622,6 +32644,7 @@ function AddressInput() {
|
|
|
32622
32644
|
React.createElement(FormLabel, null, t("CheckoutEmbed.CustomerForm.address.country")),
|
|
32623
32645
|
React.createElement(CountryDropdown, { placeholder: t("CheckoutEmbed.CustomerForm.address.countryPlaceholder"), defaultValue: field.value, onChange: (country) => {
|
|
32624
32646
|
field.onChange(country.name);
|
|
32647
|
+
form.setValue("address.countryCode", country.alpha2);
|
|
32625
32648
|
} }),
|
|
32626
32649
|
React.createElement(FormMessage, null))) })),
|
|
32627
32650
|
React.createElement(DialogFooter, null,
|
|
@@ -34238,16 +34261,62 @@ function Skeleton(_a) {
|
|
|
34238
34261
|
return (React__namespace.createElement("div", Object.assign({ "data-slot": "skeleton", className: cn("bg-accent animate-pulse rounded-md", className) }, props)));
|
|
34239
34262
|
}
|
|
34240
34263
|
|
|
34241
|
-
function
|
|
34264
|
+
function ZasilkovnaShippingOption({ children, onPickupPointSelected, locale, countryCode, apiKey, }) {
|
|
34265
|
+
const [widgetLoaded, setWidgetLoaded] = React.useState(false);
|
|
34266
|
+
React.useEffect(() => {
|
|
34267
|
+
// Check if the script is already present
|
|
34268
|
+
if (!document.querySelector('script[src="https://widget.packeta.com/v6/www/js/library.js"]')) {
|
|
34269
|
+
const script = document.createElement("script");
|
|
34270
|
+
script.src = "https://widget.packeta.com/v6/www/js/library.js";
|
|
34271
|
+
script.async = true;
|
|
34272
|
+
script.onload = () => {
|
|
34273
|
+
setWidgetLoaded(true);
|
|
34274
|
+
console.log("loaded");
|
|
34275
|
+
};
|
|
34276
|
+
script.onerror = () => console.error("Failed to load Packeta Widget script.");
|
|
34277
|
+
document.body.appendChild(script);
|
|
34278
|
+
}
|
|
34279
|
+
else {
|
|
34280
|
+
setWidgetLoaded(true);
|
|
34281
|
+
}
|
|
34282
|
+
}, []);
|
|
34283
|
+
const handleClick = () => {
|
|
34284
|
+
if (widgetLoaded && window.Packeta && window.Packeta.Widget) {
|
|
34285
|
+
const options = {
|
|
34286
|
+
language: locale,
|
|
34287
|
+
country: countryCode,
|
|
34288
|
+
view: "modal",
|
|
34289
|
+
valueFormat: "id,name,city,street",
|
|
34290
|
+
};
|
|
34291
|
+
window.Packeta.Widget.pick(apiKey, (point) => {
|
|
34292
|
+
onPickupPointSelected === null || onPickupPointSelected === void 0 ? void 0 : onPickupPointSelected(point.id);
|
|
34293
|
+
}, options);
|
|
34294
|
+
}
|
|
34295
|
+
else {
|
|
34296
|
+
console.error("Packeta widget not found", window);
|
|
34297
|
+
}
|
|
34298
|
+
};
|
|
34299
|
+
return (React.createElement(React.Fragment, null,
|
|
34300
|
+
React.createElement("div", { onClick: () => handleClick() }, children)));
|
|
34301
|
+
}
|
|
34302
|
+
|
|
34303
|
+
function ShippingOptionWrapper({ rate, children, onPickupPointSelected, locale, countryCode, }) {
|
|
34304
|
+
if (rate.provider === "zasilkovna") {
|
|
34305
|
+
return (React.createElement(ZasilkovnaShippingOption, { onPickupPointSelected: onPickupPointSelected, locale: locale, countryCode: countryCode, apiKey: rate.clientSecret }, children));
|
|
34306
|
+
}
|
|
34307
|
+
return;
|
|
34308
|
+
}
|
|
34309
|
+
|
|
34310
|
+
function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, currency, exchangeRate, locale, countryCode, }) {
|
|
34242
34311
|
var _a;
|
|
34243
34312
|
const { t } = useTranslation();
|
|
34244
34313
|
const form = useForm({
|
|
34245
34314
|
resolver: s$1(shippingMethodSchema),
|
|
34246
34315
|
defaultValues: initialData || {
|
|
34247
34316
|
rateId: "",
|
|
34248
|
-
name: "",
|
|
34249
34317
|
provider: "",
|
|
34250
|
-
|
|
34318
|
+
price: 0,
|
|
34319
|
+
pickupPointId: "",
|
|
34251
34320
|
},
|
|
34252
34321
|
});
|
|
34253
34322
|
const currentRateId = form.watch("rateId");
|
|
@@ -34271,28 +34340,27 @@ function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, cont
|
|
|
34271
34340
|
shippingRates.length === 0 &&
|
|
34272
34341
|
Array.from({ length: 3 }).map((_, index) => (React.createElement(ShippingRateLoading, { key: index }))),
|
|
34273
34342
|
shippingRates.map((rate) => {
|
|
34274
|
-
const rateId = rate.
|
|
34275
|
-
const intPrice = Math.ceil(Number(rate.
|
|
34276
|
-
const
|
|
34277
|
-
|
|
34278
|
-
|
|
34279
|
-
|
|
34280
|
-
|
|
34281
|
-
form.setValue("
|
|
34282
|
-
|
|
34283
|
-
|
|
34284
|
-
|
|
34285
|
-
|
|
34286
|
-
|
|
34287
|
-
|
|
34288
|
-
|
|
34289
|
-
|
|
34290
|
-
|
|
34291
|
-
|
|
34292
|
-
|
|
34293
|
-
|
|
34294
|
-
|
|
34295
|
-
: t("CheckoutEmbed.Shipping.days")))));
|
|
34343
|
+
const rateId = rate.provider + rate.name;
|
|
34344
|
+
const intPrice = Math.ceil(Number(rate.price));
|
|
34345
|
+
const displayPrice = storeHelpers.formatPrice(intPrice, currency, exchangeRate);
|
|
34346
|
+
const description = rate.provider === "zasilkovna"
|
|
34347
|
+
? t("CheckoutEmbed.Shipping.description.zasilkovna")
|
|
34348
|
+
: t("CheckoutEmbed.Shipping.description.other");
|
|
34349
|
+
return (React.createElement(ShippingOptionWrapper, { rate: rate, key: rateId, onPickupPointSelected: (pickupPointId) => {
|
|
34350
|
+
form.setValue("pickupPointId", pickupPointId);
|
|
34351
|
+
}, locale: locale, countryCode: countryCode },
|
|
34352
|
+
React.createElement("div", { className: clsx("p-4 cursor-pointer rounded-md border bg-background", {
|
|
34353
|
+
"bg-muted border-primary": currentRateId === rateId,
|
|
34354
|
+
}), onClick: () => {
|
|
34355
|
+
form.setValue("rateId", rateId);
|
|
34356
|
+
form.setValue("provider", rate.provider);
|
|
34357
|
+
form.setValue("name", rate.name);
|
|
34358
|
+
form.setValue("price", intPrice);
|
|
34359
|
+
} },
|
|
34360
|
+
React.createElement("div", { className: "flex items-center justify-between w-full" },
|
|
34361
|
+
React.createElement("p", null, rate.name),
|
|
34362
|
+
React.createElement("p", null, displayPrice)),
|
|
34363
|
+
React.createElement("p", { className: "text-sm text-muted-foreground" }, description))));
|
|
34296
34364
|
}),
|
|
34297
34365
|
React.createElement(FormMessage, null, (_a = form.formState.errors.rateId) === null || _a === void 0 ? void 0 : _a.message),
|
|
34298
34366
|
React.createElement("div", { className: "flex justify-between items-center pt-4" },
|
|
@@ -34322,7 +34390,7 @@ const motionSettings = {
|
|
|
34322
34390
|
exit: { opacity: 0 },
|
|
34323
34391
|
transition: { duration: 0.2 },
|
|
34324
34392
|
};
|
|
34325
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }) {
|
|
34393
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }) {
|
|
34326
34394
|
const { formData, setFormData, step, setStep } = useFormStore(checkoutId)();
|
|
34327
34395
|
const [paymentSecret, setPaymentSecret] = React.useState(null);
|
|
34328
34396
|
const [shippingRates, setShippingRates] = React.useState([]);
|
|
@@ -34346,7 +34414,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34346
34414
|
validateStep();
|
|
34347
34415
|
}, [step]);
|
|
34348
34416
|
React.useEffect(() => {
|
|
34349
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34417
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
34350
34418
|
if (customer && !((_a = formData.customer) === null || _a === void 0 ? void 0 : _a.email)) {
|
|
34351
34419
|
setFormData(Object.assign(Object.assign({}, formData), { customerId: customer.id, customer: {
|
|
34352
34420
|
firstName: (_d = (_c = (_b = customer.address) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split(" ")[0]) !== null && _d !== void 0 ? _d : "",
|
|
@@ -34359,6 +34427,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34359
34427
|
city: (_r = (_q = customer.address) === null || _q === void 0 ? void 0 : _q.city) !== null && _r !== void 0 ? _r : "",
|
|
34360
34428
|
zipCode: (_t = (_s = customer.address) === null || _s === void 0 ? void 0 : _s.zipCode) !== null && _t !== void 0 ? _t : "",
|
|
34361
34429
|
country: (_v = (_u = customer.address) === null || _u === void 0 ? void 0 : _u.country) !== null && _v !== void 0 ? _v : "",
|
|
34430
|
+
countryCode: (_x = (_w = customer.address) === null || _w === void 0 ? void 0 : _w.countryCode) !== null && _x !== void 0 ? _x : "",
|
|
34362
34431
|
},
|
|
34363
34432
|
} }));
|
|
34364
34433
|
}
|
|
@@ -34370,12 +34439,14 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34370
34439
|
return;
|
|
34371
34440
|
const getShippingRates = () => __awaiter(this, void 0, void 0, function* () {
|
|
34372
34441
|
const shippingRates = yield storeClient.getCheckoutShippingRates(clientSecret, checkoutId);
|
|
34442
|
+
console.log(shippingRates);
|
|
34373
34443
|
setShippingRates(shippingRates);
|
|
34374
34444
|
});
|
|
34375
34445
|
getShippingRates();
|
|
34376
34446
|
}, [step, shippingRates]);
|
|
34377
34447
|
// Handle address form submission
|
|
34378
34448
|
const handleCustomerSubmit = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
34449
|
+
setFormData(Object.assign(Object.assign({}, formData), { customer: data }));
|
|
34379
34450
|
let newCustomerId = formData.customerId;
|
|
34380
34451
|
if (!newCustomerId) {
|
|
34381
34452
|
const newCustomer = yield storeClient.createCustomer(clientSecret, {
|
|
@@ -34409,16 +34480,15 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34409
34480
|
const newFormData = Object.assign(Object.assign({}, formData), { shipping: data });
|
|
34410
34481
|
setFormData(newFormData);
|
|
34411
34482
|
yield storeClient.updateCheckout(clientSecret, checkoutId, {
|
|
34412
|
-
shipping: data.
|
|
34413
|
-
|
|
34414
|
-
rateId: data.rateId,
|
|
34415
|
-
name: data.name,
|
|
34483
|
+
shipping: data.price,
|
|
34484
|
+
shipmentInfo: {
|
|
34416
34485
|
provider: data.provider,
|
|
34486
|
+
pickupPointId: data.pickupPointId,
|
|
34417
34487
|
},
|
|
34418
34488
|
});
|
|
34419
34489
|
const paymentSecret = yield storeClient.generateCheckoutsPaymentSecret(clientSecret, checkoutId);
|
|
34420
34490
|
setPaymentSecret(paymentSecret);
|
|
34421
|
-
setShippingCost(data.
|
|
34491
|
+
setShippingCost(data.price);
|
|
34422
34492
|
setStep("payment");
|
|
34423
34493
|
});
|
|
34424
34494
|
// Navigate back to previous step
|
|
@@ -34448,9 +34518,9 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34448
34518
|
step === "customer" && (React.createElement(motion.div, Object.assign({ key: "customer" }, motionSettings, { className: "absolute w-full" }),
|
|
34449
34519
|
React.createElement(CustomerForm, { initialData: formData.customer, onSubmit: handleCustomerSubmit }))),
|
|
34450
34520
|
step === "shipping" && formData.customer && (React.createElement(motion.div, Object.assign({ key: "shipping" }, motionSettings, { className: "absolute w-full" }),
|
|
34451
|
-
React.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address) }))),
|
|
34521
|
+
React.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), currency: currency, exchangeRate: exchangeRate, locale: locale, countryCode: formData.customer.address.countryCode }))),
|
|
34452
34522
|
step === "payment" && formData.customer && formData.shipping && (React.createElement(motion.div, Object.assign({ key: "payment" }, motionSettings, { className: "absolute w-full" }),
|
|
34453
|
-
React.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.
|
|
34523
|
+
React.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: storeHelpers.formatPrice(formData.shipping.price, currency, exchangeRate) }))))));
|
|
34454
34524
|
}
|
|
34455
34525
|
|
|
34456
34526
|
function CheckoutFormLoading() {
|
|
@@ -34472,8 +34542,6 @@ function InputGroupLoading({ className }) {
|
|
|
34472
34542
|
React.createElement(Skeleton, { className: "w-full h-9" })));
|
|
34473
34543
|
}
|
|
34474
34544
|
|
|
34475
|
-
const storeHelpers = sdk.createStoreHelpers();
|
|
34476
|
-
|
|
34477
34545
|
function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }) {
|
|
34478
34546
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
34479
34547
|
const { t } = useTranslation();
|
|
@@ -34564,7 +34632,7 @@ function CheckoutSummaryLoading() {
|
|
|
34564
34632
|
}
|
|
34565
34633
|
|
|
34566
34634
|
function CheckoutEmbed({ checkoutId, config }) {
|
|
34567
|
-
var _a, _b, _c, _d;
|
|
34635
|
+
var _a, _b, _c, _d, _e;
|
|
34568
34636
|
const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
|
|
34569
34637
|
const storeClient = sdk.createStoreClient({ proxy: clientProxy });
|
|
34570
34638
|
React.useMemo(() => createI18nInstance(locale), []);
|
|
@@ -34615,8 +34683,8 @@ function CheckoutEmbed({ checkoutId, config }) {
|
|
|
34615
34683
|
};
|
|
34616
34684
|
return (React.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
34617
34685
|
React.createElement(Appearance, { appearance: appearance }),
|
|
34618
|
-
React.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError }))),
|
|
34619
|
-
React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (
|
|
34686
|
+
React.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1 }))),
|
|
34687
|
+
React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
|
|
34620
34688
|
}
|
|
34621
34689
|
var index = React.memo(CheckoutEmbed);
|
|
34622
34690
|
|
package/dist/index.mjs
CHANGED
|
@@ -2570,6 +2570,13 @@ function defaults(obj) {
|
|
|
2570
2570
|
});
|
|
2571
2571
|
return obj;
|
|
2572
2572
|
}
|
|
2573
|
+
function hasXSS(input) {
|
|
2574
|
+
if (typeof input !== 'string') return false;
|
|
2575
|
+
|
|
2576
|
+
// Common XSS attack patterns
|
|
2577
|
+
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
|
|
2578
|
+
return xssPatterns.some(pattern => pattern.test(input));
|
|
2579
|
+
}
|
|
2573
2580
|
|
|
2574
2581
|
// eslint-disable-next-line no-control-regex
|
|
2575
2582
|
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
@@ -2933,7 +2940,7 @@ class Browser {
|
|
|
2933
2940
|
if (lookup) detected = detected.concat(lookup);
|
|
2934
2941
|
}
|
|
2935
2942
|
});
|
|
2936
|
-
detected = detected.map(d => this.options.convertDetectedLanguage(d));
|
|
2943
|
+
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
|
|
2937
2944
|
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
|
2938
2945
|
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
|
2939
2946
|
}
|
|
@@ -3246,7 +3253,11 @@ const CheckoutEmbed$2 = {
|
|
|
3246
3253
|
estimatedDeliveryDate: "Odhadované datum dodání:",
|
|
3247
3254
|
shipTo: "Ship to:",
|
|
3248
3255
|
shipping: "Doprava:",
|
|
3249
|
-
title: "Přeprava"
|
|
3256
|
+
title: "Přeprava",
|
|
3257
|
+
description: {
|
|
3258
|
+
other: "Váš balíček bude doručen kurýrem.",
|
|
3259
|
+
zasilkovna: "Váš balíček bude doručen do bodu vyzvednutí."
|
|
3260
|
+
}
|
|
3250
3261
|
}
|
|
3251
3262
|
};
|
|
3252
3263
|
const Errors$1 = {
|
|
@@ -3314,7 +3325,11 @@ const CheckoutEmbed$1 = {
|
|
|
3314
3325
|
shipping: "Shipping:",
|
|
3315
3326
|
estimatedDeliveryDate: "Estimated delivery date: ",
|
|
3316
3327
|
day: "day",
|
|
3317
|
-
days: "days"
|
|
3328
|
+
days: "days",
|
|
3329
|
+
description: {
|
|
3330
|
+
other: "Your package will be delivered by a courier.",
|
|
3331
|
+
zasilkovna: "Your package will be delivered to a pickup point."
|
|
3332
|
+
}
|
|
3318
3333
|
},
|
|
3319
3334
|
Payment: {
|
|
3320
3335
|
title: "Payment",
|
|
@@ -3529,6 +3544,8 @@ const convertCheckoutAppearanceToStripeAppearance = (appearance$1, fonts) => {
|
|
|
3529
3544
|
return newAppearance;
|
|
3530
3545
|
};
|
|
3531
3546
|
|
|
3547
|
+
const storeHelpers = createStoreHelpers();
|
|
3548
|
+
|
|
3532
3549
|
const LayoutGroupContext = createContext({});
|
|
3533
3550
|
|
|
3534
3551
|
/**
|
|
@@ -3643,33 +3660,36 @@ function PopChild({ children, isPresent, anchorX }) {
|
|
|
3643
3660
|
const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, mode, anchorX, }) => {
|
|
3644
3661
|
const presenceChildren = useConstant(newChildrenMap);
|
|
3645
3662
|
const id = useId();
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3663
|
+
let isReusedContext = true;
|
|
3664
|
+
let context = useMemo(() => {
|
|
3665
|
+
isReusedContext = false;
|
|
3666
|
+
return {
|
|
3667
|
+
id,
|
|
3668
|
+
initial,
|
|
3669
|
+
isPresent,
|
|
3670
|
+
custom,
|
|
3671
|
+
onExitComplete: (childId) => {
|
|
3672
|
+
presenceChildren.set(childId, true);
|
|
3673
|
+
for (const isComplete of presenceChildren.values()) {
|
|
3674
|
+
if (!isComplete)
|
|
3675
|
+
return; // can stop searching when any is incomplete
|
|
3676
|
+
}
|
|
3677
|
+
onExitComplete && onExitComplete();
|
|
3678
|
+
},
|
|
3679
|
+
register: (childId) => {
|
|
3680
|
+
presenceChildren.set(childId, false);
|
|
3681
|
+
return () => presenceChildren.delete(childId);
|
|
3682
|
+
},
|
|
3683
|
+
};
|
|
3684
|
+
}, [isPresent, presenceChildren, onExitComplete]);
|
|
3665
3685
|
/**
|
|
3666
3686
|
* If the presence of a child affects the layout of the components around it,
|
|
3667
3687
|
* we want to make a new context value to ensure they get re-rendered
|
|
3668
3688
|
* so they can detect that layout change.
|
|
3669
3689
|
*/
|
|
3670
|
-
presenceAffectsLayout
|
|
3671
|
-
|
|
3672
|
-
|
|
3690
|
+
if (presenceAffectsLayout && isReusedContext) {
|
|
3691
|
+
context = { ...context };
|
|
3692
|
+
}
|
|
3673
3693
|
useMemo(() => {
|
|
3674
3694
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
3675
3695
|
}, [isPresent]);
|
|
@@ -5576,7 +5596,7 @@ class MotionValue {
|
|
|
5576
5596
|
* This will be replaced by the build step with the latest version number.
|
|
5577
5597
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
5578
5598
|
*/
|
|
5579
|
-
this.version = "12.7.
|
|
5599
|
+
this.version = "12.7.4";
|
|
5580
5600
|
/**
|
|
5581
5601
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
5582
5602
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -13178,7 +13198,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
13178
13198
|
* and warn against mismatches.
|
|
13179
13199
|
*/
|
|
13180
13200
|
if (process.env.NODE_ENV === "development") {
|
|
13181
|
-
warnOnce(nextValue.version === "12.7.
|
|
13201
|
+
warnOnce(nextValue.version === "12.7.4", `Attempting to mix Motion versions ${nextValue.version} with 12.7.4 may not work as expected.`);
|
|
13182
13202
|
}
|
|
13183
13203
|
}
|
|
13184
13204
|
else if (isMotionValue(prevValue)) {
|
|
@@ -18218,6 +18238,7 @@ const customerSchema = z.object({
|
|
|
18218
18238
|
state: z.string().optional(),
|
|
18219
18239
|
zipCode: z.string().min(5, "invalid_zipCode"),
|
|
18220
18240
|
country: z.string().min(1, "required_error"),
|
|
18241
|
+
countryCode: z.string().min(1, "required_error"),
|
|
18221
18242
|
}),
|
|
18222
18243
|
saveInfo: z.boolean().optional(),
|
|
18223
18244
|
phone: z.string().regex(phoneRegex, "invalid_phone"),
|
|
@@ -18225,9 +18246,10 @@ const customerSchema = z.object({
|
|
|
18225
18246
|
// Shipping method schema
|
|
18226
18247
|
const shippingMethodSchema = z.object({
|
|
18227
18248
|
rateId: z.string().min(1, "required_error"),
|
|
18228
|
-
name: z.string().min(1, "required_error"),
|
|
18229
18249
|
provider: z.string().min(1, "required_error"),
|
|
18230
|
-
|
|
18250
|
+
price: z.number().min(1, "required_error"),
|
|
18251
|
+
name: z.string().min(1, "required_error"),
|
|
18252
|
+
pickupPointId: z.string().optional(),
|
|
18231
18253
|
});
|
|
18232
18254
|
// Combined checkout schema
|
|
18233
18255
|
z.object({
|
|
@@ -32599,6 +32621,7 @@ function AddressInput() {
|
|
|
32599
32621
|
React__default.createElement(FormLabel, null, t("CheckoutEmbed.CustomerForm.address.country")),
|
|
32600
32622
|
React__default.createElement(CountryDropdown, { placeholder: t("CheckoutEmbed.CustomerForm.address.countryPlaceholder"), defaultValue: field.value, onChange: (country) => {
|
|
32601
32623
|
field.onChange(country.name);
|
|
32624
|
+
form.setValue("address.countryCode", country.alpha2);
|
|
32602
32625
|
} }),
|
|
32603
32626
|
React__default.createElement(FormMessage, null))) })),
|
|
32604
32627
|
React__default.createElement(DialogFooter, null,
|
|
@@ -34215,16 +34238,62 @@ function Skeleton(_a) {
|
|
|
34215
34238
|
return (React.createElement("div", Object.assign({ "data-slot": "skeleton", className: cn("bg-accent animate-pulse rounded-md", className) }, props)));
|
|
34216
34239
|
}
|
|
34217
34240
|
|
|
34218
|
-
function
|
|
34241
|
+
function ZasilkovnaShippingOption({ children, onPickupPointSelected, locale, countryCode, apiKey, }) {
|
|
34242
|
+
const [widgetLoaded, setWidgetLoaded] = useState(false);
|
|
34243
|
+
useEffect(() => {
|
|
34244
|
+
// Check if the script is already present
|
|
34245
|
+
if (!document.querySelector('script[src="https://widget.packeta.com/v6/www/js/library.js"]')) {
|
|
34246
|
+
const script = document.createElement("script");
|
|
34247
|
+
script.src = "https://widget.packeta.com/v6/www/js/library.js";
|
|
34248
|
+
script.async = true;
|
|
34249
|
+
script.onload = () => {
|
|
34250
|
+
setWidgetLoaded(true);
|
|
34251
|
+
console.log("loaded");
|
|
34252
|
+
};
|
|
34253
|
+
script.onerror = () => console.error("Failed to load Packeta Widget script.");
|
|
34254
|
+
document.body.appendChild(script);
|
|
34255
|
+
}
|
|
34256
|
+
else {
|
|
34257
|
+
setWidgetLoaded(true);
|
|
34258
|
+
}
|
|
34259
|
+
}, []);
|
|
34260
|
+
const handleClick = () => {
|
|
34261
|
+
if (widgetLoaded && window.Packeta && window.Packeta.Widget) {
|
|
34262
|
+
const options = {
|
|
34263
|
+
language: locale,
|
|
34264
|
+
country: countryCode,
|
|
34265
|
+
view: "modal",
|
|
34266
|
+
valueFormat: "id,name,city,street",
|
|
34267
|
+
};
|
|
34268
|
+
window.Packeta.Widget.pick(apiKey, (point) => {
|
|
34269
|
+
onPickupPointSelected === null || onPickupPointSelected === void 0 ? void 0 : onPickupPointSelected(point.id);
|
|
34270
|
+
}, options);
|
|
34271
|
+
}
|
|
34272
|
+
else {
|
|
34273
|
+
console.error("Packeta widget not found", window);
|
|
34274
|
+
}
|
|
34275
|
+
};
|
|
34276
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
34277
|
+
React__default.createElement("div", { onClick: () => handleClick() }, children)));
|
|
34278
|
+
}
|
|
34279
|
+
|
|
34280
|
+
function ShippingOptionWrapper({ rate, children, onPickupPointSelected, locale, countryCode, }) {
|
|
34281
|
+
if (rate.provider === "zasilkovna") {
|
|
34282
|
+
return (React__default.createElement(ZasilkovnaShippingOption, { onPickupPointSelected: onPickupPointSelected, locale: locale, countryCode: countryCode, apiKey: rate.clientSecret }, children));
|
|
34283
|
+
}
|
|
34284
|
+
return;
|
|
34285
|
+
}
|
|
34286
|
+
|
|
34287
|
+
function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, currency, exchangeRate, locale, countryCode, }) {
|
|
34219
34288
|
var _a;
|
|
34220
34289
|
const { t } = useTranslation();
|
|
34221
34290
|
const form = useForm({
|
|
34222
34291
|
resolver: s$1(shippingMethodSchema),
|
|
34223
34292
|
defaultValues: initialData || {
|
|
34224
34293
|
rateId: "",
|
|
34225
|
-
name: "",
|
|
34226
34294
|
provider: "",
|
|
34227
|
-
|
|
34295
|
+
price: 0,
|
|
34296
|
+
pickupPointId: "",
|
|
34228
34297
|
},
|
|
34229
34298
|
});
|
|
34230
34299
|
const currentRateId = form.watch("rateId");
|
|
@@ -34248,28 +34317,27 @@ function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, cont
|
|
|
34248
34317
|
shippingRates.length === 0 &&
|
|
34249
34318
|
Array.from({ length: 3 }).map((_, index) => (React__default.createElement(ShippingRateLoading, { key: index }))),
|
|
34250
34319
|
shippingRates.map((rate) => {
|
|
34251
|
-
const rateId = rate.
|
|
34252
|
-
const intPrice = Math.ceil(Number(rate.
|
|
34253
|
-
const
|
|
34254
|
-
|
|
34255
|
-
|
|
34256
|
-
|
|
34257
|
-
|
|
34258
|
-
form.setValue("
|
|
34259
|
-
|
|
34260
|
-
|
|
34261
|
-
|
|
34262
|
-
|
|
34263
|
-
|
|
34264
|
-
|
|
34265
|
-
|
|
34266
|
-
|
|
34267
|
-
|
|
34268
|
-
|
|
34269
|
-
|
|
34270
|
-
|
|
34271
|
-
|
|
34272
|
-
: t("CheckoutEmbed.Shipping.days")))));
|
|
34320
|
+
const rateId = rate.provider + rate.name;
|
|
34321
|
+
const intPrice = Math.ceil(Number(rate.price));
|
|
34322
|
+
const displayPrice = storeHelpers.formatPrice(intPrice, currency, exchangeRate);
|
|
34323
|
+
const description = rate.provider === "zasilkovna"
|
|
34324
|
+
? t("CheckoutEmbed.Shipping.description.zasilkovna")
|
|
34325
|
+
: t("CheckoutEmbed.Shipping.description.other");
|
|
34326
|
+
return (React__default.createElement(ShippingOptionWrapper, { rate: rate, key: rateId, onPickupPointSelected: (pickupPointId) => {
|
|
34327
|
+
form.setValue("pickupPointId", pickupPointId);
|
|
34328
|
+
}, locale: locale, countryCode: countryCode },
|
|
34329
|
+
React__default.createElement("div", { className: clsx("p-4 cursor-pointer rounded-md border bg-background", {
|
|
34330
|
+
"bg-muted border-primary": currentRateId === rateId,
|
|
34331
|
+
}), onClick: () => {
|
|
34332
|
+
form.setValue("rateId", rateId);
|
|
34333
|
+
form.setValue("provider", rate.provider);
|
|
34334
|
+
form.setValue("name", rate.name);
|
|
34335
|
+
form.setValue("price", intPrice);
|
|
34336
|
+
} },
|
|
34337
|
+
React__default.createElement("div", { className: "flex items-center justify-between w-full" },
|
|
34338
|
+
React__default.createElement("p", null, rate.name),
|
|
34339
|
+
React__default.createElement("p", null, displayPrice)),
|
|
34340
|
+
React__default.createElement("p", { className: "text-sm text-muted-foreground" }, description))));
|
|
34273
34341
|
}),
|
|
34274
34342
|
React__default.createElement(FormMessage, null, (_a = form.formState.errors.rateId) === null || _a === void 0 ? void 0 : _a.message),
|
|
34275
34343
|
React__default.createElement("div", { className: "flex justify-between items-center pt-4" },
|
|
@@ -34299,7 +34367,7 @@ const motionSettings = {
|
|
|
34299
34367
|
exit: { opacity: 0 },
|
|
34300
34368
|
transition: { duration: 0.2 },
|
|
34301
34369
|
};
|
|
34302
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }) {
|
|
34370
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }) {
|
|
34303
34371
|
const { formData, setFormData, step, setStep } = useFormStore(checkoutId)();
|
|
34304
34372
|
const [paymentSecret, setPaymentSecret] = useState(null);
|
|
34305
34373
|
const [shippingRates, setShippingRates] = useState([]);
|
|
@@ -34323,7 +34391,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34323
34391
|
validateStep();
|
|
34324
34392
|
}, [step]);
|
|
34325
34393
|
useEffect(() => {
|
|
34326
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34394
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
34327
34395
|
if (customer && !((_a = formData.customer) === null || _a === void 0 ? void 0 : _a.email)) {
|
|
34328
34396
|
setFormData(Object.assign(Object.assign({}, formData), { customerId: customer.id, customer: {
|
|
34329
34397
|
firstName: (_d = (_c = (_b = customer.address) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split(" ")[0]) !== null && _d !== void 0 ? _d : "",
|
|
@@ -34336,6 +34404,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34336
34404
|
city: (_r = (_q = customer.address) === null || _q === void 0 ? void 0 : _q.city) !== null && _r !== void 0 ? _r : "",
|
|
34337
34405
|
zipCode: (_t = (_s = customer.address) === null || _s === void 0 ? void 0 : _s.zipCode) !== null && _t !== void 0 ? _t : "",
|
|
34338
34406
|
country: (_v = (_u = customer.address) === null || _u === void 0 ? void 0 : _u.country) !== null && _v !== void 0 ? _v : "",
|
|
34407
|
+
countryCode: (_x = (_w = customer.address) === null || _w === void 0 ? void 0 : _w.countryCode) !== null && _x !== void 0 ? _x : "",
|
|
34339
34408
|
},
|
|
34340
34409
|
} }));
|
|
34341
34410
|
}
|
|
@@ -34347,12 +34416,14 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34347
34416
|
return;
|
|
34348
34417
|
const getShippingRates = () => __awaiter(this, void 0, void 0, function* () {
|
|
34349
34418
|
const shippingRates = yield storeClient.getCheckoutShippingRates(clientSecret, checkoutId);
|
|
34419
|
+
console.log(shippingRates);
|
|
34350
34420
|
setShippingRates(shippingRates);
|
|
34351
34421
|
});
|
|
34352
34422
|
getShippingRates();
|
|
34353
34423
|
}, [step, shippingRates]);
|
|
34354
34424
|
// Handle address form submission
|
|
34355
34425
|
const handleCustomerSubmit = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
34426
|
+
setFormData(Object.assign(Object.assign({}, formData), { customer: data }));
|
|
34356
34427
|
let newCustomerId = formData.customerId;
|
|
34357
34428
|
if (!newCustomerId) {
|
|
34358
34429
|
const newCustomer = yield storeClient.createCustomer(clientSecret, {
|
|
@@ -34386,16 +34457,15 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34386
34457
|
const newFormData = Object.assign(Object.assign({}, formData), { shipping: data });
|
|
34387
34458
|
setFormData(newFormData);
|
|
34388
34459
|
yield storeClient.updateCheckout(clientSecret, checkoutId, {
|
|
34389
|
-
shipping: data.
|
|
34390
|
-
|
|
34391
|
-
rateId: data.rateId,
|
|
34392
|
-
name: data.name,
|
|
34460
|
+
shipping: data.price,
|
|
34461
|
+
shipmentInfo: {
|
|
34393
34462
|
provider: data.provider,
|
|
34463
|
+
pickupPointId: data.pickupPointId,
|
|
34394
34464
|
},
|
|
34395
34465
|
});
|
|
34396
34466
|
const paymentSecret = yield storeClient.generateCheckoutsPaymentSecret(clientSecret, checkoutId);
|
|
34397
34467
|
setPaymentSecret(paymentSecret);
|
|
34398
|
-
setShippingCost(data.
|
|
34468
|
+
setShippingCost(data.price);
|
|
34399
34469
|
setStep("payment");
|
|
34400
34470
|
});
|
|
34401
34471
|
// Navigate back to previous step
|
|
@@ -34425,9 +34495,9 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34425
34495
|
step === "customer" && (React__default.createElement(motion.div, Object.assign({ key: "customer" }, motionSettings, { className: "absolute w-full" }),
|
|
34426
34496
|
React__default.createElement(CustomerForm, { initialData: formData.customer, onSubmit: handleCustomerSubmit }))),
|
|
34427
34497
|
step === "shipping" && formData.customer && (React__default.createElement(motion.div, Object.assign({ key: "shipping" }, motionSettings, { className: "absolute w-full" }),
|
|
34428
|
-
React__default.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address) }))),
|
|
34498
|
+
React__default.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), currency: currency, exchangeRate: exchangeRate, locale: locale, countryCode: formData.customer.address.countryCode }))),
|
|
34429
34499
|
step === "payment" && formData.customer && formData.shipping && (React__default.createElement(motion.div, Object.assign({ key: "payment" }, motionSettings, { className: "absolute w-full" }),
|
|
34430
|
-
React__default.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.
|
|
34500
|
+
React__default.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: storeHelpers.formatPrice(formData.shipping.price, currency, exchangeRate) }))))));
|
|
34431
34501
|
}
|
|
34432
34502
|
|
|
34433
34503
|
function CheckoutFormLoading() {
|
|
@@ -34449,8 +34519,6 @@ function InputGroupLoading({ className }) {
|
|
|
34449
34519
|
React__default.createElement(Skeleton, { className: "w-full h-9" })));
|
|
34450
34520
|
}
|
|
34451
34521
|
|
|
34452
|
-
const storeHelpers = createStoreHelpers();
|
|
34453
|
-
|
|
34454
34522
|
function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }) {
|
|
34455
34523
|
const [isOpen, setIsOpen] = useState(false);
|
|
34456
34524
|
const { t } = useTranslation();
|
|
@@ -34541,7 +34609,7 @@ function CheckoutSummaryLoading() {
|
|
|
34541
34609
|
}
|
|
34542
34610
|
|
|
34543
34611
|
function CheckoutEmbed({ checkoutId, config }) {
|
|
34544
|
-
var _a, _b, _c, _d;
|
|
34612
|
+
var _a, _b, _c, _d, _e;
|
|
34545
34613
|
const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
|
|
34546
34614
|
const storeClient = createStoreClient({ proxy: clientProxy });
|
|
34547
34615
|
React__default.useMemo(() => createI18nInstance(locale), []);
|
|
@@ -34592,8 +34660,8 @@ function CheckoutEmbed({ checkoutId, config }) {
|
|
|
34592
34660
|
};
|
|
34593
34661
|
return (React__default.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
34594
34662
|
React__default.createElement(Appearance, { appearance: appearance }),
|
|
34595
|
-
React__default.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError }))),
|
|
34596
|
-
React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (
|
|
34663
|
+
React__default.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1 }))),
|
|
34664
|
+
React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
|
|
34597
34665
|
}
|
|
34598
34666
|
var index = memo$1(CheckoutEmbed);
|
|
34599
34667
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"description": "E-commerce for Developers",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"author": "Better Store",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@betterstore/sdk": "^0.3.
|
|
22
|
+
"@betterstore/sdk": "^0.3.31",
|
|
23
23
|
"@changesets/cli": "^2.28.1",
|
|
24
24
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
25
25
|
"@rollup/plugin-json": "^6.1.0",
|