@blotoutio/providers-blotout-wallet-sdk 0.62.1 → 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.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,144 +107,37 @@ const customAttributes = {
59
107
  };
60
108
 
61
109
  const packageName = 'blotoutWallet';
62
- const cartTokenCookie = 'cart';
63
- const cartTokenTwoCookie = 'cart2';
64
- const cartTokenLinkCookie = 'bwCartLinkToken';
110
+ const PREVIEW_KEY_NAME = '_blotoutWalletPreview';
65
111
 
66
- const getCookieValue = (key) => {
67
- var _a;
68
- try {
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, ...cookieValues]) => {
84
- const cookieValue = cookieValues.join('=');
85
- if (!cookieKey) {
86
- return [];
87
- }
88
- let decodedValue = '';
89
- if (cookieValue) {
90
- try {
91
- decodedValue = decodeURIComponent(cookieValue);
92
- }
93
- catch (e) {
94
- console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
95
- decodedValue = cookieValue;
96
- }
97
- }
98
- return [cookieKey, decodedValue];
99
- }));
100
- };
101
- const setCookie = (key, value, options) => {
102
- var _a;
103
- try {
104
- if (!document) {
105
- return;
106
- }
107
- const extras = [`path=${(_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : '/'}`];
108
- if (options === null || options === void 0 ? void 0 : options['maxAge']) {
109
- extras.push(`max-age=${options['maxAge']}`);
110
- }
111
- if (options === null || options === void 0 ? void 0 : options.expires) {
112
- extras.push(`expires=${options.expires}`);
113
- }
114
- if (options === null || options === void 0 ? void 0 : options.partitioned) {
115
- extras.push('partitioned');
116
- }
117
- if (options === null || options === void 0 ? void 0 : options.samesite) {
118
- extras.push(`samesite=${options.samesite}`);
119
- }
120
- if (options === null || options === void 0 ? void 0 : options.secure) {
121
- extras.push('secure');
122
- }
123
- document.cookie = `${key}=${encodeURIComponent(value)};${extras.join(';')}`;
124
- }
125
- catch {
126
- return;
127
- }
128
- };
112
+ var _a;
113
+ const registryKey = Symbol.for('blotout-wallet');
114
+ (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
129
115
 
130
- const canLog = () => {
116
+ // eslint-disable-next-line @nx/enforce-module-boundaries
117
+ const getPreviewKey = () => {
118
+ let key = null;
131
119
  try {
132
- return localStorage.getItem('edgeTagDebug') === '1';
120
+ key = localStorage.getItem(PREVIEW_KEY_NAME) || null;
133
121
  }
134
122
  catch {
135
- return false;
123
+ /* do nothing */
136
124
  }
125
+ return key;
137
126
  };
138
- const logger = {
139
- log: (...args) => {
140
- if (canLog()) {
141
- console.log(...args);
142
- }
143
- },
144
- error: (...args) => {
145
- if (canLog()) {
146
- console.error(...args);
147
- }
148
- },
149
- info: (...args) => {
150
- if (canLog()) {
151
- console.info(...args);
152
- }
153
- },
154
- trace: (...args) => {
155
- if (canLog()) {
156
- console.trace(...args);
157
- }
158
- },
159
- table: (...args) => {
160
- if (canLog()) {
161
- console.table(...args);
162
- }
163
- },
164
- dir: (...args) => {
165
- if (canLog()) {
166
- console.dir(...args);
167
- }
168
- },
169
- };
170
-
171
- var _a;
172
- const registryKey = Symbol.for('blotout-wallet');
173
- (_a = window[registryKey]) !== null && _a !== void 0 ? _a : (window[registryKey] = {});
174
127
 
175
- // eslint-disable-next-line @nx/enforce-module-boundaries
176
- const tag = ({ eventName }) => {
128
+ const tag = () => {
129
+ const result = {
130
+ cartToken: null,
131
+ previewKey: getPreviewKey(),
132
+ };
177
133
  if (!window) {
178
- return;
134
+ return result;
179
135
  }
180
- const platform = window[registryKey].platform;
181
- switch (platform) {
182
- case 'SHOPIFY': {
183
- let cartToken = getCookieValue(cartTokenCookie);
184
- const cartTokenLink = getCookieValue(cartTokenLinkCookie);
185
- if (!cartToken) {
186
- cartToken = getCookieValue(cartTokenTwoCookie);
187
- }
188
- if (eventName === 'Purchase') {
189
- setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
190
- }
191
- if (cartTokenLink) {
192
- setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
193
- }
194
- return { cartToken, cartTokenLink };
195
- }
196
- default: {
197
- return {};
198
- }
136
+ const store = window[registryKey].storeAPI;
137
+ if (store) {
138
+ result.cartToken = store.getCartToken();
199
139
  }
140
+ return result;
200
141
  };
201
142
 
202
143
  /******************************************************************************
@@ -416,6 +357,111 @@ const flipIn = (element) => {
416
357
  return animation.finished;
417
358
  };
418
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
+
419
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">
420
466
  <g clip-path="url(#clip0_10367_379)">
421
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"/>
@@ -448,6 +494,7 @@ const circleCross = (attrs) => b `<svg class=${attrs === null || attrs === void
448
494
  <path d="M47.5332 12.334L51.2443 16.0451L15.5379 51.7515L11.8268 48.0404L47.5332 12.334Z" fill="currentColor"/>
449
495
  </svg>
450
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==`;
451
498
 
452
499
  /**
453
500
  * Sets the max-age for the dismissed popup cookie
@@ -472,7 +519,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
472
519
  this.transitionTo = (newState) => {
473
520
  return flipOut(this.dialog)
474
521
  .then(() => (this.state = newState))
475
- .then(() => flipIn(this.dialog));
522
+ .then(() => flipIn(this.dialog))
523
+ .catch(logger.error);
476
524
  };
477
525
  this.restoreCart = async () => {
478
526
  if (!this.lastExpiredCart) {
@@ -498,8 +546,6 @@ let BlotoutWallet = class BlotoutWallet extends s {
498
546
  }
499
547
  await this.storeApi.addItems(this.lastExpiredCart.items);
500
548
  const expiredCartId = this.lastExpiredCart.cartId;
501
- // this cookie will be cleared once the next event is processed
502
- setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
503
549
  // We attempt to mark the cart as restored, but if the request fails,
504
550
  // we log the error in the console and let the user continue. Since the
505
551
  // problem is probably in the `/cart/restore` endpoint, further attempts
@@ -632,7 +678,13 @@ let BlotoutWallet = class BlotoutWallet extends s {
632
678
  method: 'POST',
633
679
  headers: this.getHeaders(),
634
680
  body: JSON.stringify({ action: 'popupDismissed' }),
635
- }).catch(logger.error);
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);
636
688
  }
637
689
  connectedCallback() {
638
690
  var _a;
@@ -700,7 +752,13 @@ let BlotoutWallet = class BlotoutWallet extends s {
700
752
  method: 'POST',
701
753
  headers: this.getHeaders(),
702
754
  body: JSON.stringify({ action: 'popupShown' }),
703
- }).catch(logger.error);
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);
704
762
  }
705
763
  hideModal(action) {
706
764
  fadeOutToBottom(this.dialog)
@@ -720,8 +778,14 @@ let BlotoutWallet = class BlotoutWallet extends s {
720
778
  getUrl(path) {
721
779
  const url = new URL(`/providers/blotoutWallet${path}`, this.edgeURL);
722
780
  if (this.storeApi) {
723
- const { cartToken } = this.storeApi.getCartInfo();
724
- url.searchParams.set('t', cartToken);
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
+ }
725
789
  }
726
790
  return url;
727
791
  }
@@ -918,8 +982,25 @@ BlotoutWallet = __decorate([
918
982
  t$1('blotout-wallet')
919
983
  ], BlotoutWallet);
920
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);
921
994
  const init = (params) => {
922
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
+ }
923
1004
  if (
924
1005
  // if loaded in non-browser SDKs
925
1006
  !window ||
@@ -927,15 +1008,22 @@ const init = (params) => {
927
1008
  window.top !== window) {
928
1009
  return;
929
1010
  }
930
- let store = window[registryKey].storeAPI;
931
- if (!store) {
932
- store = window[registryKey].storeAPI =
933
- (_b = (_a = window[registryKey]).storeAPIFactory) === null || _b === void 0 ? void 0 : _b.call(_a);
934
- if (!store) {
935
- throw new Error('Implementation for store API missing!');
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');
936
1024
  }
937
1025
  }
938
- if ((_c = params.manifest.variables) === null || _c === void 0 ? void 0 : _c['enabled']) {
1026
+ if (enabled || experiment.isEnabled) {
939
1027
  // if the component is already defined, skip creating the element to avoid
940
1028
  // layering multiple widgets
941
1029
  if (window[registryKey].wallet) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-blotout-wallet-sdk",
3
- "version": "0.62.1",
3
+ "version": "0.63.0",
4
4
  "description": "Blotout Wallet SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
@@ -95,46 +95,12 @@ const createShopApi = (fetchOverride = window.fetch) => ({
95
95
  }
96
96
  });
97
97
  },
98
- clearCart() {
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() {
98
+ getCartToken() {
133
99
  let cartToken = getCookieValue(cartTokenCookie);
134
100
  if (!cartToken) {
135
101
  cartToken = getCookieValue(cartTokenTwoCookie);
136
102
  }
137
- return { cartToken };
103
+ return cartToken || null;
138
104
  },
139
105
  });
140
106
  window[registryKey].storeAPIFactory = createShopApi;
@@ -96,46 +96,12 @@
96
96
  }
97
97
  });
98
98
  },
99
- clearCart() {
100
- return fetchOverride(`${window.Shopify.routes.root}cart/clear.js`, {
101
- method: 'POST',
102
- }).then(async (response) => {
103
- if (!response.ok) {
104
- throw new Error('Could not clear cart', {
105
- cause: await response.text(),
106
- });
107
- }
108
- });
109
- },
110
- getCart() {
111
- return fetchOverride(`${window.Shopify.routes.root}cart.js`, {
112
- method: 'GET',
113
- headers: { Accept: 'application/json' },
114
- })
115
- .then(async (response) => {
116
- if (!response.ok) {
117
- throw new Error('Could not fetch cart', {
118
- cause: await response.text(),
119
- });
120
- }
121
- return response.json();
122
- })
123
- .then((cart) => cart.items.map(({ product_id, variant_id, title, quantity, price }) => ({
124
- productId: product_id.toString(),
125
- variantId: (variant_id === null || variant_id === void 0 ? void 0 : variant_id.toString()) || null,
126
- name: title,
127
- quantity: quantity,
128
- // TODO: should this be `final_price`, `discounted_price` or just `price`?
129
- price: price,
130
- })));
131
- },
132
- // duplicated this on tag call, as this was not being set before tag call gets initiated
133
- getCartInfo() {
99
+ getCartToken() {
134
100
  let cartToken = getCookieValue(cartTokenCookie);
135
101
  if (!cartToken) {
136
102
  cartToken = getCookieValue(cartTokenTwoCookie);
137
103
  }
138
- return { cartToken };
104
+ return cartToken || null;
139
105
  },
140
106
  });
141
107
  window[registryKey].storeAPIFactory = createShopApi;
@@ -93,46 +93,12 @@ const createShopApi = (fetchOverride = window.fetch) => ({
93
93
  }
94
94
  });
95
95
  },
96
- clearCart() {
97
- return fetchOverride(`${window.Shopify.routes.root}cart/clear.js`, {
98
- method: 'POST',
99
- }).then(async (response) => {
100
- if (!response.ok) {
101
- throw new Error('Could not clear cart', {
102
- cause: await response.text(),
103
- });
104
- }
105
- });
106
- },
107
- getCart() {
108
- return fetchOverride(`${window.Shopify.routes.root}cart.js`, {
109
- method: 'GET',
110
- headers: { Accept: 'application/json' },
111
- })
112
- .then(async (response) => {
113
- if (!response.ok) {
114
- throw new Error('Could not fetch cart', {
115
- cause: await response.text(),
116
- });
117
- }
118
- return response.json();
119
- })
120
- .then((cart) => cart.items.map(({ product_id, variant_id, title, quantity, price }) => ({
121
- productId: product_id.toString(),
122
- variantId: (variant_id === null || variant_id === void 0 ? void 0 : variant_id.toString()) || null,
123
- name: title,
124
- quantity: quantity,
125
- // TODO: should this be `final_price`, `discounted_price` or just `price`?
126
- price: price,
127
- })));
128
- },
129
- // duplicated this on tag call, as this was not being set before tag call gets initiated
130
- getCartInfo() {
96
+ getCartToken() {
131
97
  let cartToken = getCookieValue(cartTokenCookie);
132
98
  if (!cartToken) {
133
99
  cartToken = getCookieValue(cartTokenTwoCookie);
134
100
  }
135
- return { cartToken };
101
+ return cartToken || null;
136
102
  },
137
103
  });
138
104
  window[registryKey].storeAPIFactory = createShopApi;