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