@blotoutio/providers-blotout-wallet-sdk 0.62.0 → 0.63.0
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/index.cjs.js +229 -140
- package/index.js +229 -140
- package/index.mjs +229 -140
- package/package.json +1 -1
- package/stores/shopify/index.cjs.js +4 -37
- package/stores/shopify/index.js +4 -37
- package/stores/shopify/index.mjs +4 -37
package/index.mjs
CHANGED
@@ -34,6 +34,54 @@ new Set([
|
|
34
34
|
|
35
35
|
const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
|
36
36
|
|
37
|
+
const createEnabled = () => ({
|
38
|
+
name: 'enabled',
|
39
|
+
groupNames: new Set(),
|
40
|
+
segment: 0,
|
41
|
+
groupName: '',
|
42
|
+
isEnabled: true,
|
43
|
+
});
|
44
|
+
const createDisabled = () => ({
|
45
|
+
name: 'disabled',
|
46
|
+
groupNames: new Set(),
|
47
|
+
segment: 0,
|
48
|
+
groupName: '',
|
49
|
+
isEnabled: false,
|
50
|
+
});
|
51
|
+
const createABTest = ({ userId }) => {
|
52
|
+
const [sample] = userId.split('-');
|
53
|
+
const segment = parseInt(sample, 16) % 2;
|
54
|
+
return {
|
55
|
+
name: 'ab-test',
|
56
|
+
groupNames: new Set(['enabled', 'control']),
|
57
|
+
segment,
|
58
|
+
groupName: segment == 1 ? 'enabled' : 'control',
|
59
|
+
isEnabled: segment == 1,
|
60
|
+
};
|
61
|
+
};
|
62
|
+
const createPreview = ({ previewKey, userPreviewKey }) => {
|
63
|
+
const isEnabled = !!(previewKey && previewKey === userPreviewKey);
|
64
|
+
return {
|
65
|
+
name: 'preview',
|
66
|
+
groupNames: new Set(['preview']),
|
67
|
+
groupName: isEnabled ? 'preview' : '',
|
68
|
+
segment: isEnabled ? 1 : 0,
|
69
|
+
isEnabled,
|
70
|
+
};
|
71
|
+
};
|
72
|
+
const createExperiment = (props) => {
|
73
|
+
switch (props.name) {
|
74
|
+
case 'enabled':
|
75
|
+
return createEnabled();
|
76
|
+
case 'disabled':
|
77
|
+
return createDisabled();
|
78
|
+
case 'ab-test':
|
79
|
+
return createABTest(props);
|
80
|
+
case 'preview':
|
81
|
+
return createPreview(props);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
37
85
|
const customAttributes = {
|
38
86
|
'--bw-primary': { type: 'color', defaultValue: '#000000' },
|
39
87
|
'--bw-title-color': { type: 'color', defaultValue: '#000000' },
|
@@ -59,143 +107,37 @@ const customAttributes = {
|
|
59
107
|
};
|
60
108
|
|
61
109
|
const packageName = 'blotoutWallet';
|
62
|
-
const
|
63
|
-
const cartTokenTwoCookie = 'cart2';
|
64
|
-
const cartTokenLinkCookie = 'bwCartLinkToken';
|
110
|
+
const PREVIEW_KEY_NAME = '_blotoutWalletPreview';
|
65
111
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if (!document || !document.cookie) {
|
70
|
-
return '';
|
71
|
-
}
|
72
|
-
const cookies = parseCookies(document.cookie);
|
73
|
-
return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
|
74
|
-
}
|
75
|
-
catch {
|
76
|
-
return '';
|
77
|
-
}
|
78
|
-
};
|
79
|
-
const parseCookies = (cookie) => {
|
80
|
-
return Object.fromEntries(cookie
|
81
|
-
.split(/;\s+/)
|
82
|
-
.map((r) => r.split('=').map((str) => str.trim()))
|
83
|
-
.map(([cookieKey, cookieValue]) => {
|
84
|
-
if (!cookieKey) {
|
85
|
-
return [];
|
86
|
-
}
|
87
|
-
let decodedValue = '';
|
88
|
-
if (cookieValue) {
|
89
|
-
try {
|
90
|
-
decodedValue = decodeURIComponent(cookieValue);
|
91
|
-
}
|
92
|
-
catch (e) {
|
93
|
-
console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
|
94
|
-
decodedValue = cookieValue;
|
95
|
-
}
|
96
|
-
}
|
97
|
-
return [cookieKey, decodedValue];
|
98
|
-
}));
|
99
|
-
};
|
100
|
-
const setCookie = (key, value, options) => {
|
101
|
-
var _a;
|
102
|
-
try {
|
103
|
-
if (!document) {
|
104
|
-
return;
|
105
|
-
}
|
106
|
-
const extras = [`path=${(_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : '/'}`];
|
107
|
-
if (options === null || options === void 0 ? void 0 : options['maxAge']) {
|
108
|
-
extras.push(`max-age=${options['maxAge']}`);
|
109
|
-
}
|
110
|
-
if (options === null || options === void 0 ? void 0 : options.expires) {
|
111
|
-
extras.push(`expires=${options.expires}`);
|
112
|
-
}
|
113
|
-
if (options === null || options === void 0 ? void 0 : options.partitioned) {
|
114
|
-
extras.push('partitioned');
|
115
|
-
}
|
116
|
-
if (options === null || options === void 0 ? void 0 : options.samesite) {
|
117
|
-
extras.push(`samesite=${options.samesite}`);
|
118
|
-
}
|
119
|
-
if (options === null || options === void 0 ? void 0 : options.secure) {
|
120
|
-
extras.push('secure');
|
121
|
-
}
|
122
|
-
document.cookie = `${key}=${value};${extras.join(';')}`;
|
123
|
-
}
|
124
|
-
catch {
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
};
|
112
|
+
var _a;
|
113
|
+
const registryKey = Symbol.for('blotout-wallet');
|
114
|
+
(_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
|
128
115
|
|
129
|
-
|
116
|
+
// eslint-disable-next-line @nx/enforce-module-boundaries
|
117
|
+
const getPreviewKey = () => {
|
118
|
+
let key = null;
|
130
119
|
try {
|
131
|
-
|
120
|
+
key = localStorage.getItem(PREVIEW_KEY_NAME) || null;
|
132
121
|
}
|
133
122
|
catch {
|
134
|
-
|
123
|
+
/* do nothing */
|
135
124
|
}
|
125
|
+
return key;
|
136
126
|
};
|
137
|
-
const logger = {
|
138
|
-
log: (...args) => {
|
139
|
-
if (canLog()) {
|
140
|
-
console.log(...args);
|
141
|
-
}
|
142
|
-
},
|
143
|
-
error: (...args) => {
|
144
|
-
if (canLog()) {
|
145
|
-
console.error(...args);
|
146
|
-
}
|
147
|
-
},
|
148
|
-
info: (...args) => {
|
149
|
-
if (canLog()) {
|
150
|
-
console.info(...args);
|
151
|
-
}
|
152
|
-
},
|
153
|
-
trace: (...args) => {
|
154
|
-
if (canLog()) {
|
155
|
-
console.trace(...args);
|
156
|
-
}
|
157
|
-
},
|
158
|
-
table: (...args) => {
|
159
|
-
if (canLog()) {
|
160
|
-
console.table(...args);
|
161
|
-
}
|
162
|
-
},
|
163
|
-
dir: (...args) => {
|
164
|
-
if (canLog()) {
|
165
|
-
console.dir(...args);
|
166
|
-
}
|
167
|
-
},
|
168
|
-
};
|
169
|
-
|
170
|
-
var _a;
|
171
|
-
const registryKey = Symbol.for('blotout-wallet');
|
172
|
-
(_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
|
173
127
|
|
174
|
-
|
175
|
-
const
|
128
|
+
const tag = () => {
|
129
|
+
const result = {
|
130
|
+
cartToken: null,
|
131
|
+
previewKey: getPreviewKey(),
|
132
|
+
};
|
176
133
|
if (!window) {
|
177
|
-
return;
|
134
|
+
return result;
|
178
135
|
}
|
179
|
-
const
|
180
|
-
|
181
|
-
|
182
|
-
let cartToken = getCookieValue(cartTokenCookie);
|
183
|
-
const cartTokenLink = getCookieValue(cartTokenLinkCookie);
|
184
|
-
if (!cartToken) {
|
185
|
-
cartToken = getCookieValue(cartTokenTwoCookie);
|
186
|
-
}
|
187
|
-
if (eventName === 'Purchase') {
|
188
|
-
setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
|
189
|
-
}
|
190
|
-
if (cartTokenLink) {
|
191
|
-
setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
|
192
|
-
}
|
193
|
-
return { cartToken, cartTokenLink };
|
194
|
-
}
|
195
|
-
default: {
|
196
|
-
return {};
|
197
|
-
}
|
136
|
+
const store = window[registryKey].storeAPI;
|
137
|
+
if (store) {
|
138
|
+
result.cartToken = store.getCartToken();
|
198
139
|
}
|
140
|
+
return result;
|
199
141
|
};
|
200
142
|
|
201
143
|
/******************************************************************************
|
@@ -415,6 +357,111 @@ const flipIn = (element) => {
|
|
415
357
|
return animation.finished;
|
416
358
|
};
|
417
359
|
|
360
|
+
const getCookieValue = (key) => {
|
361
|
+
var _a;
|
362
|
+
try {
|
363
|
+
if (!document || !document.cookie) {
|
364
|
+
return '';
|
365
|
+
}
|
366
|
+
const cookies = parseCookies(document.cookie);
|
367
|
+
return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
|
368
|
+
}
|
369
|
+
catch {
|
370
|
+
return '';
|
371
|
+
}
|
372
|
+
};
|
373
|
+
const parseCookies = (cookie) => {
|
374
|
+
return Object.fromEntries(cookie
|
375
|
+
.split(/;\s+/)
|
376
|
+
.map((r) => r.split('=').map((str) => str.trim()))
|
377
|
+
.map(([cookieKey, ...cookieValues]) => {
|
378
|
+
const cookieValue = cookieValues.join('=');
|
379
|
+
if (!cookieKey) {
|
380
|
+
return [];
|
381
|
+
}
|
382
|
+
let decodedValue = '';
|
383
|
+
if (cookieValue) {
|
384
|
+
try {
|
385
|
+
decodedValue = decodeURIComponent(cookieValue);
|
386
|
+
}
|
387
|
+
catch (e) {
|
388
|
+
console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
|
389
|
+
decodedValue = cookieValue;
|
390
|
+
}
|
391
|
+
}
|
392
|
+
return [cookieKey, decodedValue];
|
393
|
+
}));
|
394
|
+
};
|
395
|
+
const setCookie = (key, value, options) => {
|
396
|
+
var _a;
|
397
|
+
try {
|
398
|
+
if (!document) {
|
399
|
+
return;
|
400
|
+
}
|
401
|
+
const extras = [`path=${(_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : '/'}`];
|
402
|
+
if (options === null || options === void 0 ? void 0 : options['maxAge']) {
|
403
|
+
extras.push(`max-age=${options['maxAge']}`);
|
404
|
+
}
|
405
|
+
if (options === null || options === void 0 ? void 0 : options.expires) {
|
406
|
+
extras.push(`expires=${options.expires}`);
|
407
|
+
}
|
408
|
+
if (options === null || options === void 0 ? void 0 : options.partitioned) {
|
409
|
+
extras.push('partitioned');
|
410
|
+
}
|
411
|
+
if (options === null || options === void 0 ? void 0 : options.samesite) {
|
412
|
+
extras.push(`samesite=${options.samesite}`);
|
413
|
+
}
|
414
|
+
if (options === null || options === void 0 ? void 0 : options.secure) {
|
415
|
+
extras.push('secure');
|
416
|
+
}
|
417
|
+
document.cookie = `${key}=${encodeURIComponent(value)};${extras.join(';')}`;
|
418
|
+
}
|
419
|
+
catch {
|
420
|
+
return;
|
421
|
+
}
|
422
|
+
};
|
423
|
+
|
424
|
+
const canLog = () => {
|
425
|
+
try {
|
426
|
+
return localStorage.getItem('edgeTagDebug') === '1';
|
427
|
+
}
|
428
|
+
catch {
|
429
|
+
return false;
|
430
|
+
}
|
431
|
+
};
|
432
|
+
const logger = {
|
433
|
+
log: (...args) => {
|
434
|
+
if (canLog()) {
|
435
|
+
console.log(...args);
|
436
|
+
}
|
437
|
+
},
|
438
|
+
error: (...args) => {
|
439
|
+
if (canLog()) {
|
440
|
+
console.error(...args);
|
441
|
+
}
|
442
|
+
},
|
443
|
+
info: (...args) => {
|
444
|
+
if (canLog()) {
|
445
|
+
console.info(...args);
|
446
|
+
}
|
447
|
+
},
|
448
|
+
trace: (...args) => {
|
449
|
+
if (canLog()) {
|
450
|
+
console.trace(...args);
|
451
|
+
}
|
452
|
+
},
|
453
|
+
table: (...args) => {
|
454
|
+
if (canLog()) {
|
455
|
+
console.table(...args);
|
456
|
+
}
|
457
|
+
},
|
458
|
+
dir: (...args) => {
|
459
|
+
if (canLog()) {
|
460
|
+
console.dir(...args);
|
461
|
+
}
|
462
|
+
},
|
463
|
+
};
|
464
|
+
|
418
465
|
const cart = (attrs) => b `<svg class=${attrs === null || attrs === void 0 ? void 0 : attrs.class} style=${attrs === null || attrs === void 0 ? void 0 : attrs.style} width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
|
419
466
|
<g clip-path="url(#clip0_10367_379)">
|
420
467
|
<path d="M20 60C22.2091 60 24 58.2091 24 56C24 53.7909 22.2091 52 20 52C17.7909 52 16 53.7909 16 56C16 58.2091 17.7909 60 20 60Z" fill="currentColor"/>
|
@@ -447,6 +494,7 @@ const circleCross = (attrs) => b `<svg class=${attrs === null || attrs === void
|
|
447
494
|
<path d="M47.5332 12.334L51.2443 16.0451L15.5379 51.7515L11.8268 48.0404L47.5332 12.334Z" fill="currentColor"/>
|
448
495
|
</svg>
|
449
496
|
`;
|
497
|
+
const logoImage = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAgCAYAAABU1PscAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEt0lEQVRYhdWYX4hUdRTHP+d358+6azNGqUVqilrQXaNIClKSQHsQpJceSu4IBSFIvQRWLwWW9dBD0IMYvUTNSAUGGVRYGLFQQU8aO2VhhVpBlOHcdXd2Z+b+vj3MrG6z7c7OpO32hTt/DjO/+/2ec37nnPszgJEoXCvYB2w3WCIwFi5+B44AB3Kl8nEbKYTrJT4ZSLlV1cSb13zzmx2BGWlneGmo5rUvJfH8QMqtGm34hez1i0gkvBeIzUDkgO3V5P9BfhISYDgzdqQMFrenjQGZwDAgEdQXYF5J4IxrXTs1ZyCojHs9UU30QN3rlZSzsXlh2QFe4NqNzgzgvEnFfKn8ruCoQW2h5tg0AS0YWF8lCg3I/JeEukVqvgmYzezFuWBeBQRmeClJoAokvawxbwICMzz6WbAf7BhQp4cJYE4CDEg7I3CGJERzs0ui7kXSQ5UNHJjsq4b0ea40fKr7FZqYi4Ag5Yxqw39X8zoKHBfEhpYCdwPbsoEtq3k5dSNEgPCtT8RRuBK4AUhP2i6PAOOPsYbfCxwWVsmXhqcu/mqlEK6ZSLQ37WxnIuV9FxraUMg4e9wZ1xmGEA0vGppdTEcB+WJ5CBia/D5S2JAWygJjueKwzxfLPwF74ig8lQnsqbrXsq4icQlBzavevJd+aHG73ZndhJSZack5b+KRaPB6occkfx+wBPgljsJDwDu5UjnOlcovx1G4OhvYrrpXvofpw4DXgTdypfKPAHEUbnLGCx62zOSUOZXgkcLgeqEjAyn3ZNbZxrSzdX2B25IN7DVnvBRH4XIAwcGJRKfpIofb0P6/oFOb6BiB8d0brTZafbE/5W4da/jU5B3qCGcQmO0GfR1HYSlXKn8bR+GXKbPVDZTrMgoCHgG2xlF4BgiADYlYyyxPWB0F1MaqG4B7qonPtvPxgowzEmkH8AEQA8PO7AJSriv6kGScpZ2xCdgkoOFFIolZItp5D8hWpB2ZxgzuTCQkVgDZlumcGY0uyQMUa16fctnLKDqfNOv1P8IZmBFLF0kvphn+2WGt1xbVXKl8Fjjbmc/fMYc+YCe89H0msI31RKl21zgMB8c8qrRM673U32nZxINHdwKb4yic4EqNErni8Ggchc/VEhWzgV1T92o9DRl9gTGe+C8ScUimP+PC4FKku+qeqzr1gkQiMFvp0QH9i2FuTmU0Vyp/hLFzItGQF+MtAiOjDf9WIh4WnMoXvxFSIRvYzTA9UjOJwAgCY3Fg5Hu55tzIcsXyx5Vdt3xm3tYLloD9CpzNlYYbACOFwa2S9tS9lndTPqUeXd/CTAIEjOdLZVUK4ToTi4CTuTfLNaA89Yf+0dvsQrX+kKT9zuxG9ThH9AqLo9AzZfM4Ay8qwNPAGWAbUADea10nMRszKS+4A3gw7exeSf2Jem/BPQsYiULf3ugMSLmmSYAk0s5R955EjNGsGH2ZwDImrOY7jIxXCM6MlCB2xt+GL9E8CzIueTRJPAY4o3/SXuvlSeYywQyEzjngw0XBtOMhYHo6iOb4kKj5Pl+wpge9xGEn7NnRhj89kHJyC/XwZwoCM7LOkXY2BLxtAJUoXGPwDHC/wdUL8Xi9lbYe+A14HziYK5VP/AXU+TX099lFgwAAAABJRU5ErkJggg==`;
|
450
498
|
|
451
499
|
/**
|
452
500
|
* Sets the max-age for the dismissed popup cookie
|
@@ -471,7 +519,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
471
519
|
this.transitionTo = (newState) => {
|
472
520
|
return flipOut(this.dialog)
|
473
521
|
.then(() => (this.state = newState))
|
474
|
-
.then(() => flipIn(this.dialog))
|
522
|
+
.then(() => flipIn(this.dialog))
|
523
|
+
.catch(logger.error);
|
475
524
|
};
|
476
525
|
this.restoreCart = async () => {
|
477
526
|
if (!this.lastExpiredCart) {
|
@@ -497,8 +546,6 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
497
546
|
}
|
498
547
|
await this.storeApi.addItems(this.lastExpiredCart.items);
|
499
548
|
const expiredCartId = this.lastExpiredCart.cartId;
|
500
|
-
// this cookie will be cleared once the next event is processed
|
501
|
-
setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
|
502
549
|
// We attempt to mark the cart as restored, but if the request fails,
|
503
550
|
// we log the error in the console and let the user continue. Since the
|
504
551
|
// problem is probably in the `/cart/restore` endpoint, further attempts
|
@@ -631,7 +678,13 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
631
678
|
method: 'POST',
|
632
679
|
headers: this.getHeaders(),
|
633
680
|
body: JSON.stringify({ action: 'popupDismissed' }),
|
634
|
-
})
|
681
|
+
})
|
682
|
+
.then(async (response) => {
|
683
|
+
if (!response.ok) {
|
684
|
+
throw new Error(`Error while recording user event - ${response.status}: ${response.statusText}\n\n${await response.text()}`);
|
685
|
+
}
|
686
|
+
})
|
687
|
+
.catch(logger.error);
|
635
688
|
}
|
636
689
|
connectedCallback() {
|
637
690
|
var _a;
|
@@ -699,7 +752,13 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
699
752
|
method: 'POST',
|
700
753
|
headers: this.getHeaders(),
|
701
754
|
body: JSON.stringify({ action: 'popupShown' }),
|
702
|
-
})
|
755
|
+
})
|
756
|
+
.then(async (response) => {
|
757
|
+
if (!response.ok) {
|
758
|
+
throw new Error(`Error while recording user event - ${response.status}: ${response.statusText}\n\n${await response.text()}`);
|
759
|
+
}
|
760
|
+
})
|
761
|
+
.catch(logger.error);
|
703
762
|
}
|
704
763
|
hideModal(action) {
|
705
764
|
fadeOutToBottom(this.dialog)
|
@@ -719,8 +778,14 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
719
778
|
getUrl(path) {
|
720
779
|
const url = new URL(`/providers/blotoutWallet${path}`, this.edgeURL);
|
721
780
|
if (this.storeApi) {
|
722
|
-
const
|
723
|
-
|
781
|
+
const cartToken = this.storeApi.getCartToken();
|
782
|
+
if (cartToken) {
|
783
|
+
url.searchParams.set('t', cartToken);
|
784
|
+
}
|
785
|
+
const previewKey = getPreviewKey();
|
786
|
+
if (previewKey) {
|
787
|
+
url.searchParams.set('pk', previewKey);
|
788
|
+
}
|
724
789
|
}
|
725
790
|
return url;
|
726
791
|
}
|
@@ -917,8 +982,25 @@ BlotoutWallet = __decorate([
|
|
917
982
|
t$1('blotout-wallet')
|
918
983
|
], BlotoutWallet);
|
919
984
|
|
985
|
+
const logStyles = `
|
986
|
+
padding: 4px 8px 4px 36px;
|
987
|
+
border: 1px dashed red;
|
988
|
+
border-radius: 3px;
|
989
|
+
font-weight: bold;
|
990
|
+
background: url(${logoImage}) 8px 50% no-repeat;
|
991
|
+
background-size: 24px 16px;
|
992
|
+
`;
|
993
|
+
const log = (message) => console.log(`%c${message}`, logStyles);
|
920
994
|
const init = (params) => {
|
921
995
|
var _a, _b, _c, _d, _e, _f;
|
996
|
+
let store = window[registryKey].storeAPI;
|
997
|
+
if (!store) {
|
998
|
+
store = window[registryKey].storeAPI =
|
999
|
+
(_b = (_a = window[registryKey]).storeAPIFactory) === null || _b === void 0 ? void 0 : _b.call(_a);
|
1000
|
+
}
|
1001
|
+
if (!store) {
|
1002
|
+
throw new Error('Implementation for store API missing!');
|
1003
|
+
}
|
922
1004
|
if (
|
923
1005
|
// if loaded in non-browser SDKs
|
924
1006
|
!window ||
|
@@ -926,15 +1008,22 @@ const init = (params) => {
|
|
926
1008
|
window.top !== window) {
|
927
1009
|
return;
|
928
1010
|
}
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
1011
|
+
const { enabled, previewKey, mode = 'disabled', } = (_c = params.manifest.variables) !== null && _c !== void 0 ? _c : {};
|
1012
|
+
const experiment = createExperiment({
|
1013
|
+
name: mode,
|
1014
|
+
userId: params.userId,
|
1015
|
+
previewKey,
|
1016
|
+
userPreviewKey: getPreviewKey(),
|
1017
|
+
});
|
1018
|
+
if (experiment.name == 'preview') {
|
1019
|
+
if (experiment.isEnabled) {
|
1020
|
+
log('Previewing functionality using preview key');
|
1021
|
+
}
|
1022
|
+
else {
|
1023
|
+
log('Preview key set but does not match the configured key');
|
935
1024
|
}
|
936
1025
|
}
|
937
|
-
if (
|
1026
|
+
if (enabled || experiment.isEnabled) {
|
938
1027
|
// if the component is already defined, skip creating the element to avoid
|
939
1028
|
// layering multiple widgets
|
940
1029
|
if (window[registryKey].wallet) {
|
package/package.json
CHANGED
@@ -58,7 +58,8 @@ const parseCookies = (cookie) => {
|
|
58
58
|
return Object.fromEntries(cookie
|
59
59
|
.split(/;\s+/)
|
60
60
|
.map((r) => r.split('=').map((str) => str.trim()))
|
61
|
-
.map(([cookieKey,
|
61
|
+
.map(([cookieKey, ...cookieValues]) => {
|
62
|
+
const cookieValue = cookieValues.join('=');
|
62
63
|
if (!cookieKey) {
|
63
64
|
return [];
|
64
65
|
}
|
@@ -94,46 +95,12 @@ const createShopApi = (fetchOverride = window.fetch) => ({
|
|
94
95
|
}
|
95
96
|
});
|
96
97
|
},
|
97
|
-
|
98
|
-
return fetchOverride(`${window.Shopify.routes.root}cart/clear.js`, {
|
99
|
-
method: 'POST',
|
100
|
-
}).then(async (response) => {
|
101
|
-
if (!response.ok) {
|
102
|
-
throw new Error('Could not clear cart', {
|
103
|
-
cause: await response.text(),
|
104
|
-
});
|
105
|
-
}
|
106
|
-
});
|
107
|
-
},
|
108
|
-
getCart() {
|
109
|
-
return fetchOverride(`${window.Shopify.routes.root}cart.js`, {
|
110
|
-
method: 'GET',
|
111
|
-
headers: { Accept: 'application/json' },
|
112
|
-
})
|
113
|
-
.then(async (response) => {
|
114
|
-
if (!response.ok) {
|
115
|
-
throw new Error('Could not fetch cart', {
|
116
|
-
cause: await response.text(),
|
117
|
-
});
|
118
|
-
}
|
119
|
-
return response.json();
|
120
|
-
})
|
121
|
-
.then((cart) => cart.items.map(({ product_id, variant_id, title, quantity, price }) => ({
|
122
|
-
productId: product_id.toString(),
|
123
|
-
variantId: (variant_id === null || variant_id === void 0 ? void 0 : variant_id.toString()) || null,
|
124
|
-
name: title,
|
125
|
-
quantity: quantity,
|
126
|
-
// TODO: should this be `final_price`, `discounted_price` or just `price`?
|
127
|
-
price: price,
|
128
|
-
})));
|
129
|
-
},
|
130
|
-
// duplicated this on tag call, as this was not being set before tag call gets initiated
|
131
|
-
getCartInfo() {
|
98
|
+
getCartToken() {
|
132
99
|
let cartToken = getCookieValue(cartTokenCookie);
|
133
100
|
if (!cartToken) {
|
134
101
|
cartToken = getCookieValue(cartTokenTwoCookie);
|
135
102
|
}
|
136
|
-
return
|
103
|
+
return cartToken || null;
|
137
104
|
},
|
138
105
|
});
|
139
106
|
window[registryKey].storeAPIFactory = createShopApi;
|
package/stores/shopify/index.js
CHANGED
@@ -59,7 +59,8 @@
|
|
59
59
|
return Object.fromEntries(cookie
|
60
60
|
.split(/;\s+/)
|
61
61
|
.map((r) => r.split('=').map((str) => str.trim()))
|
62
|
-
.map(([cookieKey,
|
62
|
+
.map(([cookieKey, ...cookieValues]) => {
|
63
|
+
const cookieValue = cookieValues.join('=');
|
63
64
|
if (!cookieKey) {
|
64
65
|
return [];
|
65
66
|
}
|
@@ -95,46 +96,12 @@
|
|
95
96
|
}
|
96
97
|
});
|
97
98
|
},
|
98
|
-
|
99
|
-
return fetchOverride(`${window.Shopify.routes.root}cart/clear.js`, {
|
100
|
-
method: 'POST',
|
101
|
-
}).then(async (response) => {
|
102
|
-
if (!response.ok) {
|
103
|
-
throw new Error('Could not clear cart', {
|
104
|
-
cause: await response.text(),
|
105
|
-
});
|
106
|
-
}
|
107
|
-
});
|
108
|
-
},
|
109
|
-
getCart() {
|
110
|
-
return fetchOverride(`${window.Shopify.routes.root}cart.js`, {
|
111
|
-
method: 'GET',
|
112
|
-
headers: { Accept: 'application/json' },
|
113
|
-
})
|
114
|
-
.then(async (response) => {
|
115
|
-
if (!response.ok) {
|
116
|
-
throw new Error('Could not fetch cart', {
|
117
|
-
cause: await response.text(),
|
118
|
-
});
|
119
|
-
}
|
120
|
-
return response.json();
|
121
|
-
})
|
122
|
-
.then((cart) => cart.items.map(({ product_id, variant_id, title, quantity, price }) => ({
|
123
|
-
productId: product_id.toString(),
|
124
|
-
variantId: (variant_id === null || variant_id === void 0 ? void 0 : variant_id.toString()) || null,
|
125
|
-
name: title,
|
126
|
-
quantity: quantity,
|
127
|
-
// TODO: should this be `final_price`, `discounted_price` or just `price`?
|
128
|
-
price: price,
|
129
|
-
})));
|
130
|
-
},
|
131
|
-
// duplicated this on tag call, as this was not being set before tag call gets initiated
|
132
|
-
getCartInfo() {
|
99
|
+
getCartToken() {
|
133
100
|
let cartToken = getCookieValue(cartTokenCookie);
|
134
101
|
if (!cartToken) {
|
135
102
|
cartToken = getCookieValue(cartTokenTwoCookie);
|
136
103
|
}
|
137
|
-
return
|
104
|
+
return cartToken || null;
|
138
105
|
},
|
139
106
|
});
|
140
107
|
window[registryKey].storeAPIFactory = createShopApi;
|
package/stores/shopify/index.mjs
CHANGED
@@ -56,7 +56,8 @@ const parseCookies = (cookie) => {
|
|
56
56
|
return Object.fromEntries(cookie
|
57
57
|
.split(/;\s+/)
|
58
58
|
.map((r) => r.split('=').map((str) => str.trim()))
|
59
|
-
.map(([cookieKey,
|
59
|
+
.map(([cookieKey, ...cookieValues]) => {
|
60
|
+
const cookieValue = cookieValues.join('=');
|
60
61
|
if (!cookieKey) {
|
61
62
|
return [];
|
62
63
|
}
|
@@ -92,46 +93,12 @@ const createShopApi = (fetchOverride = window.fetch) => ({
|
|
92
93
|
}
|
93
94
|
});
|
94
95
|
},
|
95
|
-
|
96
|
-
return fetchOverride(`${window.Shopify.routes.root}cart/clear.js`, {
|
97
|
-
method: 'POST',
|
98
|
-
}).then(async (response) => {
|
99
|
-
if (!response.ok) {
|
100
|
-
throw new Error('Could not clear cart', {
|
101
|
-
cause: await response.text(),
|
102
|
-
});
|
103
|
-
}
|
104
|
-
});
|
105
|
-
},
|
106
|
-
getCart() {
|
107
|
-
return fetchOverride(`${window.Shopify.routes.root}cart.js`, {
|
108
|
-
method: 'GET',
|
109
|
-
headers: { Accept: 'application/json' },
|
110
|
-
})
|
111
|
-
.then(async (response) => {
|
112
|
-
if (!response.ok) {
|
113
|
-
throw new Error('Could not fetch cart', {
|
114
|
-
cause: await response.text(),
|
115
|
-
});
|
116
|
-
}
|
117
|
-
return response.json();
|
118
|
-
})
|
119
|
-
.then((cart) => cart.items.map(({ product_id, variant_id, title, quantity, price }) => ({
|
120
|
-
productId: product_id.toString(),
|
121
|
-
variantId: (variant_id === null || variant_id === void 0 ? void 0 : variant_id.toString()) || null,
|
122
|
-
name: title,
|
123
|
-
quantity: quantity,
|
124
|
-
// TODO: should this be `final_price`, `discounted_price` or just `price`?
|
125
|
-
price: price,
|
126
|
-
})));
|
127
|
-
},
|
128
|
-
// duplicated this on tag call, as this was not being set before tag call gets initiated
|
129
|
-
getCartInfo() {
|
96
|
+
getCartToken() {
|
130
97
|
let cartToken = getCookieValue(cartTokenCookie);
|
131
98
|
if (!cartToken) {
|
132
99
|
cartToken = getCookieValue(cartTokenTwoCookie);
|
133
100
|
}
|
134
|
-
return
|
101
|
+
return cartToken || null;
|
135
102
|
},
|
136
103
|
});
|
137
104
|
window[registryKey].storeAPIFactory = createShopApi;
|