@blotoutio/providers-blotout-wallet-sdk 0.53.1 → 0.55.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 +11 -15
- package/index.js +11 -15
- package/index.mjs +11 -15
- package/package.json +1 -1
package/index.cjs.js
CHANGED
@@ -60,6 +60,7 @@ const packageName = 'blotoutWallet';
|
|
60
60
|
const cartTokenCookie = 'cart';
|
61
61
|
const cartTokenTwoCookie = 'cart2';
|
62
62
|
const cartCurrencyCookie = 'cart_currency';
|
63
|
+
const cartTokenLinkCookie = 'bwCartLinkToken';
|
63
64
|
|
64
65
|
const getCookieValue = (key) => {
|
65
66
|
try {
|
@@ -168,13 +169,17 @@ const tag = ({ eventName }) => {
|
|
168
169
|
case 'SHOPIFY': {
|
169
170
|
let cartToken = getCookieValue(cartTokenCookie);
|
170
171
|
const cartCurrency = getCookieValue(cartCurrencyCookie);
|
172
|
+
const cartTokenLink = getCookieValue(cartTokenLinkCookie);
|
171
173
|
if (!cartToken) {
|
172
174
|
cartToken = getCookieValue(cartTokenTwoCookie);
|
173
175
|
}
|
174
176
|
if (eventName === 'Purchase') {
|
175
|
-
|
177
|
+
setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
|
176
178
|
}
|
177
|
-
|
179
|
+
if (cartTokenLink) {
|
180
|
+
setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
|
181
|
+
}
|
182
|
+
return { cartToken, cartCurrency, cartTokenLink };
|
178
183
|
}
|
179
184
|
default: {
|
180
185
|
return {};
|
@@ -421,7 +426,7 @@ const formatString = (str) => {
|
|
421
426
|
const parts = str.split(/<\s*br\s*\/?\s*>/);
|
422
427
|
return o(parts, x `<br />`);
|
423
428
|
};
|
424
|
-
const
|
429
|
+
const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
|
425
430
|
let BlotoutWallet = class BlotoutWallet extends s {
|
426
431
|
constructor() {
|
427
432
|
super(...arguments);
|
@@ -460,6 +465,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
460
465
|
bubbles: true,
|
461
466
|
}));
|
462
467
|
const expiredCartId = this.lastExpiredCart.cartId;
|
468
|
+
// this cookie will be cleared once the next event is processed
|
469
|
+
setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
|
463
470
|
// We attempt to mark the cart as restored, but if the request fails,
|
464
471
|
// we log the error in the console and let the user continue. Since the
|
465
472
|
// problem is probably in the `/cart/restore` endpoint, further attempts
|
@@ -473,17 +480,6 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
473
480
|
if (!response.ok) {
|
474
481
|
throw new Error(`Could not update status in DB - ${response.status}: ${response.text}\n\n${await response.text()}`);
|
475
482
|
}
|
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()}`);
|
486
|
-
}
|
487
483
|
})
|
488
484
|
.catch((err) => {
|
489
485
|
console.error(err);
|
@@ -491,7 +487,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
491
487
|
this.lastExpiredCart = undefined;
|
492
488
|
}
|
493
489
|
await this.transitionTo('restored');
|
494
|
-
|
490
|
+
delay(2000).then(() => {
|
495
491
|
if (this.state == 'restored') {
|
496
492
|
this.hideModal();
|
497
493
|
}
|
package/index.js
CHANGED
@@ -61,6 +61,7 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
61
61
|
const cartTokenCookie = 'cart';
|
62
62
|
const cartTokenTwoCookie = 'cart2';
|
63
63
|
const cartCurrencyCookie = 'cart_currency';
|
64
|
+
const cartTokenLinkCookie = 'bwCartLinkToken';
|
64
65
|
|
65
66
|
const getCookieValue = (key) => {
|
66
67
|
try {
|
@@ -169,13 +170,17 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
169
170
|
case 'SHOPIFY': {
|
170
171
|
let cartToken = getCookieValue(cartTokenCookie);
|
171
172
|
const cartCurrency = getCookieValue(cartCurrencyCookie);
|
173
|
+
const cartTokenLink = getCookieValue(cartTokenLinkCookie);
|
172
174
|
if (!cartToken) {
|
173
175
|
cartToken = getCookieValue(cartTokenTwoCookie);
|
174
176
|
}
|
175
177
|
if (eventName === 'Purchase') {
|
176
|
-
|
178
|
+
setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
|
177
179
|
}
|
178
|
-
|
180
|
+
if (cartTokenLink) {
|
181
|
+
setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
|
182
|
+
}
|
183
|
+
return { cartToken, cartCurrency, cartTokenLink };
|
179
184
|
}
|
180
185
|
default: {
|
181
186
|
return {};
|
@@ -422,7 +427,7 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
422
427
|
const parts = str.split(/<\s*br\s*\/?\s*>/);
|
423
428
|
return o(parts, x `<br />`);
|
424
429
|
};
|
425
|
-
const
|
430
|
+
const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
|
426
431
|
let BlotoutWallet = class BlotoutWallet extends s {
|
427
432
|
constructor() {
|
428
433
|
super(...arguments);
|
@@ -461,6 +466,8 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
461
466
|
bubbles: true,
|
462
467
|
}));
|
463
468
|
const expiredCartId = this.lastExpiredCart.cartId;
|
469
|
+
// this cookie will be cleared once the next event is processed
|
470
|
+
setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
|
464
471
|
// We attempt to mark the cart as restored, but if the request fails,
|
465
472
|
// we log the error in the console and let the user continue. Since the
|
466
473
|
// problem is probably in the `/cart/restore` endpoint, further attempts
|
@@ -474,17 +481,6 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
474
481
|
if (!response.ok) {
|
475
482
|
throw new Error(`Could not update status in DB - ${response.status}: ${response.text}\n\n${await response.text()}`);
|
476
483
|
}
|
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()}`);
|
487
|
-
}
|
488
484
|
})
|
489
485
|
.catch((err) => {
|
490
486
|
console.error(err);
|
@@ -492,7 +488,7 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
492
488
|
this.lastExpiredCart = undefined;
|
493
489
|
}
|
494
490
|
await this.transitionTo('restored');
|
495
|
-
|
491
|
+
delay(2000).then(() => {
|
496
492
|
if (this.state == 'restored') {
|
497
493
|
this.hideModal();
|
498
494
|
}
|
package/index.mjs
CHANGED
@@ -58,6 +58,7 @@ const packageName = 'blotoutWallet';
|
|
58
58
|
const cartTokenCookie = 'cart';
|
59
59
|
const cartTokenTwoCookie = 'cart2';
|
60
60
|
const cartCurrencyCookie = 'cart_currency';
|
61
|
+
const cartTokenLinkCookie = 'bwCartLinkToken';
|
61
62
|
|
62
63
|
const getCookieValue = (key) => {
|
63
64
|
try {
|
@@ -166,13 +167,17 @@ const tag = ({ eventName }) => {
|
|
166
167
|
case 'SHOPIFY': {
|
167
168
|
let cartToken = getCookieValue(cartTokenCookie);
|
168
169
|
const cartCurrency = getCookieValue(cartCurrencyCookie);
|
170
|
+
const cartTokenLink = getCookieValue(cartTokenLinkCookie);
|
169
171
|
if (!cartToken) {
|
170
172
|
cartToken = getCookieValue(cartTokenTwoCookie);
|
171
173
|
}
|
172
174
|
if (eventName === 'Purchase') {
|
173
|
-
|
175
|
+
setCookie(cartTokenTwoCookie, cartToken, { path: '/', maxAge: 10 });
|
174
176
|
}
|
175
|
-
|
177
|
+
if (cartTokenLink) {
|
178
|
+
setCookie(cartTokenLinkCookie, '', { maxAge: 0 });
|
179
|
+
}
|
180
|
+
return { cartToken, cartCurrency, cartTokenLink };
|
176
181
|
}
|
177
182
|
default: {
|
178
183
|
return {};
|
@@ -419,7 +424,7 @@ const formatString = (str) => {
|
|
419
424
|
const parts = str.split(/<\s*br\s*\/?\s*>/);
|
420
425
|
return o(parts, x `<br />`);
|
421
426
|
};
|
422
|
-
const
|
427
|
+
const delay = (n, resolvedValue) => new Promise((resolve) => setTimeout(() => resolve(resolvedValue), n));
|
423
428
|
let BlotoutWallet = class BlotoutWallet extends s {
|
424
429
|
constructor() {
|
425
430
|
super(...arguments);
|
@@ -458,6 +463,8 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
458
463
|
bubbles: true,
|
459
464
|
}));
|
460
465
|
const expiredCartId = this.lastExpiredCart.cartId;
|
466
|
+
// this cookie will be cleared once the next event is processed
|
467
|
+
setCookie(cartTokenLinkCookie, expiredCartId, { path: '/' });
|
461
468
|
// We attempt to mark the cart as restored, but if the request fails,
|
462
469
|
// we log the error in the console and let the user continue. Since the
|
463
470
|
// problem is probably in the `/cart/restore` endpoint, further attempts
|
@@ -471,17 +478,6 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
471
478
|
if (!response.ok) {
|
472
479
|
throw new Error(`Could not update status in DB - ${response.status}: ${response.text}\n\n${await response.text()}`);
|
473
480
|
}
|
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()}`);
|
484
|
-
}
|
485
481
|
})
|
486
482
|
.catch((err) => {
|
487
483
|
console.error(err);
|
@@ -489,7 +485,7 @@ let BlotoutWallet = class BlotoutWallet extends s {
|
|
489
485
|
this.lastExpiredCart = undefined;
|
490
486
|
}
|
491
487
|
await this.transitionTo('restored');
|
492
|
-
|
488
|
+
delay(2000).then(() => {
|
493
489
|
if (this.state == 'restored') {
|
494
490
|
this.hideModal();
|
495
491
|
}
|