@blotoutio/providers-blotout-wallet-sdk 0.54.0 → 0.55.1

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 CHANGED
@@ -59,7 +59,7 @@ const customAttributes = {
59
59
  const packageName = 'blotoutWallet';
60
60
  const cartTokenCookie = 'cart';
61
61
  const cartTokenTwoCookie = 'cart2';
62
- const cartCurrencyCookie = 'cart_currency';
62
+ const cartTokenLinkCookie = 'bwCartLinkToken';
63
63
 
64
64
  const getCookieValue = (key) => {
65
65
  try {
@@ -167,14 +167,17 @@ const tag = ({ eventName }) => {
167
167
  switch (platform) {
168
168
  case 'SHOPIFY': {
169
169
  let cartToken = getCookieValue(cartTokenCookie);
170
- const cartCurrency = getCookieValue(cartCurrencyCookie);
170
+ const cartTokenLink = getCookieValue(cartTokenLinkCookie);
171
171
  if (!cartToken) {
172
172
  cartToken = getCookieValue(cartTokenTwoCookie);
173
173
  }
174
174
  if (eventName === 'Purchase') {
175
- document.cookie = `${cartTokenTwoCookie}=${cartToken};path=/;Max-Age=10`;
175
+ setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
176
176
  }
177
- return { cartToken, cartCurrency };
177
+ if (cartTokenLink) {
178
+ setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
179
+ }
180
+ return { cartToken, cartTokenLink };
178
181
  }
179
182
  default: {
180
183
  return {};
@@ -421,7 +424,7 @@ const formatString = (str) => {
421
424
  const parts = str.split(/<\s*br\s*\/?\s*>/);
422
425
  return o(parts, x `<br />`);
423
426
  };
424
- const wait = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
427
+ const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
425
428
  let BlotoutWallet = class BlotoutWallet extends s {
426
429
  constructor() {
427
430
  super(...arguments);
@@ -460,6 +463,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
460
463
  bubbles: true,
461
464
  }));
462
465
  const expiredCartId = this.lastExpiredCart.cartId;
466
+ // this cookie will be cleared once the next event is processed
467
+ setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
463
468
  // We attempt to mark the cart as restored, but if the request fails,
464
469
  // we log the error in the console and let the user continue. Since the
465
470
  // problem is probably in the `/cart/restore` endpoint, further attempts
@@ -473,16 +478,15 @@ let BlotoutWallet = class BlotoutWallet extends s {
473
478
  if (!response.ok) {
474
479
  throw new Error(`Could not update status in DB - ${response.status}: ${response.text}\n\n${await response.text()}`);
475
480
  }
476
- })
477
- .then(() => wait(500, expiredCartId))
478
- .then((restoredFrom) => fetch(this.getUrl('/cart/link'), {
479
- method: 'POST',
480
- headers: this.getHeaders(),
481
- body: JSON.stringify({ restoredFrom }),
482
- }))
483
- .then(async (response) => {
484
- if (!response.ok) {
485
- throw new Error(`Could not link cart restoration - ${response.status}: ${response.statusText}\n\n${await response.text()}`);
481
+ // Redirect to custom path
482
+ if (this.restoreRedirect) {
483
+ try {
484
+ const redirect = new URL(this.restoreRedirect, window.location.origin);
485
+ window.location.href = redirect.href;
486
+ }
487
+ catch (e) {
488
+ console.error('Invalid redirect URL', e);
489
+ }
486
490
  }
487
491
  })
488
492
  .catch((err) => {
@@ -491,7 +495,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
491
495
  this.lastExpiredCart = undefined;
492
496
  }
493
497
  await this.transitionTo('restored');
494
- wait(2000).then(() => {
498
+ delay(2000).then(() => {
495
499
  if (this.state == 'restored') {
496
500
  this.hideModal();
497
501
  }
@@ -517,11 +521,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
517
521
  };
518
522
  this.expiredCartContent = () => {
519
523
  var _a, _b, _c, _d;
520
- return x `<form
521
- class="restore-form"
522
- method="dialog"
523
- @submit=${this.onSubmit}
524
- >
524
+ return x `
525
+ <form class="restore-form" method="dialog" @submit=${this.onSubmit}>
525
526
  <div>
526
527
  ${formatString(((_a = this.theme) === null || _a === void 0 ? void 0 : _a.text) || customAttributes.text.defaultValue)}
527
528
  </div>
@@ -543,7 +544,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
543
544
  <button class="delete" type="button" @click=${this.skipCarts}>
544
545
  ${((_d = this.theme) === null || _d === void 0 ? void 0 : _d.rejectionLabel) ||
545
546
  customAttributes.rejectionLabel.defaultValue}
546
- </button> `;
547
+ </button>
548
+ `;
547
549
  };
548
550
  this.loadingContent = () => {
549
551
  return x `
@@ -638,8 +640,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
638
640
  getUrl(path) {
639
641
  const url = new URL(`/providers/blotoutWallet${path}`, this.edgeURL);
640
642
  if (this.storeApi) {
641
- const { cartToken, cartCurrency } = this.storeApi.getCartInfo();
642
- url.searchParams.set('c', cartCurrency);
643
+ const { cartToken } = this.storeApi.getCartInfo();
643
644
  url.searchParams.set('t', cartToken);
644
645
  }
645
646
  return url;
@@ -662,7 +663,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
662
663
  if (this.isPopUpDismissed) {
663
664
  return T;
664
665
  }
665
- return x `<dialog @click=${this.onDialogClick}>
666
+ return x ` <dialog @click=${this.onDialogClick}>
666
667
  <div @click=${this.onWrapperClick}>
667
668
  <div
668
669
  class="centered"
@@ -817,7 +818,7 @@ BlotoutWallet = __decorate([
817
818
  ], BlotoutWallet);
818
819
 
819
820
  const init = (params) => {
820
- var _a, _b, _c, _d;
821
+ var _a, _b, _c, _d, _e;
821
822
  if (
822
823
  // if loaded in non-browser SDKs
823
824
  !window ||
@@ -846,6 +847,7 @@ const init = (params) => {
846
847
  element.theme = theme;
847
848
  element.edgeURL = params.baseUrl;
848
849
  element.userId = params.userId;
850
+ element.restoreRedirect = (_e = params.manifest.variables) === null || _e === void 0 ? void 0 : _e['restoreRedirect'];
849
851
  document.body.append(element);
850
852
  }
851
853
  };
package/index.js CHANGED
@@ -60,7 +60,7 @@ var ProvidersBlotoutWalletSdk = (function () {
60
60
  const packageName = 'blotoutWallet';
61
61
  const cartTokenCookie = 'cart';
62
62
  const cartTokenTwoCookie = 'cart2';
63
- const cartCurrencyCookie = 'cart_currency';
63
+ const cartTokenLinkCookie = 'bwCartLinkToken';
64
64
 
65
65
  const getCookieValue = (key) => {
66
66
  try {
@@ -168,14 +168,17 @@ var ProvidersBlotoutWalletSdk = (function () {
168
168
  switch (platform) {
169
169
  case 'SHOPIFY': {
170
170
  let cartToken = getCookieValue(cartTokenCookie);
171
- const cartCurrency = getCookieValue(cartCurrencyCookie);
171
+ const cartTokenLink = getCookieValue(cartTokenLinkCookie);
172
172
  if (!cartToken) {
173
173
  cartToken = getCookieValue(cartTokenTwoCookie);
174
174
  }
175
175
  if (eventName === 'Purchase') {
176
- document.cookie = `${cartTokenTwoCookie}=${cartToken};path=/;Max-Age=10`;
176
+ setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
177
177
  }
178
- return { cartToken, cartCurrency };
178
+ if (cartTokenLink) {
179
+ setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
180
+ }
181
+ return { cartToken, cartTokenLink };
179
182
  }
180
183
  default: {
181
184
  return {};
@@ -422,7 +425,7 @@ var ProvidersBlotoutWalletSdk = (function () {
422
425
  const parts = str.split(/<\s*br\s*\/?\s*>/);
423
426
  return o(parts, x `<br />`);
424
427
  };
425
- const wait = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
428
+ const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
426
429
  let BlotoutWallet = class BlotoutWallet extends s {
427
430
  constructor() {
428
431
  super(...arguments);
@@ -461,6 +464,8 @@ var ProvidersBlotoutWalletSdk = (function () {
461
464
  bubbles: true,
462
465
  }));
463
466
  const expiredCartId = this.lastExpiredCart.cartId;
467
+ // this cookie will be cleared once the next event is processed
468
+ setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
464
469
  // We attempt to mark the cart as restored, but if the request fails,
465
470
  // we log the error in the console and let the user continue. Since the
466
471
  // problem is probably in the `/cart/restore` endpoint, further attempts
@@ -474,16 +479,15 @@ var ProvidersBlotoutWalletSdk = (function () {
474
479
  if (!response.ok) {
475
480
  throw new Error(`Could not update status in DB - ${response.status}: ${response.text}\n\n${await response.text()}`);
476
481
  }
477
- })
478
- .then(() => wait(500, expiredCartId))
479
- .then((restoredFrom) => fetch(this.getUrl('/cart/link'), {
480
- method: 'POST',
481
- headers: this.getHeaders(),
482
- body: JSON.stringify({ restoredFrom }),
483
- }))
484
- .then(async (response) => {
485
- if (!response.ok) {
486
- throw new Error(`Could not link cart restoration - ${response.status}: ${response.statusText}\n\n${await response.text()}`);
482
+ // Redirect to custom path
483
+ if (this.restoreRedirect) {
484
+ try {
485
+ const redirect = new URL(this.restoreRedirect, window.location.origin);
486
+ window.location.href = redirect.href;
487
+ }
488
+ catch (e) {
489
+ console.error('Invalid redirect URL', e);
490
+ }
487
491
  }
488
492
  })
489
493
  .catch((err) => {
@@ -492,7 +496,7 @@ var ProvidersBlotoutWalletSdk = (function () {
492
496
  this.lastExpiredCart = undefined;
493
497
  }
494
498
  await this.transitionTo('restored');
495
- wait(2000).then(() => {
499
+ delay(2000).then(() => {
496
500
  if (this.state == 'restored') {
497
501
  this.hideModal();
498
502
  }
@@ -518,11 +522,8 @@ var ProvidersBlotoutWalletSdk = (function () {
518
522
  };
519
523
  this.expiredCartContent = () => {
520
524
  var _a, _b, _c, _d;
521
- return x `<form
522
- class="restore-form"
523
- method="dialog"
524
- @submit=${this.onSubmit}
525
- >
525
+ return x `
526
+ <form class="restore-form" method="dialog" @submit=${this.onSubmit}>
526
527
  <div>
527
528
  ${formatString(((_a = this.theme) === null || _a === void 0 ? void 0 : _a.text) || customAttributes.text.defaultValue)}
528
529
  </div>
@@ -544,7 +545,8 @@ var ProvidersBlotoutWalletSdk = (function () {
544
545
  <button class="delete" type="button" @click=${this.skipCarts}>
545
546
  ${((_d = this.theme) === null || _d === void 0 ? void 0 : _d.rejectionLabel) ||
546
547
  customAttributes.rejectionLabel.defaultValue}
547
- </button> `;
548
+ </button>
549
+ `;
548
550
  };
549
551
  this.loadingContent = () => {
550
552
  return x `
@@ -639,8 +641,7 @@ var ProvidersBlotoutWalletSdk = (function () {
639
641
  getUrl(path) {
640
642
  const url = new URL(`/providers/blotoutWallet${path}`, this.edgeURL);
641
643
  if (this.storeApi) {
642
- const { cartToken, cartCurrency } = this.storeApi.getCartInfo();
643
- url.searchParams.set('c', cartCurrency);
644
+ const { cartToken } = this.storeApi.getCartInfo();
644
645
  url.searchParams.set('t', cartToken);
645
646
  }
646
647
  return url;
@@ -663,7 +664,7 @@ var ProvidersBlotoutWalletSdk = (function () {
663
664
  if (this.isPopUpDismissed) {
664
665
  return T;
665
666
  }
666
- return x `<dialog @click=${this.onDialogClick}>
667
+ return x ` <dialog @click=${this.onDialogClick}>
667
668
  <div @click=${this.onWrapperClick}>
668
669
  <div
669
670
  class="centered"
@@ -818,7 +819,7 @@ var ProvidersBlotoutWalletSdk = (function () {
818
819
  ], BlotoutWallet);
819
820
 
820
821
  const init = (params) => {
821
- var _a, _b, _c, _d;
822
+ var _a, _b, _c, _d, _e;
822
823
  if (
823
824
  // if loaded in non-browser SDKs
824
825
  !window ||
@@ -847,6 +848,7 @@ var ProvidersBlotoutWalletSdk = (function () {
847
848
  element.theme = theme;
848
849
  element.edgeURL = params.baseUrl;
849
850
  element.userId = params.userId;
851
+ element.restoreRedirect = (_e = params.manifest.variables) === null || _e === void 0 ? void 0 : _e['restoreRedirect'];
850
852
  document.body.append(element);
851
853
  }
852
854
  };
package/index.mjs CHANGED
@@ -57,7 +57,7 @@ const customAttributes = {
57
57
  const packageName = 'blotoutWallet';
58
58
  const cartTokenCookie = 'cart';
59
59
  const cartTokenTwoCookie = 'cart2';
60
- const cartCurrencyCookie = 'cart_currency';
60
+ const cartTokenLinkCookie = 'bwCartLinkToken';
61
61
 
62
62
  const getCookieValue = (key) => {
63
63
  try {
@@ -165,14 +165,17 @@ const tag = ({ eventName }) => {
165
165
  switch (platform) {
166
166
  case 'SHOPIFY': {
167
167
  let cartToken = getCookieValue(cartTokenCookie);
168
- const cartCurrency = getCookieValue(cartCurrencyCookie);
168
+ const cartTokenLink = getCookieValue(cartTokenLinkCookie);
169
169
  if (!cartToken) {
170
170
  cartToken = getCookieValue(cartTokenTwoCookie);
171
171
  }
172
172
  if (eventName === 'Purchase') {
173
- document.cookie = `${cartTokenTwoCookie}=${cartToken};path=/;Max-Age=10`;
173
+ setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
174
174
  }
175
- return { cartToken, cartCurrency };
175
+ if (cartTokenLink) {
176
+ setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
177
+ }
178
+ return { cartToken, cartTokenLink };
176
179
  }
177
180
  default: {
178
181
  return {};
@@ -419,7 +422,7 @@ const formatString = (str) => {
419
422
  const parts = str.split(/<\s*br\s*\/?\s*>/);
420
423
  return o(parts, x `<br />`);
421
424
  };
422
- const wait = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
425
+ const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
423
426
  let BlotoutWallet = class BlotoutWallet extends s {
424
427
  constructor() {
425
428
  super(...arguments);
@@ -458,6 +461,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
458
461
  bubbles: true,
459
462
  }));
460
463
  const expiredCartId = this.lastExpiredCart.cartId;
464
+ // this cookie will be cleared once the next event is processed
465
+ setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
461
466
  // We attempt to mark the cart as restored, but if the request fails,
462
467
  // we log the error in the console and let the user continue. Since the
463
468
  // problem is probably in the `/cart/restore` endpoint, further attempts
@@ -471,16 +476,15 @@ let BlotoutWallet = class BlotoutWallet extends s {
471
476
  if (!response.ok) {
472
477
  throw new Error(`Could not update status in DB - ${response.status}: ${response.text}\n\n${await response.text()}`);
473
478
  }
474
- })
475
- .then(() => wait(500, expiredCartId))
476
- .then((restoredFrom) => fetch(this.getUrl('/cart/link'), {
477
- method: 'POST',
478
- headers: this.getHeaders(),
479
- body: JSON.stringify({ restoredFrom }),
480
- }))
481
- .then(async (response) => {
482
- if (!response.ok) {
483
- throw new Error(`Could not link cart restoration - ${response.status}: ${response.statusText}\n\n${await response.text()}`);
479
+ // Redirect to custom path
480
+ if (this.restoreRedirect) {
481
+ try {
482
+ const redirect = new URL(this.restoreRedirect, window.location.origin);
483
+ window.location.href = redirect.href;
484
+ }
485
+ catch (e) {
486
+ console.error('Invalid redirect URL', e);
487
+ }
484
488
  }
485
489
  })
486
490
  .catch((err) => {
@@ -489,7 +493,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
489
493
  this.lastExpiredCart = undefined;
490
494
  }
491
495
  await this.transitionTo('restored');
492
- wait(2000).then(() => {
496
+ delay(2000).then(() => {
493
497
  if (this.state == 'restored') {
494
498
  this.hideModal();
495
499
  }
@@ -515,11 +519,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
515
519
  };
516
520
  this.expiredCartContent = () => {
517
521
  var _a, _b, _c, _d;
518
- return x `<form
519
- class="restore-form"
520
- method="dialog"
521
- @submit=${this.onSubmit}
522
- >
522
+ return x `
523
+ <form class="restore-form" method="dialog" @submit=${this.onSubmit}>
523
524
  <div>
524
525
  ${formatString(((_a = this.theme) === null || _a === void 0 ? void 0 : _a.text) || customAttributes.text.defaultValue)}
525
526
  </div>
@@ -541,7 +542,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
541
542
  <button class="delete" type="button" @click=${this.skipCarts}>
542
543
  ${((_d = this.theme) === null || _d === void 0 ? void 0 : _d.rejectionLabel) ||
543
544
  customAttributes.rejectionLabel.defaultValue}
544
- </button> `;
545
+ </button>
546
+ `;
545
547
  };
546
548
  this.loadingContent = () => {
547
549
  return x `
@@ -636,8 +638,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
636
638
  getUrl(path) {
637
639
  const url = new URL(`/providers/blotoutWallet${path}`, this.edgeURL);
638
640
  if (this.storeApi) {
639
- const { cartToken, cartCurrency } = this.storeApi.getCartInfo();
640
- url.searchParams.set('c', cartCurrency);
641
+ const { cartToken } = this.storeApi.getCartInfo();
641
642
  url.searchParams.set('t', cartToken);
642
643
  }
643
644
  return url;
@@ -660,7 +661,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
660
661
  if (this.isPopUpDismissed) {
661
662
  return T;
662
663
  }
663
- return x `<dialog @click=${this.onDialogClick}>
664
+ return x ` <dialog @click=${this.onDialogClick}>
664
665
  <div @click=${this.onWrapperClick}>
665
666
  <div
666
667
  class="centered"
@@ -815,7 +816,7 @@ BlotoutWallet = __decorate([
815
816
  ], BlotoutWallet);
816
817
 
817
818
  const init = (params) => {
818
- var _a, _b, _c, _d;
819
+ var _a, _b, _c, _d, _e;
819
820
  if (
820
821
  // if loaded in non-browser SDKs
821
822
  !window ||
@@ -844,6 +845,7 @@ const init = (params) => {
844
845
  element.theme = theme;
845
846
  element.edgeURL = params.baseUrl;
846
847
  element.userId = params.userId;
848
+ element.restoreRedirect = (_e = params.manifest.variables) === null || _e === void 0 ? void 0 : _e['restoreRedirect'];
847
849
  document.body.append(element);
848
850
  }
849
851
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-blotout-wallet-sdk",
3
- "version": "0.54.0",
3
+ "version": "0.55.1",
4
4
  "description": "Blotout Wallet SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
@@ -36,7 +36,6 @@ new Set([
36
36
 
37
37
  const cartTokenCookie = 'cart';
38
38
  const cartTokenTwoCookie = 'cart2';
39
- const cartCurrencyCookie = 'cart_currency';
40
39
 
41
40
  var _a;
42
41
  const registryKey = Symbol.for('blotout-wallet');
@@ -120,11 +119,10 @@ const createShopApi = (fetchOverride = window.fetch) => ({
120
119
  // duplicated this on tag call, as this was not being set before tag call gets initiated
121
120
  getCartInfo() {
122
121
  let cartToken = getCookieValue(cartTokenCookie);
123
- const cartCurrency = getCookieValue(cartCurrencyCookie);
124
122
  if (!cartToken) {
125
123
  cartToken = getCookieValue(cartTokenTwoCookie);
126
124
  }
127
- return { cartToken, cartCurrency };
125
+ return { cartToken };
128
126
  },
129
127
  });
130
128
  window[registryKey].storeAPIFactory = createShopApi;
@@ -37,7 +37,6 @@
37
37
 
38
38
  const cartTokenCookie = 'cart';
39
39
  const cartTokenTwoCookie = 'cart2';
40
- const cartCurrencyCookie = 'cart_currency';
41
40
 
42
41
  var _a;
43
42
  const registryKey = Symbol.for('blotout-wallet');
@@ -121,11 +120,10 @@
121
120
  // duplicated this on tag call, as this was not being set before tag call gets initiated
122
121
  getCartInfo() {
123
122
  let cartToken = getCookieValue(cartTokenCookie);
124
- const cartCurrency = getCookieValue(cartCurrencyCookie);
125
123
  if (!cartToken) {
126
124
  cartToken = getCookieValue(cartTokenTwoCookie);
127
125
  }
128
- return { cartToken, cartCurrency };
126
+ return { cartToken };
129
127
  },
130
128
  });
131
129
  window[registryKey].storeAPIFactory = createShopApi;
@@ -34,7 +34,6 @@ new Set([
34
34
 
35
35
  const cartTokenCookie = 'cart';
36
36
  const cartTokenTwoCookie = 'cart2';
37
- const cartCurrencyCookie = 'cart_currency';
38
37
 
39
38
  var _a;
40
39
  const registryKey = Symbol.for('blotout-wallet');
@@ -118,11 +117,10 @@ const createShopApi = (fetchOverride = window.fetch) => ({
118
117
  // duplicated this on tag call, as this was not being set before tag call gets initiated
119
118
  getCartInfo() {
120
119
  let cartToken = getCookieValue(cartTokenCookie);
121
- const cartCurrency = getCookieValue(cartCurrencyCookie);
122
120
  if (!cartToken) {
123
121
  cartToken = getCookieValue(cartTokenTwoCookie);
124
122
  }
125
- return { cartToken, cartCurrency };
123
+ return { cartToken };
126
124
  },
127
125
  });
128
126
  window[registryKey].storeAPIFactory = createShopApi;