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