@ordersune/crm-web-sdk 1.0.7 → 1.0.8
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/dist/types/index.d.ts +46 -0
- package/dist/web-sdk.d.ts +5 -0
- package/dist/web-sdk.js +214 -1
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -31,8 +31,54 @@ export interface DeviceDetails {
|
|
|
31
31
|
screenResolution: string;
|
|
32
32
|
userAgent: string;
|
|
33
33
|
platform: string;
|
|
34
|
+
pushToken?: string;
|
|
34
35
|
}
|
|
35
36
|
export interface BrowserInfo {
|
|
36
37
|
browserType: string;
|
|
37
38
|
browserVersion: string;
|
|
38
39
|
}
|
|
40
|
+
export interface ButtonProperties {
|
|
41
|
+
backgroundColor: string;
|
|
42
|
+
borderColor: string;
|
|
43
|
+
textColor: string;
|
|
44
|
+
androidOnClickValue?: string;
|
|
45
|
+
androidOnClickAction?: string;
|
|
46
|
+
iOSOnClickValue?: string;
|
|
47
|
+
iOSOnClickAction?: string;
|
|
48
|
+
type?: string;
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
}
|
|
51
|
+
export interface ModalConfig {
|
|
52
|
+
button1: ButtonProperties;
|
|
53
|
+
button2: ButtonProperties;
|
|
54
|
+
dismissMessageAutomatically: boolean;
|
|
55
|
+
dismissMessageInSeconds: string;
|
|
56
|
+
headerColor: string;
|
|
57
|
+
messageColor: string;
|
|
58
|
+
closeColor: string;
|
|
59
|
+
}
|
|
60
|
+
export interface MediaConfig {
|
|
61
|
+
inAppImage: string;
|
|
62
|
+
}
|
|
63
|
+
export interface InAppMessageData {
|
|
64
|
+
header: string;
|
|
65
|
+
message: string;
|
|
66
|
+
modal: ModalConfig;
|
|
67
|
+
mediaConfig: MediaConfig;
|
|
68
|
+
}
|
|
69
|
+
export interface ShowInAppMessageOptions {
|
|
70
|
+
context?: any;
|
|
71
|
+
title: string;
|
|
72
|
+
body: string;
|
|
73
|
+
primaryButtonText: string;
|
|
74
|
+
secondaryButtonText?: string;
|
|
75
|
+
imageUrl: string;
|
|
76
|
+
onClose?: () => void;
|
|
77
|
+
buttonPropertiesPrimary: ButtonProperties;
|
|
78
|
+
buttonPropertiesSecondary: ButtonProperties;
|
|
79
|
+
dismissMessageAutomatically: boolean;
|
|
80
|
+
dismissMessageInSeconds: string;
|
|
81
|
+
headerColor: string;
|
|
82
|
+
messageColor: string;
|
|
83
|
+
closeColor: string;
|
|
84
|
+
}
|
package/dist/web-sdk.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare class WebSDK {
|
|
|
19
19
|
identify(userId: string): void;
|
|
20
20
|
clearUserData(): void;
|
|
21
21
|
trackEvent(eventName: string, properties?: Record<string, any>, options?: EventOptions): void;
|
|
22
|
+
setToken(token: string): void;
|
|
22
23
|
trackCustomAttribute(attributeName: string, attributeValue: any): void;
|
|
23
24
|
logProductPurchase(orderId: string, itemId: string, itemName: string, unitPrice: number, quantity: number, source: string, channel: string, itemCategory?: string): void;
|
|
24
25
|
getUserProfile(): UserProfile | undefined;
|
|
@@ -41,4 +42,8 @@ export declare class WebSDK {
|
|
|
41
42
|
private queueEvent;
|
|
42
43
|
private processBatch;
|
|
43
44
|
private sendBatchToServer;
|
|
45
|
+
displayInAppMessage(inAppMessageData: string, context?: any): void;
|
|
46
|
+
private hexToColor;
|
|
47
|
+
private openWebUrl;
|
|
48
|
+
private showInAppMessage;
|
|
44
49
|
}
|
package/dist/web-sdk.js
CHANGED
|
@@ -102,6 +102,9 @@ class WebSDK {
|
|
|
102
102
|
};
|
|
103
103
|
this.queueEvent(payload);
|
|
104
104
|
}
|
|
105
|
+
setToken(token) {
|
|
106
|
+
this.deviceDetails.pushToken = token;
|
|
107
|
+
}
|
|
105
108
|
trackCustomAttribute(attributeName, attributeValue) {
|
|
106
109
|
if (!attributeName || typeof attributeName !== "string") {
|
|
107
110
|
throw new Error("Attribute name is required and must be a string");
|
|
@@ -215,7 +218,7 @@ class WebSDK {
|
|
|
215
218
|
language: navigator.language,
|
|
216
219
|
screenResolution: `${window.screen.width}x${window.screen.height}`,
|
|
217
220
|
userAgent: navigator.userAgent,
|
|
218
|
-
platform:
|
|
221
|
+
platform: 'web',
|
|
219
222
|
};
|
|
220
223
|
}
|
|
221
224
|
async getBrowserInfo() {
|
|
@@ -395,5 +398,215 @@ class WebSDK {
|
|
|
395
398
|
throw error;
|
|
396
399
|
}
|
|
397
400
|
}
|
|
401
|
+
displayInAppMessage(inAppMessageData, context) {
|
|
402
|
+
const transformedData = JSON.parse(inAppMessageData);
|
|
403
|
+
const title = transformedData.header;
|
|
404
|
+
const body = transformedData.message;
|
|
405
|
+
const buttonDataPrimary = transformedData.modal.button1;
|
|
406
|
+
const buttonDataSecondary = transformedData.modal.button2;
|
|
407
|
+
const buttonTextPrimary = buttonDataPrimary.type || "";
|
|
408
|
+
const buttonTextSecondary = buttonDataSecondary.type || "";
|
|
409
|
+
const imageUrl = transformedData.mediaConfig.inAppImage;
|
|
410
|
+
this.showInAppMessage({
|
|
411
|
+
context,
|
|
412
|
+
title,
|
|
413
|
+
body,
|
|
414
|
+
primaryButtonText: buttonTextPrimary,
|
|
415
|
+
secondaryButtonText: buttonTextSecondary,
|
|
416
|
+
imageUrl,
|
|
417
|
+
buttonPropertiesPrimary: buttonDataPrimary,
|
|
418
|
+
buttonPropertiesSecondary: buttonDataSecondary,
|
|
419
|
+
dismissMessageAutomatically: transformedData.modal.dismissMessageAutomatically,
|
|
420
|
+
dismissMessageInSeconds: transformedData.modal.dismissMessageInSeconds,
|
|
421
|
+
headerColor: transformedData.modal.headerColor,
|
|
422
|
+
messageColor: transformedData.modal.messageColor,
|
|
423
|
+
closeColor: transformedData.modal.closeColor
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
hexToColor(hexColor) {
|
|
427
|
+
hexColor = hexColor.toUpperCase().replace("#", "");
|
|
428
|
+
if (hexColor.length === 6) {
|
|
429
|
+
return `#${hexColor}`;
|
|
430
|
+
}
|
|
431
|
+
return `#${hexColor.substring(2)}`;
|
|
432
|
+
}
|
|
433
|
+
openWebUrl(url) {
|
|
434
|
+
if (url) {
|
|
435
|
+
window.open(url, '_blank');
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
showInAppMessage(options) {
|
|
439
|
+
const { title, body, primaryButtonText, secondaryButtonText, imageUrl, onClose, buttonPropertiesPrimary, buttonPropertiesSecondary, dismissMessageAutomatically, dismissMessageInSeconds, headerColor, messageColor, closeColor } = options;
|
|
440
|
+
// Create modal container
|
|
441
|
+
const modalOverlay = document.createElement('div');
|
|
442
|
+
modalOverlay.style.position = 'fixed';
|
|
443
|
+
modalOverlay.style.top = '0';
|
|
444
|
+
modalOverlay.style.left = '0';
|
|
445
|
+
modalOverlay.style.width = '100%';
|
|
446
|
+
modalOverlay.style.height = '100%';
|
|
447
|
+
modalOverlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
|
|
448
|
+
modalOverlay.style.display = 'flex';
|
|
449
|
+
modalOverlay.style.justifyContent = 'center';
|
|
450
|
+
modalOverlay.style.alignItems = 'center';
|
|
451
|
+
modalOverlay.style.zIndex = '9999';
|
|
452
|
+
// Create modal dialog
|
|
453
|
+
const modalDialog = document.createElement('div');
|
|
454
|
+
modalDialog.style.backgroundColor = 'white';
|
|
455
|
+
modalDialog.style.borderRadius = '12px';
|
|
456
|
+
modalDialog.style.padding = '16px';
|
|
457
|
+
modalDialog.style.maxWidth = '400px';
|
|
458
|
+
modalDialog.style.width = '90%';
|
|
459
|
+
modalDialog.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
|
|
460
|
+
modalDialog.style.position = 'relative';
|
|
461
|
+
// Close button
|
|
462
|
+
const closeButton = document.createElement('button');
|
|
463
|
+
closeButton.innerHTML = '×';
|
|
464
|
+
closeButton.style.position = 'absolute';
|
|
465
|
+
closeButton.style.top = '8px';
|
|
466
|
+
closeButton.style.right = '8px';
|
|
467
|
+
closeButton.style.background = 'none';
|
|
468
|
+
closeButton.style.border = 'none';
|
|
469
|
+
closeButton.style.fontSize = '20px';
|
|
470
|
+
closeButton.style.cursor = 'pointer';
|
|
471
|
+
closeButton.style.color = this.hexToColor(closeColor);
|
|
472
|
+
closeButton.onclick = () => {
|
|
473
|
+
if (onClose) {
|
|
474
|
+
onClose();
|
|
475
|
+
}
|
|
476
|
+
document.body.removeChild(modalOverlay);
|
|
477
|
+
};
|
|
478
|
+
// Create content
|
|
479
|
+
const contentContainer = document.createElement('div');
|
|
480
|
+
contentContainer.style.display = 'flex';
|
|
481
|
+
contentContainer.style.flexDirection = 'column';
|
|
482
|
+
contentContainer.style.alignItems = 'center';
|
|
483
|
+
contentContainer.style.textAlign = 'center';
|
|
484
|
+
// Image
|
|
485
|
+
if (imageUrl && imageUrl.trim() !== '') {
|
|
486
|
+
const image = document.createElement('img');
|
|
487
|
+
image.src = imageUrl;
|
|
488
|
+
image.style.width = '100px';
|
|
489
|
+
image.style.height = '100px';
|
|
490
|
+
image.style.marginBottom = '16px';
|
|
491
|
+
image.style.marginTop = '16px';
|
|
492
|
+
image.onerror = () => {
|
|
493
|
+
image.style.display = 'none';
|
|
494
|
+
};
|
|
495
|
+
contentContainer.appendChild(image);
|
|
496
|
+
}
|
|
497
|
+
// Title
|
|
498
|
+
const titleElement = document.createElement('h2');
|
|
499
|
+
titleElement.textContent = title;
|
|
500
|
+
titleElement.style.fontSize = '22px';
|
|
501
|
+
titleElement.style.fontWeight = '600';
|
|
502
|
+
titleElement.style.color = this.hexToColor(headerColor);
|
|
503
|
+
titleElement.style.margin = '8px 0';
|
|
504
|
+
contentContainer.appendChild(titleElement);
|
|
505
|
+
// Body
|
|
506
|
+
const bodyElement = document.createElement('p');
|
|
507
|
+
bodyElement.textContent = body;
|
|
508
|
+
bodyElement.style.fontSize = '14px';
|
|
509
|
+
bodyElement.style.color = this.hexToColor(messageColor);
|
|
510
|
+
bodyElement.style.fontWeight = '500';
|
|
511
|
+
bodyElement.style.margin = '8px 0 24px 0';
|
|
512
|
+
contentContainer.appendChild(bodyElement);
|
|
513
|
+
// Button handlers
|
|
514
|
+
const onPrimaryButtonPress = () => {
|
|
515
|
+
if (buttonPropertiesPrimary.webOnClickValue === "redirect_to_web_url" ||
|
|
516
|
+
buttonPropertiesPrimary.webOnClickValue === "deeplink_into_app") {
|
|
517
|
+
this.openWebUrl(buttonPropertiesPrimary.webOnClickAction || '');
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
const onSecondaryButtonPress = () => {
|
|
521
|
+
if (buttonPropertiesSecondary.webOnClickValue === "redirect_to_web_url" ||
|
|
522
|
+
buttonPropertiesSecondary.webOnClickValue === "deeplink_into_app") {
|
|
523
|
+
this.openWebUrl(buttonPropertiesSecondary.webOnClickAction || '');
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
// Create buttons
|
|
527
|
+
const buttonsContainer = document.createElement('div');
|
|
528
|
+
buttonsContainer.style.display = 'flex';
|
|
529
|
+
buttonsContainer.style.justifyContent = 'center';
|
|
530
|
+
buttonsContainer.style.width = '100%';
|
|
531
|
+
buttonsContainer.style.gap = '16px';
|
|
532
|
+
if (secondaryButtonText && secondaryButtonText.trim() !== '') {
|
|
533
|
+
// Primary button
|
|
534
|
+
const primaryButton = document.createElement('button');
|
|
535
|
+
primaryButton.textContent = primaryButtonText;
|
|
536
|
+
primaryButton.style.flex = '1';
|
|
537
|
+
primaryButton.style.maxWidth = '140px';
|
|
538
|
+
primaryButton.style.padding = '12px';
|
|
539
|
+
primaryButton.style.backgroundColor = this.hexToColor(buttonPropertiesPrimary.backgroundColor);
|
|
540
|
+
primaryButton.style.color = this.hexToColor(buttonPropertiesPrimary.textColor);
|
|
541
|
+
primaryButton.style.border = `2px solid ${this.hexToColor(buttonPropertiesPrimary.borderColor)}`;
|
|
542
|
+
primaryButton.style.borderRadius = '8px';
|
|
543
|
+
primaryButton.style.fontSize = '16px';
|
|
544
|
+
primaryButton.style.fontWeight = '600';
|
|
545
|
+
primaryButton.style.cursor = 'pointer';
|
|
546
|
+
primaryButton.onclick = () => {
|
|
547
|
+
document.body.removeChild(modalOverlay);
|
|
548
|
+
onPrimaryButtonPress();
|
|
549
|
+
};
|
|
550
|
+
buttonsContainer.appendChild(primaryButton);
|
|
551
|
+
// Secondary button
|
|
552
|
+
const secondaryButton = document.createElement('button');
|
|
553
|
+
secondaryButton.textContent = secondaryButtonText;
|
|
554
|
+
secondaryButton.style.flex = '1';
|
|
555
|
+
secondaryButton.style.maxWidth = '140px';
|
|
556
|
+
secondaryButton.style.padding = '12px';
|
|
557
|
+
secondaryButton.style.backgroundColor = this.hexToColor(buttonPropertiesSecondary.backgroundColor);
|
|
558
|
+
secondaryButton.style.color = this.hexToColor(buttonPropertiesSecondary.textColor);
|
|
559
|
+
secondaryButton.style.border = `2px solid ${this.hexToColor(buttonPropertiesSecondary.borderColor)}`;
|
|
560
|
+
secondaryButton.style.borderRadius = '8px';
|
|
561
|
+
secondaryButton.style.fontSize = '16px';
|
|
562
|
+
secondaryButton.style.fontWeight = '600';
|
|
563
|
+
secondaryButton.style.cursor = 'pointer';
|
|
564
|
+
secondaryButton.onclick = () => {
|
|
565
|
+
document.body.removeChild(modalOverlay);
|
|
566
|
+
onSecondaryButtonPress();
|
|
567
|
+
};
|
|
568
|
+
buttonsContainer.appendChild(secondaryButton);
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
// Single button
|
|
572
|
+
const primaryButton = document.createElement('button');
|
|
573
|
+
primaryButton.textContent = primaryButtonText;
|
|
574
|
+
primaryButton.style.width = '100%';
|
|
575
|
+
primaryButton.style.padding = '12px';
|
|
576
|
+
primaryButton.style.backgroundColor = this.hexToColor(buttonPropertiesPrimary.backgroundColor);
|
|
577
|
+
primaryButton.style.color = this.hexToColor(buttonPropertiesPrimary.textColor);
|
|
578
|
+
primaryButton.style.border = `2px solid ${this.hexToColor(buttonPropertiesPrimary.borderColor)}`;
|
|
579
|
+
primaryButton.style.borderRadius = '8px';
|
|
580
|
+
primaryButton.style.fontSize = '16px';
|
|
581
|
+
primaryButton.style.fontWeight = '600';
|
|
582
|
+
primaryButton.style.cursor = 'pointer';
|
|
583
|
+
primaryButton.onclick = () => {
|
|
584
|
+
document.body.removeChild(modalOverlay);
|
|
585
|
+
onPrimaryButtonPress();
|
|
586
|
+
};
|
|
587
|
+
buttonsContainer.appendChild(primaryButton);
|
|
588
|
+
}
|
|
589
|
+
// Add all elements to the modal
|
|
590
|
+
modalDialog.appendChild(closeButton);
|
|
591
|
+
modalDialog.appendChild(contentContainer);
|
|
592
|
+
contentContainer.appendChild(buttonsContainer);
|
|
593
|
+
modalOverlay.appendChild(modalDialog);
|
|
594
|
+
// Add to document
|
|
595
|
+
document.body.appendChild(modalOverlay);
|
|
596
|
+
// Auto dismiss if enabled
|
|
597
|
+
if (dismissMessageAutomatically) {
|
|
598
|
+
setTimeout(() => {
|
|
599
|
+
if (document.body.contains(modalOverlay)) {
|
|
600
|
+
document.body.removeChild(modalOverlay);
|
|
601
|
+
}
|
|
602
|
+
}, parseInt(dismissMessageInSeconds) * 1000);
|
|
603
|
+
}
|
|
604
|
+
// Add click event to close when clicking outside
|
|
605
|
+
modalOverlay.addEventListener('click', (event) => {
|
|
606
|
+
if (event.target === modalOverlay) {
|
|
607
|
+
document.body.removeChild(modalOverlay);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
}
|
|
398
611
|
}
|
|
399
612
|
exports.WebSDK = WebSDK;
|