@blotoutio/providers-blotout-wallet-sdk 0.42.1 → 0.43.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 +220 -183
- package/index.js +220 -183
- package/index.mjs +220 -183
- package/package.json +1 -1
- package/stores/shopify/index.cjs.js +3 -5
- package/stores/shopify/index.js +3 -5
- package/stores/shopify/index.mjs +3 -5
package/index.js
CHANGED
@@ -2,6 +2,58 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
const packageName = 'blotoutWallet';
|
5
|
+
const customAttributes = {
|
6
|
+
'--bw-primary': { type: 'color', defaultValue: '#f25c2b' },
|
7
|
+
'--bw-secondary': { type: 'color', defaultValue: '#172a41' },
|
8
|
+
'--bw-button': { type: 'color', defaultValue: '#da2e3a' },
|
9
|
+
'--bw-foreground': { type: 'color', defaultValue: 'white' },
|
10
|
+
'--bw-input-border': { type: 'color', defaultValue: '#dbe2eb' },
|
11
|
+
'--bw-input-foreground': { type: 'color', defaultValue: '#172a41' },
|
12
|
+
'--bw-input-background': { type: 'color', defaultValue: 'white' },
|
13
|
+
'--bw-backdrop': { type: 'color', defaultValue: '#00000077' },
|
14
|
+
'--bw-z-index': { type: 'number', defaultValue: '9999' },
|
15
|
+
};
|
16
|
+
|
17
|
+
const canLog = () => {
|
18
|
+
try {
|
19
|
+
return localStorage.getItem('edgeTagDebug') === '1';
|
20
|
+
}
|
21
|
+
catch {
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
};
|
25
|
+
const logger = {
|
26
|
+
log: (...args) => {
|
27
|
+
if (canLog()) {
|
28
|
+
console.log(...args);
|
29
|
+
}
|
30
|
+
},
|
31
|
+
error: (...args) => {
|
32
|
+
if (canLog()) {
|
33
|
+
console.error(...args);
|
34
|
+
}
|
35
|
+
},
|
36
|
+
info: (...args) => {
|
37
|
+
if (canLog()) {
|
38
|
+
console.info(...args);
|
39
|
+
}
|
40
|
+
},
|
41
|
+
trace: (...args) => {
|
42
|
+
if (canLog()) {
|
43
|
+
console.trace(...args);
|
44
|
+
}
|
45
|
+
},
|
46
|
+
table: (...args) => {
|
47
|
+
if (canLog()) {
|
48
|
+
console.table(...args);
|
49
|
+
}
|
50
|
+
},
|
51
|
+
dir: (...args) => {
|
52
|
+
if (canLog()) {
|
53
|
+
console.dir(...args);
|
54
|
+
}
|
55
|
+
},
|
56
|
+
};
|
5
57
|
|
6
58
|
class APIError extends Error {
|
7
59
|
constructor(...args) {
|
@@ -9,11 +61,13 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
9
61
|
}
|
10
62
|
}
|
11
63
|
class WalletAPI {
|
12
|
-
constructor({ baseUrl, userId }) {
|
64
|
+
constructor({ baseUrl, userId, enabled }) {
|
13
65
|
this.listeners = new Set();
|
14
66
|
this._cart = { cartId: null, items: [], email: false };
|
15
67
|
this.baseUrl = baseUrl;
|
16
68
|
this.userId = userId;
|
69
|
+
this.enabled = enabled;
|
70
|
+
logger.info(`[Blotout Wallet] User is ${enabled ? 'enabled' : 'disabled'}`);
|
17
71
|
}
|
18
72
|
getHeaders(json = false) {
|
19
73
|
const headers = new Headers({
|
@@ -44,6 +98,9 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
44
98
|
this._cart = value;
|
45
99
|
this.notify();
|
46
100
|
}
|
101
|
+
get segmentEnabled() {
|
102
|
+
return this.enabled;
|
103
|
+
}
|
47
104
|
subscribe(listener) {
|
48
105
|
this.listeners.add(listener);
|
49
106
|
return () => {
|
@@ -115,19 +172,6 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
115
172
|
return (this.cart = await response.json());
|
116
173
|
});
|
117
174
|
}
|
118
|
-
purchase(orderId) {
|
119
|
-
return fetch(this.getUrl('/cart/purchase'), {
|
120
|
-
method: 'POST',
|
121
|
-
body: JSON.stringify({ orderId }),
|
122
|
-
headers: this.getHeaders(true),
|
123
|
-
}).then((response) => {
|
124
|
-
if (!response.ok) {
|
125
|
-
throw new APIError(`Could not mark purchase`, { cause: response });
|
126
|
-
}
|
127
|
-
this.cart = { cartId: null, email: this.cart.email, items: [] };
|
128
|
-
this.notify();
|
129
|
-
});
|
130
|
-
}
|
131
175
|
saveEmail(email) {
|
132
176
|
return fetch(this.getUrl('/cart/email'), {
|
133
177
|
method: 'POST',
|
@@ -274,15 +318,42 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
274
318
|
|
275
319
|
const cssVars = i$4 `
|
276
320
|
:host {
|
277
|
-
--primary: var(
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
--
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
--
|
321
|
+
--primary: var(
|
322
|
+
--bw-primary,
|
323
|
+
${r$5(customAttributes['--bw-primary'].defaultValue)}
|
324
|
+
);
|
325
|
+
--secondary: var(
|
326
|
+
--bw-secondary,
|
327
|
+
${r$5(customAttributes['--bw-secondary'].defaultValue)}
|
328
|
+
);
|
329
|
+
--button: var(
|
330
|
+
--bw-button,
|
331
|
+
${r$5(customAttributes['--bw-button'].defaultValue)}
|
332
|
+
);
|
333
|
+
--foreground: var(
|
334
|
+
--bw-foreground,
|
335
|
+
${r$5(customAttributes['--bw-foreground'].defaultValue)}
|
336
|
+
);
|
337
|
+
--input-border: var(
|
338
|
+
--bw-input-border,
|
339
|
+
${r$5(customAttributes['--bw-input-border'].defaultValue)}
|
340
|
+
);
|
341
|
+
--input-foreground: var(
|
342
|
+
--bw-input-foreground,
|
343
|
+
${r$5(customAttributes['--bw-input-foreground'].defaultValue)}
|
344
|
+
);
|
345
|
+
--input-background: var(
|
346
|
+
--bw-input-background,
|
347
|
+
${r$5(customAttributes['--bw-input-background'].defaultValue)}
|
348
|
+
);
|
349
|
+
--backdrop: var(
|
350
|
+
--bw-backdrop,
|
351
|
+
${r$5(customAttributes['--bw-backdrop'].defaultValue)}
|
352
|
+
);
|
353
|
+
--z-index: var(
|
354
|
+
--bw-z-index,
|
355
|
+
${r$5(customAttributes['--bw-z-index'].defaultValue)}
|
356
|
+
);
|
286
357
|
|
287
358
|
--spring-easing: ${r$5(spring)};
|
288
359
|
|
@@ -421,22 +492,22 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
421
492
|
'top-left',
|
422
493
|
'top-right',
|
423
494
|
]);
|
424
|
-
const getItemKey = (item) => `${item.productId}-${item.variantId}`;
|
425
495
|
const wait = (timeout) => new Promise((res) => setTimeout(res, timeout));
|
426
496
|
let BlotoutWallet = class BlotoutWallet extends s {
|
427
497
|
constructor() {
|
428
498
|
super(...arguments);
|
429
|
-
this.
|
430
|
-
this.
|
431
|
-
this.
|
432
|
-
this.
|
433
|
-
this.onWalletUpdated = () => {
|
434
|
-
|
435
|
-
this.
|
436
|
-
|
499
|
+
this.buttonVisible = false;
|
500
|
+
this.bannerVisible = false;
|
501
|
+
this.hasItemsInWallet = false;
|
502
|
+
this.hasEmail = false;
|
503
|
+
this.onWalletUpdated = (walletContent) => {
|
504
|
+
logger.log({ walletContent });
|
505
|
+
this.hasItemsInWallet = walletContent.items.length > 0;
|
506
|
+
this.hasEmail = walletContent.email;
|
507
|
+
if (this.isSegmentEnabled && (this.hasItemsInWallet || !this.hasEmail)) {
|
437
508
|
this.showButton();
|
438
509
|
}
|
439
|
-
else if (!this.
|
510
|
+
else if (!this.hasItemsInWallet && this.hasEmail) {
|
440
511
|
this.hideButton();
|
441
512
|
}
|
442
513
|
};
|
@@ -445,164 +516,152 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
445
516
|
ev.preventDefault();
|
446
517
|
ev.stopPropagation();
|
447
518
|
const modalAnimation = this.hideModal();
|
448
|
-
const email = (_a = this.
|
519
|
+
const email = (_a = this.email) === null || _a === void 0 ? void 0 : _a.value.trim();
|
449
520
|
if (email) {
|
450
|
-
this.
|
521
|
+
this.walletApi.saveEmail(email)
|
451
522
|
.then(() => {
|
452
|
-
this.
|
453
|
-
this.
|
523
|
+
this.email.value = '';
|
524
|
+
this.hasEmail = true;
|
454
525
|
this.dispatchEvent(new CustomEvent('blotout-wallet-email-saved', { bubbles: true }));
|
455
526
|
})
|
456
|
-
.catch((err) =>
|
527
|
+
.catch((err) => logger.error(err));
|
457
528
|
}
|
458
|
-
if (this.
|
459
|
-
this.
|
460
|
-
.then(() => this.
|
461
|
-
.then(() => this._walletApi.restore())
|
529
|
+
if (this.hasItemsInWallet) {
|
530
|
+
this.storeApi.addItems(this.walletApi.cart.items)
|
531
|
+
.then(() => this.walletApi.restore())
|
462
532
|
.then(() => {
|
463
533
|
this.dispatchEvent(new CustomEvent('blotout-wallet-restored', { bubbles: true }));
|
464
534
|
return modalAnimation.then(() => this.showRestorationBanner());
|
465
535
|
})
|
466
|
-
.
|
536
|
+
.then(() => wait(1000))
|
537
|
+
.then(() => (window.location.href = `${window.Shopify.routes.root}cart`))
|
538
|
+
.catch((err) => logger.error(err));
|
467
539
|
}
|
468
540
|
};
|
469
541
|
this.showRestorationBanner = async () => {
|
470
|
-
this.
|
542
|
+
if (this.bannerVisible) {
|
543
|
+
return;
|
544
|
+
}
|
545
|
+
this.bannerVisible = true;
|
471
546
|
await new Promise(requestAnimationFrame);
|
472
|
-
await springInFromBottom(this.
|
473
|
-
|
474
|
-
|
475
|
-
this.
|
547
|
+
await springInFromBottom(this.banner, '120%');
|
548
|
+
};
|
549
|
+
this.hideRestorationBanner = async () => {
|
550
|
+
if (!this.bannerVisible) {
|
551
|
+
return;
|
552
|
+
}
|
553
|
+
await springOutToBottom(this.banner, '120%');
|
554
|
+
this.bannerVisible = false;
|
476
555
|
};
|
477
556
|
}
|
478
|
-
get
|
557
|
+
get storeApi() {
|
479
558
|
var _a;
|
480
559
|
return (_a = window[registryKey]) === null || _a === void 0 ? void 0 : _a.storeAPI;
|
481
560
|
}
|
482
|
-
get
|
561
|
+
get walletApi() {
|
483
562
|
var _a;
|
484
563
|
return (_a = window[registryKey]) === null || _a === void 0 ? void 0 : _a.walletAPI;
|
485
564
|
}
|
565
|
+
get isSegmentEnabled() {
|
566
|
+
var _a;
|
567
|
+
return (_a = this.walletApi) === null || _a === void 0 ? void 0 : _a.segmentEnabled;
|
568
|
+
}
|
486
569
|
get _position() {
|
487
570
|
return validPositions.has(this.position) ? this.position : 'bottom-left';
|
488
571
|
}
|
489
572
|
connectedCallback() {
|
490
573
|
var _a;
|
491
574
|
super.connectedCallback();
|
492
|
-
this.
|
493
|
-
this.syncItems().then((
|
575
|
+
this.unsubscribe = (_a = this.walletApi) === null || _a === void 0 ? void 0 : _a.subscribe(this.onWalletUpdated);
|
576
|
+
this.syncItems().then(() => {
|
494
577
|
this.dispatchEvent(new CustomEvent('blotout-wallet-loaded', { bubbles: true }));
|
495
|
-
this._hasItemsInWallet = hasItemsSaved;
|
496
|
-
if (this._hasItemsInWallet) {
|
497
|
-
this.showButton();
|
498
|
-
}
|
499
578
|
});
|
500
579
|
}
|
501
580
|
disconnectedCallback() {
|
502
581
|
var _a;
|
503
582
|
super.disconnectedCallback();
|
504
|
-
(_a = this.
|
505
|
-
this.
|
583
|
+
(_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
|
584
|
+
this.unsubscribe = undefined;
|
506
585
|
}
|
507
586
|
async syncItems() {
|
508
|
-
if (!this.
|
509
|
-
|
587
|
+
if (!this.walletApi) {
|
588
|
+
logger.error('The required APIs are not available');
|
510
589
|
return false;
|
511
590
|
}
|
512
|
-
const
|
513
|
-
|
514
|
-
this._storeApi.getCart(),
|
515
|
-
]);
|
516
|
-
this._hasEmail = savedCart.email;
|
517
|
-
const savedItemsLookup = new Map(savedCart.items.map((item) => [getItemKey(item), item]));
|
518
|
-
const missingItems = [];
|
519
|
-
for (const item of shopItems) {
|
520
|
-
const walletItem = savedItemsLookup.get(getItemKey(item));
|
521
|
-
if (!walletItem) {
|
522
|
-
missingItems.push(item);
|
523
|
-
}
|
524
|
-
else if (walletItem.amount < item.amount) {
|
525
|
-
missingItems.push({
|
526
|
-
...item,
|
527
|
-
amount: item.amount - walletItem.amount,
|
528
|
-
});
|
529
|
-
}
|
530
|
-
}
|
531
|
-
if (missingItems.length > 0) {
|
532
|
-
await this._walletApi.addItems(missingItems);
|
533
|
-
}
|
591
|
+
const savedCart = await this.walletApi.getCart();
|
592
|
+
this.hasEmail = savedCart.email;
|
534
593
|
return savedCart.items.length > 0;
|
535
594
|
}
|
536
595
|
async showButton() {
|
537
|
-
if (this.
|
596
|
+
if (this.buttonVisible) {
|
538
597
|
return;
|
539
598
|
}
|
540
|
-
this.
|
599
|
+
this.buttonVisible = true;
|
541
600
|
await new Promise(requestAnimationFrame).then(() => {
|
542
|
-
switch (this.
|
601
|
+
switch (this.position) {
|
543
602
|
case 'top-left':
|
544
603
|
case 'left':
|
545
604
|
case 'bottom-left': {
|
546
|
-
return springInFromLeft(this.
|
605
|
+
return springInFromLeft(this.button);
|
547
606
|
}
|
548
607
|
case 'top-right':
|
549
608
|
case 'right':
|
550
609
|
case 'bottom-right': {
|
551
|
-
return springInFromRight(this.
|
610
|
+
return springInFromRight(this.button);
|
552
611
|
}
|
553
612
|
case 'bottom': {
|
554
|
-
return springInFromBottom(this.
|
613
|
+
return springInFromBottom(this.button);
|
555
614
|
}
|
556
615
|
case 'top': {
|
557
|
-
return springInFromTop(this.
|
616
|
+
return springInFromTop(this.button);
|
558
617
|
}
|
559
618
|
default: {
|
560
|
-
return springInFromLeft(this.
|
619
|
+
return springInFromLeft(this.button);
|
561
620
|
}
|
562
621
|
}
|
563
622
|
});
|
564
623
|
this.dispatchEvent(new CustomEvent('blotout-wallet-shown', { bubbles: true }));
|
565
624
|
}
|
566
625
|
async hideButton() {
|
567
|
-
if (!this.
|
626
|
+
if (!this.buttonVisible) {
|
568
627
|
return;
|
569
628
|
}
|
570
|
-
switch (this.
|
629
|
+
switch (this.position) {
|
571
630
|
case 'top-left':
|
572
631
|
case 'left':
|
573
632
|
case 'bottom-left': {
|
574
|
-
await springOutToLeft(this.
|
633
|
+
await springOutToLeft(this.button);
|
575
634
|
break;
|
576
635
|
}
|
577
636
|
case 'top-right':
|
578
637
|
case 'right':
|
579
638
|
case 'bottom-right': {
|
580
|
-
await springOutToRight(this.
|
639
|
+
await springOutToRight(this.button);
|
581
640
|
break;
|
582
641
|
}
|
583
642
|
case 'bottom': {
|
584
|
-
await springOutToBottom(this.
|
643
|
+
await springOutToBottom(this.button);
|
585
644
|
break;
|
586
645
|
}
|
587
646
|
case 'top': {
|
588
|
-
await springOutToTop(this.
|
647
|
+
await springOutToTop(this.button);
|
589
648
|
break;
|
590
649
|
}
|
591
650
|
default: {
|
592
|
-
await springOutToLeft(this.
|
651
|
+
await springOutToLeft(this.button);
|
593
652
|
}
|
594
653
|
}
|
595
|
-
this.
|
654
|
+
this.buttonVisible = false;
|
596
655
|
this.dispatchEvent(new CustomEvent('blotout-wallet-hidden', { bubbles: true }));
|
597
656
|
}
|
598
657
|
async showModal() {
|
599
|
-
this.
|
658
|
+
this.dialog.showModal();
|
600
659
|
await new Promise(requestAnimationFrame);
|
601
|
-
await fadeInDialog(this.
|
660
|
+
await fadeInDialog(this.dialog);
|
602
661
|
}
|
603
662
|
async hideModal() {
|
604
|
-
await fadeOutToBottom(this.
|
605
|
-
this.
|
663
|
+
await fadeOutToBottom(this.dialog);
|
664
|
+
this.dialog.close();
|
606
665
|
}
|
607
666
|
render() {
|
608
667
|
return x `
|
@@ -610,7 +669,7 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
610
669
|
class="${e({
|
611
670
|
cta: true,
|
612
671
|
[this._position]: true,
|
613
|
-
hidden: !this.
|
672
|
+
hidden: !this.buttonVisible,
|
614
673
|
})}"
|
615
674
|
@click=${this.showModal}
|
616
675
|
>
|
@@ -621,7 +680,7 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
621
680
|
<button class="dismiss" @click=${this.hideModal}>${cross()}</button>
|
622
681
|
${blotout({ class: 'logo' })}
|
623
682
|
<form method="dialog" @submit=${this.onSubmit}>
|
624
|
-
${this.
|
683
|
+
${this.hasItemsInWallet
|
625
684
|
? x `<p>
|
626
685
|
Hey! Your <strong>cart has expired!</strong><br />But we've got
|
627
686
|
you covered. ${wink({ style: 'vertical-align:middle' })}
|
@@ -636,15 +695,15 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
636
695
|
type="email"
|
637
696
|
name="email"
|
638
697
|
placeholder="Enter your email ID"
|
639
|
-
?required=${!this.
|
698
|
+
?required=${!this.hasEmail}
|
640
699
|
style=${o({
|
641
|
-
display: this.
|
700
|
+
display: this.hasEmail ? 'none' : 'block',
|
642
701
|
})}
|
643
702
|
/>
|
644
703
|
</p>
|
645
704
|
<p>
|
646
705
|
<button class="restore" type="submit">
|
647
|
-
${this.
|
706
|
+
${this.hasItemsInWallet ? 'Restore Cart' : 'Save Cart'}
|
648
707
|
</button>
|
649
708
|
</p>
|
650
709
|
</form>
|
@@ -652,7 +711,7 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
652
711
|
|
653
712
|
<div
|
654
713
|
class="banner"
|
655
|
-
style=${o({ display: this.
|
714
|
+
style=${o({ display: this.bannerVisible ? '' : 'none' })}
|
656
715
|
>
|
657
716
|
${blotout({
|
658
717
|
class: 'logo',
|
@@ -755,7 +814,6 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
755
814
|
}
|
756
815
|
|
757
816
|
dialog {
|
758
|
-
position: relative;
|
759
817
|
width: 430px;
|
760
818
|
max-width: 100vw;
|
761
819
|
background: var(--secondary);
|
@@ -839,97 +897,92 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
839
897
|
__decorate([
|
840
898
|
e$2('dialog'),
|
841
899
|
__metadata("design:type", HTMLDialogElement)
|
842
|
-
], BlotoutWallet.prototype, "
|
900
|
+
], BlotoutWallet.prototype, "dialog", void 0);
|
843
901
|
__decorate([
|
844
902
|
e$2('button.cta'),
|
845
903
|
__metadata("design:type", HTMLButtonElement)
|
846
|
-
], BlotoutWallet.prototype, "
|
904
|
+
], BlotoutWallet.prototype, "button", void 0);
|
847
905
|
__decorate([
|
848
906
|
e$2('input[name=email]'),
|
849
907
|
__metadata("design:type", HTMLInputElement)
|
850
|
-
], BlotoutWallet.prototype, "
|
908
|
+
], BlotoutWallet.prototype, "email", void 0);
|
851
909
|
__decorate([
|
852
910
|
e$2('.banner'),
|
853
911
|
__metadata("design:type", HTMLDivElement)
|
854
|
-
], BlotoutWallet.prototype, "
|
912
|
+
], BlotoutWallet.prototype, "banner", void 0);
|
855
913
|
__decorate([
|
856
914
|
r(),
|
857
915
|
__metadata("design:type", Boolean)
|
858
|
-
], BlotoutWallet.prototype, "
|
916
|
+
], BlotoutWallet.prototype, "buttonVisible", void 0);
|
859
917
|
__decorate([
|
860
918
|
r(),
|
861
919
|
__metadata("design:type", Boolean)
|
862
|
-
], BlotoutWallet.prototype, "
|
920
|
+
], BlotoutWallet.prototype, "bannerVisible", void 0);
|
863
921
|
__decorate([
|
864
922
|
r(),
|
865
923
|
__metadata("design:type", Boolean)
|
866
|
-
], BlotoutWallet.prototype, "
|
924
|
+
], BlotoutWallet.prototype, "hasItemsInWallet", void 0);
|
867
925
|
__decorate([
|
868
926
|
r(),
|
869
927
|
__metadata("design:type", Boolean)
|
870
|
-
], BlotoutWallet.prototype, "
|
928
|
+
], BlotoutWallet.prototype, "hasEmail", void 0);
|
871
929
|
BlotoutWallet = __decorate([
|
872
930
|
t$1('blotout-wallet')
|
873
931
|
], BlotoutWallet);
|
874
932
|
|
875
933
|
const init = (params) => {
|
876
|
-
var _a, _b;
|
877
|
-
if (
|
878
|
-
|
934
|
+
var _a, _b, _c;
|
935
|
+
if (
|
936
|
+
// if loaded in non-browser SDKs
|
937
|
+
!window ||
|
938
|
+
!document) {
|
939
|
+
return;
|
940
|
+
}
|
941
|
+
let walletAPI = window[registryKey].walletAPI;
|
942
|
+
if (!window[registryKey].walletAPI) {
|
943
|
+
walletAPI = window[registryKey].walletAPI = new WalletAPI({
|
879
944
|
baseUrl: params.baseUrl,
|
880
945
|
userId: params.userId,
|
946
|
+
enabled: !!((_a = params.manifest.variables) === null || _a === void 0 ? void 0 : _a['enabled']),
|
881
947
|
});
|
882
|
-
|
883
|
-
|
948
|
+
}
|
949
|
+
let store = window[registryKey].storeAPI;
|
950
|
+
if (!store) {
|
951
|
+
store = window[registryKey].storeAPI =
|
952
|
+
(_c = (_b = window[registryKey]).storeAPIFactory) === null || _c === void 0 ? void 0 : _c.call(_b);
|
884
953
|
if (!store) {
|
885
954
|
throw new Error('Implementation for store API missing!');
|
886
955
|
}
|
956
|
+
}
|
957
|
+
const initComponent = () => {
|
958
|
+
var _a, _b;
|
887
959
|
const element = (window[registryKey].wallet =
|
888
960
|
document.createElement('blotout-wallet'));
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
const canLog = () => {
|
895
|
-
try {
|
896
|
-
return localStorage.getItem('edgeTagDebug') === '1';
|
897
|
-
}
|
898
|
-
catch {
|
899
|
-
return false;
|
900
|
-
}
|
901
|
-
};
|
902
|
-
const logger = {
|
903
|
-
log: (...args) => {
|
904
|
-
if (canLog()) {
|
905
|
-
console.log(...args);
|
906
|
-
}
|
907
|
-
},
|
908
|
-
error: (...args) => {
|
909
|
-
if (canLog()) {
|
910
|
-
console.error(...args);
|
911
|
-
}
|
912
|
-
},
|
913
|
-
info: (...args) => {
|
914
|
-
if (canLog()) {
|
915
|
-
console.info(...args);
|
961
|
+
const theme = (_a = params.manifest.variables) === null || _a === void 0 ? void 0 : _a['theme'];
|
962
|
+
if (theme) {
|
963
|
+
element.style.cssText = Object.entries(theme)
|
964
|
+
.map(([name, value]) => `${name}:${value}`)
|
965
|
+
.join(';');
|
916
966
|
}
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
console.trace(...args);
|
967
|
+
const position = (_b = params.manifest.variables) === null || _b === void 0 ? void 0 : _b['position'];
|
968
|
+
if (position) {
|
969
|
+
element.setAttribute('position', position);
|
921
970
|
}
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
971
|
+
document.body.append(element);
|
972
|
+
};
|
973
|
+
if (window.top === window && !window[registryKey].wallet) {
|
974
|
+
if (params.isNewUser) {
|
975
|
+
// sync items from cart to wallet if a new user is detected
|
976
|
+
store
|
977
|
+
.getCart()
|
978
|
+
.then((cartContent) => walletAPI.addItems(cartContent).catch(logger.error))
|
979
|
+
.then(() => initComponent())
|
980
|
+
.catch((err) => logger.error(err));
|
926
981
|
}
|
927
|
-
|
928
|
-
|
929
|
-
if (canLog()) {
|
930
|
-
console.dir(...args);
|
982
|
+
else {
|
983
|
+
initComponent();
|
931
984
|
}
|
932
|
-
}
|
985
|
+
}
|
933
986
|
};
|
934
987
|
|
935
988
|
const transformItems = (data) => {
|
@@ -943,44 +996,28 @@ var ProvidersBlotoutWalletSdk = (function () {
|
|
943
996
|
}));
|
944
997
|
};
|
945
998
|
const tag = (params) => {
|
946
|
-
|
947
|
-
if (!
|
999
|
+
var _a;
|
1000
|
+
if (!((_a = window === null || window === void 0 ? void 0 : window[registryKey]) === null || _a === void 0 ? void 0 : _a.walletAPI)) {
|
1001
|
+
logger.error(`[Blotout Wallet] No wallet API available`);
|
948
1002
|
return;
|
949
1003
|
}
|
1004
|
+
const wallet = window[registryKey].walletAPI;
|
950
1005
|
switch (params.eventName) {
|
951
1006
|
case 'AddToCart': {
|
952
1007
|
const items = transformItems(params.data);
|
953
|
-
if (items) {
|
1008
|
+
if (items === null || items === void 0 ? void 0 : items.length) {
|
954
1009
|
wallet.addItems(items).catch(logger.error);
|
955
1010
|
}
|
956
1011
|
return;
|
957
1012
|
}
|
958
|
-
case 'InitiateCheckout': {
|
959
|
-
const items = transformItems(params.data);
|
960
|
-
if (items) {
|
961
|
-
wallet.setItems(items).catch(logger.error);
|
962
|
-
}
|
963
|
-
return;
|
964
|
-
}
|
965
|
-
case 'Purchase': {
|
966
|
-
const { orderId } = params.data;
|
967
|
-
wallet.purchase(orderId).catch(logger.error);
|
968
|
-
return;
|
969
|
-
}
|
970
1013
|
}
|
971
1014
|
};
|
972
1015
|
|
973
|
-
// eslint-disable-next-line @nx/enforce-module-boundaries
|
974
|
-
const user = (params) => {
|
975
|
-
console.log(`[${packageName}]: user`, params);
|
976
|
-
};
|
977
|
-
|
978
1016
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
979
1017
|
const data = {
|
980
1018
|
name: packageName,
|
981
1019
|
init,
|
982
1020
|
tag,
|
983
|
-
user,
|
984
1021
|
};
|
985
1022
|
try {
|
986
1023
|
if (window) {
|