@zonos/elements 1.3.29 → 1.3.31
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/dist/cjs/index.cjs.js +55 -38
- package/dist/cjs/zonos-cart-items_12.cjs.entry.js +3 -4
- package/dist/collection/components/checkout/zonos-checkout/zonos-checkout-finish/zonos-checkout-finish.js +3 -4
- package/dist/collection/environment.js +6 -0
- package/dist/collection/scripts/_getNextFallbackUrl.js +12 -0
- package/dist/collection/scripts/_zonosBase.js +42 -37
- package/dist/esm/index.js +55 -38
- package/dist/esm/zonos-cart-items_12.entry.js +3 -4
- package/dist/esm-es5/index.js +1 -1
- package/dist/esm-es5/zonos-cart-items_12.entry.js +1 -1
- package/dist/scripts/index.d.ts +3 -0
- package/dist/scripts/index.js +1 -1
- package/dist/scripts/loadZonos.js +1 -1
- package/dist/scripts/zonos.js +1 -1
- package/dist/types/environment.d.ts +4 -0
- package/dist/types/scripts/_getNextFallbackUrl.d.ts +7 -0
- package/dist/types/scripts/_zonosBase.d.ts +2 -0
- package/dist/types/types/LogLoadScriptRequestBody.d.ts +1 -1
- package/dist/zonos-elements/assets/RemoveIcon.svg +1 -1
- package/dist/zonos-elements/index.esm.js +1 -1
- package/dist/zonos-elements/p-89664e49.system.js +1 -0
- package/dist/zonos-elements/p-be2b32f5.entry.js +1 -0
- package/dist/zonos-elements/p-e0bf9666.system.js +1 -1
- package/dist/zonos-elements/p-f38fd0d9.system.entry.js +1 -0
- package/dist/zonos-elements/zonos-elements.esm.js +1 -1
- package/package.json +1 -1
- package/dist/zonos-elements/p-0e6f0bac.system.js +0 -1
- package/dist/zonos-elements/p-5b4c1c09.entry.js +0 -1
- package/dist/zonos-elements/p-f69f1ec6.system.entry.js +0 -1
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -40,6 +40,19 @@ const checkIfLoadVersionDomain = ({ loadScriptSrc }) => {
|
|
|
40
40
|
return { currentLoadScriptUrl, isForceLoadVersionDomain, isWhiteListed };
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
const fallbackList = ['jsdelivr', 'unpkg', 'vercel'];
|
|
44
|
+
/**
|
|
45
|
+
* Get the next cdn type in the fallback list
|
|
46
|
+
* @param currentCdnType The current cdn type that want to get the next fallback url
|
|
47
|
+
*/
|
|
48
|
+
const getNextFallbackUrl = (currentCdnType) => {
|
|
49
|
+
// get current index of the current fail cdn type in the fallback list
|
|
50
|
+
const currentIndex = fallbackList.indexOf(currentCdnType);
|
|
51
|
+
// get the next fallback cdn type
|
|
52
|
+
const nextFallbackCdnType = fallbackList[currentIndex + 1];
|
|
53
|
+
return nextFallbackCdnType || null;
|
|
54
|
+
};
|
|
55
|
+
|
|
43
56
|
/**
|
|
44
57
|
* Extracts the zonosQaUrl from the url
|
|
45
58
|
*
|
|
@@ -236,8 +249,10 @@ const zonosLoadUrl = (() => {
|
|
|
236
249
|
}
|
|
237
250
|
return null;
|
|
238
251
|
})();
|
|
239
|
-
const ZONOS_URL =
|
|
240
|
-
const JS_DELIVR_ZONOS_URL = "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
252
|
+
const ZONOS_URL = "https://v1.3.31.js.zonos.com";
|
|
253
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.31";
|
|
254
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.31";
|
|
255
|
+
const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
|
|
241
256
|
const INTER_FONT_URL = 'https://rsms.me';
|
|
242
257
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
243
258
|
const INTER_FONT_REGEX = /^https:\/\/rsms\.me\/inter\/inter\.css(.*)$/;
|
|
@@ -256,7 +271,7 @@ Zonos.isBigCommerce = false;
|
|
|
256
271
|
*/
|
|
257
272
|
Zonos.isNpm = true;
|
|
258
273
|
Zonos.zonosQaUrl = null;
|
|
259
|
-
Zonos.version = `v${"1.3.
|
|
274
|
+
Zonos.version = `v${"1.3.31"}`;
|
|
260
275
|
Zonos.modeAlerted = false;
|
|
261
276
|
Zonos.tempCartData = null;
|
|
262
277
|
Zonos.getCurrentTimestamp = () => new Date().getTime();
|
|
@@ -400,7 +415,8 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
|
|
|
400
415
|
_a.zonosController = zonosController;
|
|
401
416
|
logError.log('Zonos controller injected!');
|
|
402
417
|
};
|
|
403
|
-
Zonos.injectScript = ({
|
|
418
|
+
Zonos.injectScript = ({ cdnType, isModule, theRestUrl, }) => {
|
|
419
|
+
const scriptDomain = _a.getZonosUrl(cdnType);
|
|
404
420
|
const fullScriptUrl = `${scriptDomain}/${theRestUrl}`;
|
|
405
421
|
const findScript = () => {
|
|
406
422
|
const script = document.querySelector(`script[src="${fullScriptUrl}"]`);
|
|
@@ -423,55 +439,60 @@ Zonos.injectScript = ({ fallBackDomain, isModule, scriptDomain, theRestUrl, }) =
|
|
|
423
439
|
script.src = fullScriptUrl;
|
|
424
440
|
script.crossOrigin = 'anonymous';
|
|
425
441
|
script.onerror = () => {
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
if
|
|
429
|
-
|
|
442
|
+
logError.logError(`Failed to load ${script.src}`);
|
|
443
|
+
const nextFallbackCdnType = getNextFallbackUrl(cdnType);
|
|
444
|
+
// if next fallback cdn type exists, inject the script with the next fallback cdn type
|
|
445
|
+
if (!nextFallbackCdnType) {
|
|
430
446
|
return;
|
|
431
447
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
logError.logError(`Failed to load ${script.src}`);
|
|
448
|
+
_a.injectScript({
|
|
449
|
+
cdnType: nextFallbackCdnType,
|
|
450
|
+
isModule,
|
|
451
|
+
theRestUrl,
|
|
452
|
+
});
|
|
440
453
|
};
|
|
441
454
|
headOrBody.appendChild(script);
|
|
442
455
|
};
|
|
443
456
|
/**
|
|
444
457
|
* We now support loading Zonos via npm. For clients using npm, `zonosBase` will always load from the server side. Therefore, the `zonosLoadUrl` defined earlier won't work since it lacks access to client-side APIs such as `window` and `document`.
|
|
445
458
|
*/
|
|
446
|
-
Zonos.getZonosUrl = () => {
|
|
459
|
+
Zonos.getZonosUrl = (type) => {
|
|
460
|
+
const getUrl = () => {
|
|
461
|
+
switch (type) {
|
|
462
|
+
case 'jsdelivr':
|
|
463
|
+
return JS_DELIVR_ZONOS_URL;
|
|
464
|
+
case 'unpkg':
|
|
465
|
+
return UNPKG_ZONOS_URL;
|
|
466
|
+
default:
|
|
467
|
+
return ZONOS_URL;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
447
470
|
// To ensure that sites using zonos-elements load the script from a specific domain when using npm, we need to check for zonosQaUrl and use it if available. Otherwise it will always load from the compiled versioned domain
|
|
448
471
|
if (_a.isNpm) {
|
|
449
472
|
const zonosQaUrl = getZonosQaUrl();
|
|
450
473
|
// Default to hard coded domain if zonosQaUrl is not available
|
|
451
|
-
return zonosQaUrl ||
|
|
474
|
+
return zonosQaUrl || getUrl();
|
|
452
475
|
}
|
|
453
|
-
return
|
|
476
|
+
return getUrl();
|
|
454
477
|
};
|
|
455
478
|
Zonos.injectZonosCdn = () => {
|
|
456
|
-
const ZONOS_LOAD_URL = _a.getZonosUrl();
|
|
457
479
|
// init zonos elements when the zonosKey is valid
|
|
458
480
|
// inject esmodule cdn for zonos elements
|
|
459
481
|
_a.injectScript({
|
|
460
|
-
|
|
482
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
461
483
|
isModule: true,
|
|
462
|
-
scriptDomain: ZONOS_LOAD_URL,
|
|
463
484
|
theRestUrl: 'dist/zonos-elements/zonos-elements.esm.js',
|
|
464
485
|
});
|
|
465
486
|
// inject non module cdn for zonos elements
|
|
466
487
|
_a.injectScript({
|
|
467
|
-
|
|
488
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
468
489
|
isModule: false,
|
|
469
|
-
scriptDomain: ZONOS_LOAD_URL,
|
|
470
490
|
theRestUrl: 'dist/zonos-elements/zonos-elements.js',
|
|
471
491
|
});
|
|
472
492
|
logError.log('Zonos cdn script injected!');
|
|
473
493
|
};
|
|
474
|
-
Zonos.injectStylesheet = ({
|
|
494
|
+
Zonos.injectStylesheet = ({ cdnType, theRestUrl, }) => {
|
|
495
|
+
const stylesheetDomain = _a.getZonosUrl(cdnType);
|
|
475
496
|
const headOrBody = document.head || document.body;
|
|
476
497
|
// inject preconnect css for zonos elements
|
|
477
498
|
const zonosCssPreconnect = document.createElement('link');
|
|
@@ -483,19 +504,16 @@ Zonos.injectStylesheet = ({ fallBackDomain, stylesheetDomain, theRestUrl, }) =>
|
|
|
483
504
|
zonosCss.rel = 'stylesheet';
|
|
484
505
|
zonosCss.href = `${stylesheetDomain}/${theRestUrl}`;
|
|
485
506
|
zonosCss.onerror = () => {
|
|
486
|
-
|
|
487
|
-
const
|
|
488
|
-
if
|
|
489
|
-
|
|
507
|
+
logError.logError(`Failed to load ${zonosCss.href}`);
|
|
508
|
+
const nextFallbackCdnType = getNextFallbackUrl(cdnType);
|
|
509
|
+
// if the css failed to load, try to load the next fallback cdn if exists
|
|
510
|
+
if (!nextFallbackCdnType) {
|
|
490
511
|
return;
|
|
491
512
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
logError.logError(`Failed to load ${zonosCss.href}`);
|
|
513
|
+
_a.injectStylesheet({
|
|
514
|
+
cdnType: nextFallbackCdnType,
|
|
515
|
+
theRestUrl,
|
|
516
|
+
});
|
|
499
517
|
};
|
|
500
518
|
headOrBody.appendChild(zonosCss);
|
|
501
519
|
};
|
|
@@ -509,8 +527,7 @@ Zonos.injectZonosCss = () => {
|
|
|
509
527
|
}
|
|
510
528
|
// inject css for zonos elements
|
|
511
529
|
_a.injectStylesheet({
|
|
512
|
-
|
|
513
|
-
stylesheetDomain: ZONOS_URL,
|
|
530
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
514
531
|
theRestUrl: 'dist/zonos-elements/zonos-elements.css',
|
|
515
532
|
});
|
|
516
533
|
logError.log('Zonos style css injected!');
|
|
@@ -279,7 +279,6 @@ const ZonosCheckoutFinish = class {
|
|
|
279
279
|
this.notificationTitle = error
|
|
280
280
|
? cart.translate('Payment failed')
|
|
281
281
|
: cart.translate("You're all set!");
|
|
282
|
-
this.notificationActionText = cart.translate('Keep shopping');
|
|
283
282
|
// override title if notification type is success
|
|
284
283
|
this.useOverrideSuccessNotification();
|
|
285
284
|
if (error) {
|
|
@@ -320,7 +319,7 @@ const ZonosCheckoutFinish = class {
|
|
|
320
319
|
this.notificationType = 'success';
|
|
321
320
|
this.notificationTitle = '';
|
|
322
321
|
this.notificationMessages = [];
|
|
323
|
-
this.notificationActionText = '';
|
|
322
|
+
this.notificationActionText = cart.translate('Keep shopping');
|
|
324
323
|
this.order = null;
|
|
325
324
|
}
|
|
326
325
|
componentDidLoad() {
|
|
@@ -342,11 +341,11 @@ const ZonosCheckoutFinish = class {
|
|
|
342
341
|
// const totalItems = this.order?.items?.reduce((acc, item) => {
|
|
343
342
|
// return acc + item.quantity;
|
|
344
343
|
// }, 0);
|
|
345
|
-
return (index.h(index.Host, { key: '
|
|
344
|
+
return (index.h(index.Host, { key: 'c6a7067f7f9c0c58605dbf7e1ac3cc7c469d2688', class: "zonos--checkout-finish zonos--elements", style: {
|
|
346
345
|
'--border-radius': getBorderRadius.getBorderRadius({
|
|
347
346
|
overrideBorderStyle: this.borderRadius,
|
|
348
347
|
}),
|
|
349
|
-
} }, this.isLoading && (index.h("div", { key: '
|
|
348
|
+
} }, this.isLoading && (index.h("div", { key: '5d21e038191edb2135af4fa888c092f35d7d4d13', class: "loading-wrapper" }, index.h("zonos-spinner", { key: 'c2159b75682659e42f22f944a656a55d20e7268e' }))), !this.isLoading && (index.h(index.Fragment, null, index.h("div", { key: 'c51c81e44edad85e69468666a114021ebbd91a64', class: "zonos--group" }, this.notificationType === 'success' ? (index.h("zonos-icon", { "aria-label": "Order success", content: SuccessIcon, iconColor: 'blue-800', size: 50 })) : (index.h("zonos-icon", { "aria-label": "Order failed", content: RemoveIcon, iconColor: 'red-800', size: 50 })), index.h("zonos-text", { key: '5ce3ef22c69de3a56af46541e7f768369378328a', class: "zonos--title", type: "semiBoldSubheader" }, this.notificationTitle), index.h("zonos-text", { key: '1bf1911133314aa6b8dd20b7da91f84be2161b86' }, this.notificationMessages.map(message => (index.h(index.Fragment, null, message, index.h("br", null))))), index.h("zonos-button", { key: 'b5a2311dcca4852b7bee7f9abfa8de868a44fc4c', onClick: () => this.closeClickHandler(), size: "md", variant: "primary" }, this.notificationActionText))))));
|
|
350
349
|
}
|
|
351
350
|
static get assetsDirs() { return ["assets"]; }
|
|
352
351
|
};
|
|
@@ -110,7 +110,6 @@ export class ZonosCheckoutFinish {
|
|
|
110
110
|
this.notificationTitle = error
|
|
111
111
|
? translate('Payment failed')
|
|
112
112
|
: translate("You're all set!");
|
|
113
|
-
this.notificationActionText = translate('Keep shopping');
|
|
114
113
|
// override title if notification type is success
|
|
115
114
|
this.useOverrideSuccessNotification();
|
|
116
115
|
if (error) {
|
|
@@ -151,7 +150,7 @@ export class ZonosCheckoutFinish {
|
|
|
151
150
|
this.notificationType = 'success';
|
|
152
151
|
this.notificationTitle = '';
|
|
153
152
|
this.notificationMessages = [];
|
|
154
|
-
this.notificationActionText = '';
|
|
153
|
+
this.notificationActionText = translate('Keep shopping');
|
|
155
154
|
this.order = null;
|
|
156
155
|
}
|
|
157
156
|
componentDidLoad() {
|
|
@@ -173,11 +172,11 @@ export class ZonosCheckoutFinish {
|
|
|
173
172
|
// const totalItems = this.order?.items?.reduce((acc, item) => {
|
|
174
173
|
// return acc + item.quantity;
|
|
175
174
|
// }, 0);
|
|
176
|
-
return (h(Host, { key: '
|
|
175
|
+
return (h(Host, { key: 'c6a7067f7f9c0c58605dbf7e1ac3cc7c469d2688', class: "zonos--checkout-finish zonos--elements", style: {
|
|
177
176
|
'--border-radius': getBorderRadius({
|
|
178
177
|
overrideBorderStyle: this.borderRadius,
|
|
179
178
|
}),
|
|
180
|
-
} }, this.isLoading && (h("div", { key: '
|
|
179
|
+
} }, this.isLoading && (h("div", { key: '5d21e038191edb2135af4fa888c092f35d7d4d13', class: "loading-wrapper" }, h("zonos-spinner", { key: 'c2159b75682659e42f22f944a656a55d20e7268e' }))), !this.isLoading && (h(Fragment, null, h("div", { key: 'c51c81e44edad85e69468666a114021ebbd91a64', class: "zonos--group" }, this.notificationType === 'success' ? (h("zonos-icon", { "aria-label": "Order success", content: SuccessIcon, iconColor: 'blue-800', size: 50 })) : (h("zonos-icon", { "aria-label": "Order failed", content: RemoveIcon, iconColor: 'red-800', size: 50 })), h("zonos-text", { key: '5ce3ef22c69de3a56af46541e7f768369378328a', class: "zonos--title", type: "semiBoldSubheader" }, this.notificationTitle), h("zonos-text", { key: '1bf1911133314aa6b8dd20b7da91f84be2161b86' }, this.notificationMessages.map(message => (h(Fragment, null, message, h("br", null))))), h("zonos-button", { key: 'b5a2311dcca4852b7bee7f9abfa8de868a44fc4c', onClick: () => this.closeClickHandler(), size: "md", variant: "primary" }, this.notificationActionText))))));
|
|
181
180
|
}
|
|
182
181
|
static get is() { return "zonos-checkout-finish"; }
|
|
183
182
|
static get encapsulation() { return "shadow"; }
|
|
@@ -17,6 +17,10 @@ export const isVercelProd = inVercel && process.env.VERCEL_ENV === 'production';
|
|
|
17
17
|
const packageVersion = `${process.env.npm_package_version}` ||
|
|
18
18
|
process.env.NEXT_PUBLIC_ZONOS_PACKAGE_VERSION;
|
|
19
19
|
const JS_DELIVR_ZONOS_URL = `https://cdn.jsdelivr.net/npm/@zonos/elements@${packageVersion}`;
|
|
20
|
+
/**
|
|
21
|
+
* @example https://unpkg.com/@zonos/elements@1.3.15/dist/scripts/zonos.js
|
|
22
|
+
*/
|
|
23
|
+
const UNPKG_ZONOS_URL = `https://unpkg.com/@zonos/elements@${packageVersion}`;
|
|
20
24
|
const currentBranch = process.env.VERCEL_GIT_COMMIT_REF || process.env.BRANCH_NAME;
|
|
21
25
|
export const formattedUrl = ({ branchName, inCI: _inCI, inVercel: _inVercel, isVercelPreview: _isVercelPreview, packageVersion: _packageVersion, type = 'full', url, }) => {
|
|
22
26
|
if (!url) {
|
|
@@ -122,6 +126,7 @@ const envClient = {
|
|
|
122
126
|
NEXT_PUBLIC_ZONOS_JS_DELIVR_CDN_URL: z.string(),
|
|
123
127
|
NEXT_PUBLIC_ZONOS_PACKAGE_VERSION: z.string(),
|
|
124
128
|
NEXT_PUBLIC_ZONOS_ROUTE_URL: z.string(),
|
|
129
|
+
NEXT_PUBLIC_ZONOS_UNPKG_CDN_URL: z.string(),
|
|
125
130
|
};
|
|
126
131
|
const envClientSchema = z.object(envClient);
|
|
127
132
|
export const env = createEnv({
|
|
@@ -169,6 +174,7 @@ export const env = createEnv({
|
|
|
169
174
|
type: 'major',
|
|
170
175
|
url: process.env.NEXT_PUBLIC_ZONOS_ROUTE_URL,
|
|
171
176
|
}),
|
|
177
|
+
NEXT_PUBLIC_ZONOS_UNPKG_CDN_URL: UNPKG_ZONOS_URL,
|
|
172
178
|
},
|
|
173
179
|
});
|
|
174
180
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const fallbackList = ['jsdelivr', 'unpkg', 'vercel'];
|
|
2
|
+
/**
|
|
3
|
+
* Get the next cdn type in the fallback list
|
|
4
|
+
* @param currentCdnType The current cdn type that want to get the next fallback url
|
|
5
|
+
*/
|
|
6
|
+
export const getNextFallbackUrl = (currentCdnType) => {
|
|
7
|
+
// get current index of the current fail cdn type in the fallback list
|
|
8
|
+
const currentIndex = fallbackList.indexOf(currentCdnType);
|
|
9
|
+
// get the next fallback cdn type
|
|
10
|
+
const nextFallbackCdnType = fallbackList[currentIndex + 1];
|
|
11
|
+
return nextFallbackCdnType || null;
|
|
12
|
+
};
|
|
@@ -2,6 +2,7 @@ var _a;
|
|
|
2
2
|
import { log } from "../components/utils/logging/log";
|
|
3
3
|
import { logError } from "../components/utils/logging/logError";
|
|
4
4
|
import { checkIfLoadVersionDomain } from "./_checkIfLoadVersionDomain";
|
|
5
|
+
import { getNextFallbackUrl, } from "./_getNextFallbackUrl";
|
|
5
6
|
import { getZonosQaUrl } from "./_getZonosQaUrl";
|
|
6
7
|
import { zonosLoadStripe } from "./_loadStripe";
|
|
7
8
|
/**
|
|
@@ -20,8 +21,10 @@ const zonosLoadUrl = (() => {
|
|
|
20
21
|
}
|
|
21
22
|
return null;
|
|
22
23
|
})();
|
|
23
|
-
const ZONOS_URL =
|
|
24
|
-
const JS_DELIVR_ZONOS_URL = process.env.NEXT_PUBLIC_ZONOS_JS_DELIVR_CDN_URL;
|
|
24
|
+
const ZONOS_URL = process.env.NEXT_PUBLIC_ZONOS_CDN_URL;
|
|
25
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || process.env.NEXT_PUBLIC_ZONOS_JS_DELIVR_CDN_URL;
|
|
26
|
+
const UNPKG_ZONOS_URL = process.env.NEXT_PUBLIC_ZONOS_UNPKG_CDN_URL;
|
|
27
|
+
export const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
|
|
25
28
|
const INTER_FONT_URL = 'https://rsms.me';
|
|
26
29
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
27
30
|
const INTER_FONT_REGEX = /^https:\/\/rsms\.me\/inter\/inter\.css(.*)$/;
|
|
@@ -184,7 +187,8 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
|
|
|
184
187
|
_a.zonosController = zonosController;
|
|
185
188
|
log('Zonos controller injected!');
|
|
186
189
|
};
|
|
187
|
-
Zonos.injectScript = ({
|
|
190
|
+
Zonos.injectScript = ({ cdnType, isModule, theRestUrl, }) => {
|
|
191
|
+
const scriptDomain = _a.getZonosUrl(cdnType);
|
|
188
192
|
const fullScriptUrl = `${scriptDomain}/${theRestUrl}`;
|
|
189
193
|
const findScript = () => {
|
|
190
194
|
const script = document.querySelector(`script[src="${fullScriptUrl}"]`);
|
|
@@ -207,55 +211,60 @@ Zonos.injectScript = ({ fallBackDomain, isModule, scriptDomain, theRestUrl, }) =
|
|
|
207
211
|
script.src = fullScriptUrl;
|
|
208
212
|
script.crossOrigin = 'anonymous';
|
|
209
213
|
script.onerror = () => {
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
if
|
|
213
|
-
|
|
214
|
+
logError(`Failed to load ${script.src}`);
|
|
215
|
+
const nextFallbackCdnType = getNextFallbackUrl(cdnType);
|
|
216
|
+
// if next fallback cdn type exists, inject the script with the next fallback cdn type
|
|
217
|
+
if (!nextFallbackCdnType) {
|
|
214
218
|
return;
|
|
215
219
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
logError(`Failed to load ${script.src}`);
|
|
220
|
+
_a.injectScript({
|
|
221
|
+
cdnType: nextFallbackCdnType,
|
|
222
|
+
isModule,
|
|
223
|
+
theRestUrl,
|
|
224
|
+
});
|
|
224
225
|
};
|
|
225
226
|
headOrBody.appendChild(script);
|
|
226
227
|
};
|
|
227
228
|
/**
|
|
228
229
|
* We now support loading Zonos via npm. For clients using npm, `zonosBase` will always load from the server side. Therefore, the `zonosLoadUrl` defined earlier won't work since it lacks access to client-side APIs such as `window` and `document`.
|
|
229
230
|
*/
|
|
230
|
-
Zonos.getZonosUrl = () => {
|
|
231
|
+
Zonos.getZonosUrl = (type) => {
|
|
232
|
+
const getUrl = () => {
|
|
233
|
+
switch (type) {
|
|
234
|
+
case 'jsdelivr':
|
|
235
|
+
return JS_DELIVR_ZONOS_URL;
|
|
236
|
+
case 'unpkg':
|
|
237
|
+
return UNPKG_ZONOS_URL;
|
|
238
|
+
default:
|
|
239
|
+
return ZONOS_URL;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
231
242
|
// To ensure that sites using zonos-elements load the script from a specific domain when using npm, we need to check for zonosQaUrl and use it if available. Otherwise it will always load from the compiled versioned domain
|
|
232
243
|
if (_a.isNpm) {
|
|
233
244
|
const zonosQaUrl = getZonosQaUrl();
|
|
234
245
|
// Default to hard coded domain if zonosQaUrl is not available
|
|
235
|
-
return zonosQaUrl ||
|
|
246
|
+
return zonosQaUrl || getUrl();
|
|
236
247
|
}
|
|
237
|
-
return
|
|
248
|
+
return getUrl();
|
|
238
249
|
};
|
|
239
250
|
Zonos.injectZonosCdn = () => {
|
|
240
|
-
const ZONOS_LOAD_URL = _a.getZonosUrl();
|
|
241
251
|
// init zonos elements when the zonosKey is valid
|
|
242
252
|
// inject esmodule cdn for zonos elements
|
|
243
253
|
_a.injectScript({
|
|
244
|
-
|
|
254
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
245
255
|
isModule: true,
|
|
246
|
-
scriptDomain: ZONOS_LOAD_URL,
|
|
247
256
|
theRestUrl: 'dist/zonos-elements/zonos-elements.esm.js',
|
|
248
257
|
});
|
|
249
258
|
// inject non module cdn for zonos elements
|
|
250
259
|
_a.injectScript({
|
|
251
|
-
|
|
260
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
252
261
|
isModule: false,
|
|
253
|
-
scriptDomain: ZONOS_LOAD_URL,
|
|
254
262
|
theRestUrl: 'dist/zonos-elements/zonos-elements.js',
|
|
255
263
|
});
|
|
256
264
|
log('Zonos cdn script injected!');
|
|
257
265
|
};
|
|
258
|
-
Zonos.injectStylesheet = ({
|
|
266
|
+
Zonos.injectStylesheet = ({ cdnType, theRestUrl, }) => {
|
|
267
|
+
const stylesheetDomain = _a.getZonosUrl(cdnType);
|
|
259
268
|
const headOrBody = document.head || document.body;
|
|
260
269
|
// inject preconnect css for zonos elements
|
|
261
270
|
const zonosCssPreconnect = document.createElement('link');
|
|
@@ -267,19 +276,16 @@ Zonos.injectStylesheet = ({ fallBackDomain, stylesheetDomain, theRestUrl, }) =>
|
|
|
267
276
|
zonosCss.rel = 'stylesheet';
|
|
268
277
|
zonosCss.href = `${stylesheetDomain}/${theRestUrl}`;
|
|
269
278
|
zonosCss.onerror = () => {
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
if
|
|
273
|
-
|
|
279
|
+
logError(`Failed to load ${zonosCss.href}`);
|
|
280
|
+
const nextFallbackCdnType = getNextFallbackUrl(cdnType);
|
|
281
|
+
// if the css failed to load, try to load the next fallback cdn if exists
|
|
282
|
+
if (!nextFallbackCdnType) {
|
|
274
283
|
return;
|
|
275
284
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
logError(`Failed to load ${zonosCss.href}`);
|
|
285
|
+
_a.injectStylesheet({
|
|
286
|
+
cdnType: nextFallbackCdnType,
|
|
287
|
+
theRestUrl,
|
|
288
|
+
});
|
|
283
289
|
};
|
|
284
290
|
headOrBody.appendChild(zonosCss);
|
|
285
291
|
};
|
|
@@ -293,8 +299,7 @@ Zonos.injectZonosCss = () => {
|
|
|
293
299
|
}
|
|
294
300
|
// inject css for zonos elements
|
|
295
301
|
_a.injectStylesheet({
|
|
296
|
-
|
|
297
|
-
stylesheetDomain: ZONOS_URL,
|
|
302
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
298
303
|
theRestUrl: 'dist/zonos-elements/zonos-elements.css',
|
|
299
304
|
});
|
|
300
305
|
log('Zonos style css injected!');
|
package/dist/esm/index.js
CHANGED
|
@@ -36,6 +36,19 @@ const checkIfLoadVersionDomain = ({ loadScriptSrc }) => {
|
|
|
36
36
|
return { currentLoadScriptUrl, isForceLoadVersionDomain, isWhiteListed };
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const fallbackList = ['jsdelivr', 'unpkg', 'vercel'];
|
|
40
|
+
/**
|
|
41
|
+
* Get the next cdn type in the fallback list
|
|
42
|
+
* @param currentCdnType The current cdn type that want to get the next fallback url
|
|
43
|
+
*/
|
|
44
|
+
const getNextFallbackUrl = (currentCdnType) => {
|
|
45
|
+
// get current index of the current fail cdn type in the fallback list
|
|
46
|
+
const currentIndex = fallbackList.indexOf(currentCdnType);
|
|
47
|
+
// get the next fallback cdn type
|
|
48
|
+
const nextFallbackCdnType = fallbackList[currentIndex + 1];
|
|
49
|
+
return nextFallbackCdnType || null;
|
|
50
|
+
};
|
|
51
|
+
|
|
39
52
|
/**
|
|
40
53
|
* Extracts the zonosQaUrl from the url
|
|
41
54
|
*
|
|
@@ -232,8 +245,10 @@ const zonosLoadUrl = (() => {
|
|
|
232
245
|
}
|
|
233
246
|
return null;
|
|
234
247
|
})();
|
|
235
|
-
const ZONOS_URL =
|
|
236
|
-
const JS_DELIVR_ZONOS_URL = "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.
|
|
248
|
+
const ZONOS_URL = "https://v1.3.31.js.zonos.com";
|
|
249
|
+
const JS_DELIVR_ZONOS_URL = zonosLoadUrl || "https://cdn.jsdelivr.net/npm/@zonos/elements@1.3.31";
|
|
250
|
+
const UNPKG_ZONOS_URL = "https://unpkg.com/@zonos/elements@1.3.31";
|
|
251
|
+
const MAIN_LOAD_CDN_TYPE = 'jsdelivr';
|
|
237
252
|
const INTER_FONT_URL = 'https://rsms.me';
|
|
238
253
|
const GOOGLE_FONT_URL = 'https://fonts.googleapis.com';
|
|
239
254
|
const INTER_FONT_REGEX = /^https:\/\/rsms\.me\/inter\/inter\.css(.*)$/;
|
|
@@ -252,7 +267,7 @@ Zonos.isBigCommerce = false;
|
|
|
252
267
|
*/
|
|
253
268
|
Zonos.isNpm = true;
|
|
254
269
|
Zonos.zonosQaUrl = null;
|
|
255
|
-
Zonos.version = `v${"1.3.
|
|
270
|
+
Zonos.version = `v${"1.3.31"}`;
|
|
256
271
|
Zonos.modeAlerted = false;
|
|
257
272
|
Zonos.tempCartData = null;
|
|
258
273
|
Zonos.getCurrentTimestamp = () => new Date().getTime();
|
|
@@ -396,7 +411,8 @@ Zonos.injectController = ({ config, zonosApiKey, }) => {
|
|
|
396
411
|
_a.zonosController = zonosController;
|
|
397
412
|
log('Zonos controller injected!');
|
|
398
413
|
};
|
|
399
|
-
Zonos.injectScript = ({
|
|
414
|
+
Zonos.injectScript = ({ cdnType, isModule, theRestUrl, }) => {
|
|
415
|
+
const scriptDomain = _a.getZonosUrl(cdnType);
|
|
400
416
|
const fullScriptUrl = `${scriptDomain}/${theRestUrl}`;
|
|
401
417
|
const findScript = () => {
|
|
402
418
|
const script = document.querySelector(`script[src="${fullScriptUrl}"]`);
|
|
@@ -419,55 +435,60 @@ Zonos.injectScript = ({ fallBackDomain, isModule, scriptDomain, theRestUrl, }) =
|
|
|
419
435
|
script.src = fullScriptUrl;
|
|
420
436
|
script.crossOrigin = 'anonymous';
|
|
421
437
|
script.onerror = () => {
|
|
422
|
-
|
|
423
|
-
const
|
|
424
|
-
if
|
|
425
|
-
|
|
438
|
+
logError(`Failed to load ${script.src}`);
|
|
439
|
+
const nextFallbackCdnType = getNextFallbackUrl(cdnType);
|
|
440
|
+
// if next fallback cdn type exists, inject the script with the next fallback cdn type
|
|
441
|
+
if (!nextFallbackCdnType) {
|
|
426
442
|
return;
|
|
427
443
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
logError(`Failed to load ${script.src}`);
|
|
444
|
+
_a.injectScript({
|
|
445
|
+
cdnType: nextFallbackCdnType,
|
|
446
|
+
isModule,
|
|
447
|
+
theRestUrl,
|
|
448
|
+
});
|
|
436
449
|
};
|
|
437
450
|
headOrBody.appendChild(script);
|
|
438
451
|
};
|
|
439
452
|
/**
|
|
440
453
|
* We now support loading Zonos via npm. For clients using npm, `zonosBase` will always load from the server side. Therefore, the `zonosLoadUrl` defined earlier won't work since it lacks access to client-side APIs such as `window` and `document`.
|
|
441
454
|
*/
|
|
442
|
-
Zonos.getZonosUrl = () => {
|
|
455
|
+
Zonos.getZonosUrl = (type) => {
|
|
456
|
+
const getUrl = () => {
|
|
457
|
+
switch (type) {
|
|
458
|
+
case 'jsdelivr':
|
|
459
|
+
return JS_DELIVR_ZONOS_URL;
|
|
460
|
+
case 'unpkg':
|
|
461
|
+
return UNPKG_ZONOS_URL;
|
|
462
|
+
default:
|
|
463
|
+
return ZONOS_URL;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
443
466
|
// To ensure that sites using zonos-elements load the script from a specific domain when using npm, we need to check for zonosQaUrl and use it if available. Otherwise it will always load from the compiled versioned domain
|
|
444
467
|
if (_a.isNpm) {
|
|
445
468
|
const zonosQaUrl = getZonosQaUrl();
|
|
446
469
|
// Default to hard coded domain if zonosQaUrl is not available
|
|
447
|
-
return zonosQaUrl ||
|
|
470
|
+
return zonosQaUrl || getUrl();
|
|
448
471
|
}
|
|
449
|
-
return
|
|
472
|
+
return getUrl();
|
|
450
473
|
};
|
|
451
474
|
Zonos.injectZonosCdn = () => {
|
|
452
|
-
const ZONOS_LOAD_URL = _a.getZonosUrl();
|
|
453
475
|
// init zonos elements when the zonosKey is valid
|
|
454
476
|
// inject esmodule cdn for zonos elements
|
|
455
477
|
_a.injectScript({
|
|
456
|
-
|
|
478
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
457
479
|
isModule: true,
|
|
458
|
-
scriptDomain: ZONOS_LOAD_URL,
|
|
459
480
|
theRestUrl: 'dist/zonos-elements/zonos-elements.esm.js',
|
|
460
481
|
});
|
|
461
482
|
// inject non module cdn for zonos elements
|
|
462
483
|
_a.injectScript({
|
|
463
|
-
|
|
484
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
464
485
|
isModule: false,
|
|
465
|
-
scriptDomain: ZONOS_LOAD_URL,
|
|
466
486
|
theRestUrl: 'dist/zonos-elements/zonos-elements.js',
|
|
467
487
|
});
|
|
468
488
|
log('Zonos cdn script injected!');
|
|
469
489
|
};
|
|
470
|
-
Zonos.injectStylesheet = ({
|
|
490
|
+
Zonos.injectStylesheet = ({ cdnType, theRestUrl, }) => {
|
|
491
|
+
const stylesheetDomain = _a.getZonosUrl(cdnType);
|
|
471
492
|
const headOrBody = document.head || document.body;
|
|
472
493
|
// inject preconnect css for zonos elements
|
|
473
494
|
const zonosCssPreconnect = document.createElement('link');
|
|
@@ -479,19 +500,16 @@ Zonos.injectStylesheet = ({ fallBackDomain, stylesheetDomain, theRestUrl, }) =>
|
|
|
479
500
|
zonosCss.rel = 'stylesheet';
|
|
480
501
|
zonosCss.href = `${stylesheetDomain}/${theRestUrl}`;
|
|
481
502
|
zonosCss.onerror = () => {
|
|
482
|
-
|
|
483
|
-
const
|
|
484
|
-
if
|
|
485
|
-
|
|
503
|
+
logError(`Failed to load ${zonosCss.href}`);
|
|
504
|
+
const nextFallbackCdnType = getNextFallbackUrl(cdnType);
|
|
505
|
+
// if the css failed to load, try to load the next fallback cdn if exists
|
|
506
|
+
if (!nextFallbackCdnType) {
|
|
486
507
|
return;
|
|
487
508
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
logError(`Failed to load ${zonosCss.href}`);
|
|
509
|
+
_a.injectStylesheet({
|
|
510
|
+
cdnType: nextFallbackCdnType,
|
|
511
|
+
theRestUrl,
|
|
512
|
+
});
|
|
495
513
|
};
|
|
496
514
|
headOrBody.appendChild(zonosCss);
|
|
497
515
|
};
|
|
@@ -505,8 +523,7 @@ Zonos.injectZonosCss = () => {
|
|
|
505
523
|
}
|
|
506
524
|
// inject css for zonos elements
|
|
507
525
|
_a.injectStylesheet({
|
|
508
|
-
|
|
509
|
-
stylesheetDomain: ZONOS_URL,
|
|
526
|
+
cdnType: MAIN_LOAD_CDN_TYPE,
|
|
510
527
|
theRestUrl: 'dist/zonos-elements/zonos-elements.css',
|
|
511
528
|
});
|
|
512
529
|
log('Zonos style css injected!');
|
|
@@ -275,7 +275,6 @@ const ZonosCheckoutFinish = class {
|
|
|
275
275
|
this.notificationTitle = error
|
|
276
276
|
? translate('Payment failed')
|
|
277
277
|
: translate("You're all set!");
|
|
278
|
-
this.notificationActionText = translate('Keep shopping');
|
|
279
278
|
// override title if notification type is success
|
|
280
279
|
this.useOverrideSuccessNotification();
|
|
281
280
|
if (error) {
|
|
@@ -316,7 +315,7 @@ const ZonosCheckoutFinish = class {
|
|
|
316
315
|
this.notificationType = 'success';
|
|
317
316
|
this.notificationTitle = '';
|
|
318
317
|
this.notificationMessages = [];
|
|
319
|
-
this.notificationActionText = '';
|
|
318
|
+
this.notificationActionText = translate('Keep shopping');
|
|
320
319
|
this.order = null;
|
|
321
320
|
}
|
|
322
321
|
componentDidLoad() {
|
|
@@ -338,11 +337,11 @@ const ZonosCheckoutFinish = class {
|
|
|
338
337
|
// const totalItems = this.order?.items?.reduce((acc, item) => {
|
|
339
338
|
// return acc + item.quantity;
|
|
340
339
|
// }, 0);
|
|
341
|
-
return (h(Host, { key: '
|
|
340
|
+
return (h(Host, { key: 'c6a7067f7f9c0c58605dbf7e1ac3cc7c469d2688', class: "zonos--checkout-finish zonos--elements", style: {
|
|
342
341
|
'--border-radius': getBorderRadius({
|
|
343
342
|
overrideBorderStyle: this.borderRadius,
|
|
344
343
|
}),
|
|
345
|
-
} }, this.isLoading && (h("div", { key: '
|
|
344
|
+
} }, this.isLoading && (h("div", { key: '5d21e038191edb2135af4fa888c092f35d7d4d13', class: "loading-wrapper" }, h("zonos-spinner", { key: 'c2159b75682659e42f22f944a656a55d20e7268e' }))), !this.isLoading && (h(Fragment, null, h("div", { key: 'c51c81e44edad85e69468666a114021ebbd91a64', class: "zonos--group" }, this.notificationType === 'success' ? (h("zonos-icon", { "aria-label": "Order success", content: SuccessIcon, iconColor: 'blue-800', size: 50 })) : (h("zonos-icon", { "aria-label": "Order failed", content: RemoveIcon, iconColor: 'red-800', size: 50 })), h("zonos-text", { key: '5ce3ef22c69de3a56af46541e7f768369378328a', class: "zonos--title", type: "semiBoldSubheader" }, this.notificationTitle), h("zonos-text", { key: '1bf1911133314aa6b8dd20b7da91f84be2161b86' }, this.notificationMessages.map(message => (h(Fragment, null, message, h("br", null))))), h("zonos-button", { key: 'b5a2311dcca4852b7bee7f9abfa8de868a44fc4c', onClick: () => this.closeClickHandler(), size: "md", variant: "primary" }, this.notificationActionText))))));
|
|
346
345
|
}
|
|
347
346
|
static get assetsDirs() { return ["assets"]; }
|
|
348
347
|
};
|