@solucx/react-native-solucx-widget 0.2.0 → 0.2.2
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/lib/SoluCXWidget.d.ts +12 -0
- package/lib/SoluCXWidget.d.ts.map +1 -0
- package/lib/SoluCXWidget.js +110 -0
- package/lib/SoluCXWidget.js.map +1 -0
- package/lib/components/CloseButton.d.ts +8 -0
- package/lib/components/CloseButton.d.ts.map +1 -0
- package/lib/components/CloseButton.js +31 -0
- package/lib/components/CloseButton.js.map +1 -0
- package/lib/components/InlineWidget.d.ts +10 -0
- package/lib/components/InlineWidget.d.ts.map +1 -0
- package/lib/components/InlineWidget.js +19 -0
- package/lib/components/InlineWidget.js.map +1 -0
- package/lib/components/ModalWidget.d.ts +10 -0
- package/lib/components/ModalWidget.d.ts.map +1 -0
- package/lib/components/ModalWidget.js +27 -0
- package/lib/components/ModalWidget.js.map +1 -0
- package/lib/components/OverlayWidget.d.ts +12 -0
- package/lib/components/OverlayWidget.d.ts.map +1 -0
- package/lib/components/OverlayWidget.js +55 -0
- package/lib/components/OverlayWidget.js.map +1 -0
- package/lib/constants/Constants.d.ts +3 -0
- package/lib/constants/Constants.d.ts.map +1 -0
- package/lib/constants/Constants.js +10 -0
- package/lib/constants/Constants.js.map +1 -0
- package/lib/constants/webViewConstants.d.ts +12 -0
- package/lib/constants/webViewConstants.d.ts.map +1 -0
- package/lib/constants/webViewConstants.js +19 -0
- package/lib/constants/webViewConstants.js.map +1 -0
- package/lib/hooks/index.d.ts +3 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +8 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useDeviceInfoCollector.d.ts +14 -0
- package/lib/hooks/useDeviceInfoCollector.d.ts.map +1 -0
- package/lib/hooks/useDeviceInfoCollector.js +54 -0
- package/lib/hooks/useDeviceInfoCollector.js.map +1 -0
- package/lib/hooks/useHeightAnimation.d.ts +9 -0
- package/lib/hooks/useHeightAnimation.d.ts.map +1 -0
- package/lib/hooks/useHeightAnimation.js +19 -0
- package/lib/hooks/useHeightAnimation.js.map +1 -0
- package/lib/hooks/useWidgetHeight.d.ts +13 -0
- package/lib/hooks/useWidgetHeight.d.ts.map +1 -0
- package/lib/hooks/useWidgetHeight.js +21 -0
- package/lib/hooks/useWidgetHeight.js.map +1 -0
- package/lib/hooks/useWidgetState.d.ts +15 -0
- package/lib/hooks/useWidgetState.d.ts.map +1 -0
- package/lib/hooks/useWidgetState.js +79 -0
- package/lib/hooks/useWidgetState.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +43 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/WidgetCallbacks.d.ts +14 -0
- package/lib/interfaces/WidgetCallbacks.d.ts.map +1 -0
- package/lib/interfaces/WidgetCallbacks.js +3 -0
- package/lib/interfaces/WidgetCallbacks.js.map +1 -0
- package/lib/interfaces/WidgetData.d.ts +21 -0
- package/lib/interfaces/WidgetData.d.ts.map +1 -0
- package/lib/interfaces/WidgetData.js +3 -0
- package/lib/interfaces/WidgetData.js.map +1 -0
- package/lib/interfaces/WidgetOptions.d.ts +9 -0
- package/lib/interfaces/WidgetOptions.d.ts.map +1 -0
- package/lib/interfaces/WidgetOptions.js +3 -0
- package/lib/interfaces/WidgetOptions.js.map +1 -0
- package/lib/interfaces/WidgetResponse.d.ts +10 -0
- package/lib/interfaces/WidgetResponse.d.ts.map +1 -0
- package/lib/interfaces/WidgetResponse.js +12 -0
- package/lib/interfaces/WidgetResponse.js.map +1 -0
- package/lib/interfaces/WidgetSamplerLog.d.ts +7 -0
- package/lib/interfaces/WidgetSamplerLog.d.ts.map +1 -0
- package/lib/interfaces/WidgetSamplerLog.js +3 -0
- package/lib/interfaces/WidgetSamplerLog.js.map +1 -0
- package/lib/interfaces/index.d.ts +12 -0
- package/lib/interfaces/index.d.ts.map +1 -0
- package/lib/interfaces/index.js +3 -0
- package/lib/interfaces/index.js.map +1 -0
- package/lib/services/ClientVersionCollector.d.ts +2 -0
- package/lib/services/ClientVersionCollector.d.ts.map +1 -0
- package/lib/services/ClientVersionCollector.js +20 -0
- package/lib/services/ClientVersionCollector.js.map +1 -0
- package/lib/services/storage.d.ts +8 -0
- package/lib/services/storage.d.ts.map +1 -0
- package/lib/services/storage.js +23 -0
- package/lib/services/storage.js.map +1 -0
- package/lib/services/widgetBootstrapService.d.ts +5 -0
- package/lib/services/widgetBootstrapService.d.ts.map +1 -0
- package/lib/services/widgetBootstrapService.js +60 -0
- package/lib/services/widgetBootstrapService.js.map +1 -0
- package/lib/services/widgetEventService.d.ts +19 -0
- package/lib/services/widgetEventService.d.ts.map +1 -0
- package/lib/services/widgetEventService.js +79 -0
- package/lib/services/widgetEventService.js.map +1 -0
- package/lib/services/widgetValidationService.d.ts +18 -0
- package/lib/services/widgetValidationService.d.ts.map +1 -0
- package/lib/services/widgetValidationService.js +71 -0
- package/lib/services/widgetValidationService.js.map +1 -0
- package/lib/styles/widgetStyles.d.ts +87 -0
- package/lib/styles/widgetStyles.d.ts.map +1 -0
- package/lib/styles/widgetStyles.js +59 -0
- package/lib/styles/widgetStyles.js.map +1 -0
- package/lib/utils/urlUtils.d.ts +3 -0
- package/lib/utils/urlUtils.d.ts.map +1 -0
- package/lib/utils/urlUtils.js +13 -0
- package/lib/utils/urlUtils.js.map +1 -0
- package/package.json +5 -3
- package/src/SoluCXWidget.tsx +23 -17
- package/src/__tests__/SoluCXWidget.rendering.test.tsx +492 -153
- package/src/__tests__/e2e/widget-lifecycle.test.tsx +9 -10
- package/src/__tests__/integration/webview-communication.test.tsx +9 -9
- package/src/__tests__/useWidgetState.test.ts +2 -2
- package/src/__tests__/widgetBootstrapService.test.ts +45 -10
- package/src/hooks/useWidgetState.ts +3 -3
- package/src/interfaces/WidgetCallbacks.ts +0 -1
- package/src/services/widgetBootstrapService.ts +13 -4
- package/src/services/widgetEventService.ts +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WidgetOptions } from "../interfaces";
|
|
2
|
+
export type BlockReason = "BLOCKED_BY_RATING_INTERVAL" | "BLOCKED_BY_PARTIAL_INTERVAL" | "BLOCKED_BY_MAX_RETRY_ATTEMPTS";
|
|
3
|
+
export interface WidgetDisplayResult {
|
|
4
|
+
canDisplay: boolean;
|
|
5
|
+
blockReason?: BlockReason;
|
|
6
|
+
}
|
|
7
|
+
export declare class WidgetValidationService {
|
|
8
|
+
private storageService;
|
|
9
|
+
constructor(userId: string);
|
|
10
|
+
shouldDisplayWidget(widgetOptions: WidgetOptions): Promise<WidgetDisplayResult>;
|
|
11
|
+
private getLog;
|
|
12
|
+
private setLog;
|
|
13
|
+
private isWithinCollectInterval;
|
|
14
|
+
private isWithinCollectPartialInterval;
|
|
15
|
+
private isWithinRetryInterval;
|
|
16
|
+
private resetAttemptsIfNeeded;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=widgetValidationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetValidationService.d.ts","sourceRoot":"","sources":["../../src/services/widgetValidationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,eAAe,CAAC;AAGrE,MAAM,MAAM,WAAW,GACjB,4BAA4B,GAC5B,6BAA6B,GAC7B,+BAA+B,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED,qBAAa,uBAAuB;IAChC,OAAO,CAAC,cAAc,CAAiB;gBAE3B,MAAM,EAAE,MAAM;IAIpB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAsBvE,MAAM;YAcN,MAAM;IAQpB,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,8BAA8B;IAUtC,OAAO,CAAC,qBAAqB;YAYf,qBAAqB;CAKtC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WidgetValidationService = void 0;
|
|
4
|
+
const storage_1 = require("./storage");
|
|
5
|
+
class WidgetValidationService {
|
|
6
|
+
constructor(userId) {
|
|
7
|
+
this.storageService = new storage_1.StorageService(userId);
|
|
8
|
+
}
|
|
9
|
+
async shouldDisplayWidget(widgetOptions) {
|
|
10
|
+
const { retry, waitDelayAfterRating = 60 } = widgetOptions;
|
|
11
|
+
const { attempts = 5, interval = 1 } = retry || {};
|
|
12
|
+
const userLog = await this.getLog();
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
const dayInMilliseconds = 86400000;
|
|
15
|
+
if (this.isWithinCollectInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds)) {
|
|
16
|
+
return { canDisplay: false, blockReason: "BLOCKED_BY_RATING_INTERVAL" };
|
|
17
|
+
}
|
|
18
|
+
if (this.isWithinCollectPartialInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds)) {
|
|
19
|
+
return { canDisplay: false, blockReason: "BLOCKED_BY_PARTIAL_INTERVAL" };
|
|
20
|
+
}
|
|
21
|
+
if (this.isWithinRetryInterval(userLog, interval, attempts, now, dayInMilliseconds)) {
|
|
22
|
+
return { canDisplay: false, blockReason: "BLOCKED_BY_MAX_RETRY_ATTEMPTS" };
|
|
23
|
+
}
|
|
24
|
+
await this.resetAttemptsIfNeeded(userLog, attempts);
|
|
25
|
+
await this.setLog(userLog);
|
|
26
|
+
return { canDisplay: true };
|
|
27
|
+
}
|
|
28
|
+
async getLog() {
|
|
29
|
+
try {
|
|
30
|
+
return await this.storageService.read();
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error("Error reading widget log:", error);
|
|
34
|
+
return {
|
|
35
|
+
attempts: 0,
|
|
36
|
+
lastAttempt: 0,
|
|
37
|
+
lastRating: 0,
|
|
38
|
+
lastParcial: 0,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async setLog(userLog) {
|
|
43
|
+
try {
|
|
44
|
+
await this.storageService.write(userLog);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error("Error writing widget log:", error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
isWithinCollectInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds) {
|
|
51
|
+
const timeSinceLastRating = now - userLog.lastRating;
|
|
52
|
+
return userLog.lastRating > 0 && timeSinceLastRating < waitDelayAfterRating * dayInMilliseconds;
|
|
53
|
+
}
|
|
54
|
+
isWithinCollectPartialInterval(userLog, waitDelayAfterRating, now, dayInMilliseconds) {
|
|
55
|
+
const timeSinceLastPartial = now - userLog.lastParcial;
|
|
56
|
+
return userLog.lastParcial > 0 && timeSinceLastPartial < waitDelayAfterRating * dayInMilliseconds;
|
|
57
|
+
}
|
|
58
|
+
isWithinRetryInterval(userLog, interval, attempts, now, dayInMilliseconds) {
|
|
59
|
+
if (userLog.attempts < attempts)
|
|
60
|
+
return false;
|
|
61
|
+
const timeSinceLastAttempt = now - userLog.lastAttempt;
|
|
62
|
+
return timeSinceLastAttempt < interval * dayInMilliseconds;
|
|
63
|
+
}
|
|
64
|
+
async resetAttemptsIfNeeded(userLog, maxAttempts) {
|
|
65
|
+
if (userLog.attempts >= maxAttempts) {
|
|
66
|
+
userLog.attempts = 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.WidgetValidationService = WidgetValidationService;
|
|
71
|
+
//# sourceMappingURL=widgetValidationService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetValidationService.js","sourceRoot":"","sources":["../../src/services/widgetValidationService.ts"],"names":[],"mappings":";;;AACA,uCAA2C;AAY3C,MAAa,uBAAuB;IAGhC,YAAY,MAAc;QACtB,IAAI,CAAC,cAAc,GAAG,IAAI,wBAA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,OAAO,oBAAoB,GAAG,QAAQ,GAAG,iBAAiB,CAAC;IAC/D,CAAC;IAEO,KAAK,CAAC,qBAAqB,CAAC,OAAyB,EAAE,WAAmB;QAC9E,IAAI,OAAO,CAAC,QAAQ,IAAI,WAAW,EAAE,CAAC;YAClC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACzB,CAAC;IACL,CAAC;CACJ;AAxFD,0DAwFC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { WidgetType } from '../interfaces';
|
|
2
|
+
export declare const styles: {
|
|
3
|
+
wrapper: {
|
|
4
|
+
flex: number;
|
|
5
|
+
justifyContent: "center";
|
|
6
|
+
alignItems: "center";
|
|
7
|
+
};
|
|
8
|
+
inlineWrapper: {
|
|
9
|
+
justifyContent: "center";
|
|
10
|
+
alignItems: "center";
|
|
11
|
+
};
|
|
12
|
+
bottom: {
|
|
13
|
+
position: "absolute";
|
|
14
|
+
bottom: number;
|
|
15
|
+
justifyContent: "center";
|
|
16
|
+
alignItems: "center";
|
|
17
|
+
};
|
|
18
|
+
top: {
|
|
19
|
+
position: "absolute";
|
|
20
|
+
top: number;
|
|
21
|
+
justifyContent: "center";
|
|
22
|
+
alignItems: "center";
|
|
23
|
+
};
|
|
24
|
+
inline: {
|
|
25
|
+
justifyContent: "center";
|
|
26
|
+
alignItems: "center";
|
|
27
|
+
};
|
|
28
|
+
modalOverlay: {
|
|
29
|
+
flex: number;
|
|
30
|
+
justifyContent: "center";
|
|
31
|
+
backgroundColor: string;
|
|
32
|
+
alignItems: "center";
|
|
33
|
+
};
|
|
34
|
+
modalContent: {
|
|
35
|
+
backgroundColor: string;
|
|
36
|
+
borderRadius: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare const getWidgetVisibility: (visibility: boolean) => {
|
|
40
|
+
opacity: number;
|
|
41
|
+
pointerEvents: "none" | "auto";
|
|
42
|
+
};
|
|
43
|
+
export declare const getWidgetStyles: (type: WidgetType) => {
|
|
44
|
+
container: {
|
|
45
|
+
flex: number;
|
|
46
|
+
justifyContent: "center";
|
|
47
|
+
alignItems: "center";
|
|
48
|
+
};
|
|
49
|
+
content: {
|
|
50
|
+
position: "absolute";
|
|
51
|
+
bottom: number;
|
|
52
|
+
justifyContent: "center";
|
|
53
|
+
alignItems: "center";
|
|
54
|
+
};
|
|
55
|
+
} | {
|
|
56
|
+
container: {
|
|
57
|
+
flex: number;
|
|
58
|
+
justifyContent: "center";
|
|
59
|
+
alignItems: "center";
|
|
60
|
+
};
|
|
61
|
+
content: {
|
|
62
|
+
position: "absolute";
|
|
63
|
+
top: number;
|
|
64
|
+
justifyContent: "center";
|
|
65
|
+
alignItems: "center";
|
|
66
|
+
};
|
|
67
|
+
} | {
|
|
68
|
+
container: {
|
|
69
|
+
justifyContent: "center";
|
|
70
|
+
alignItems: "center";
|
|
71
|
+
};
|
|
72
|
+
content: {
|
|
73
|
+
justifyContent: "center";
|
|
74
|
+
alignItems: "center";
|
|
75
|
+
};
|
|
76
|
+
} | {
|
|
77
|
+
container: {
|
|
78
|
+
flex: number;
|
|
79
|
+
justifyContent: "center";
|
|
80
|
+
alignItems: "center";
|
|
81
|
+
};
|
|
82
|
+
content: {
|
|
83
|
+
justifyContent: "center";
|
|
84
|
+
alignItems: "center";
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=widgetStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetStyles.d.ts","sourceRoot":"","sources":["../../src/styles/widgetStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCjB,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAAI,YAAY,OAAO;;;CAKtD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAS/C,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWidgetStyles = exports.getWidgetVisibility = exports.styles = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
exports.styles = react_native_1.StyleSheet.create({
|
|
6
|
+
wrapper: {
|
|
7
|
+
flex: 1,
|
|
8
|
+
justifyContent: 'center',
|
|
9
|
+
alignItems: 'center',
|
|
10
|
+
},
|
|
11
|
+
inlineWrapper: {
|
|
12
|
+
justifyContent: 'center',
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
},
|
|
15
|
+
bottom: {
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
bottom: 0,
|
|
18
|
+
justifyContent: 'center',
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
},
|
|
21
|
+
top: {
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
top: 0,
|
|
24
|
+
justifyContent: 'center',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
},
|
|
27
|
+
inline: {
|
|
28
|
+
justifyContent: 'center',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
},
|
|
31
|
+
modalOverlay: {
|
|
32
|
+
flex: 1,
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
},
|
|
37
|
+
modalContent: {
|
|
38
|
+
backgroundColor: 'white',
|
|
39
|
+
borderRadius: 10,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const getWidgetVisibility = (visibility) => {
|
|
43
|
+
return {
|
|
44
|
+
opacity: visibility ? 1 : 0,
|
|
45
|
+
pointerEvents: visibility ? 'auto' : 'none',
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.getWidgetVisibility = getWidgetVisibility;
|
|
49
|
+
const getWidgetStyles = (type) => {
|
|
50
|
+
const styleMap = {
|
|
51
|
+
'bottom': { container: exports.styles.wrapper, content: exports.styles.bottom },
|
|
52
|
+
'top': { container: exports.styles.wrapper, content: exports.styles.top },
|
|
53
|
+
'inline': { container: exports.styles.inlineWrapper, content: exports.styles.inline },
|
|
54
|
+
'modal': { container: exports.styles.wrapper, content: exports.styles.inline }
|
|
55
|
+
};
|
|
56
|
+
return styleMap[type] || styleMap.bottom;
|
|
57
|
+
};
|
|
58
|
+
exports.getWidgetStyles = getWidgetStyles;
|
|
59
|
+
//# sourceMappingURL=widgetStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetStyles.js","sourceRoot":"","sources":["../../src/styles/widgetStyles.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAG7B,QAAA,MAAM,GAAG,yBAAU,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE;QACL,IAAI,EAAE,CAAC;QACP,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,QAAQ;KACvB;IACD,aAAa,EAAE;QACX,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,QAAQ;KACvB;IACD,MAAM,EAAE;QACJ,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,CAAC;QACT,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,QAAQ;KACvB;IACD,GAAG,EAAE;QACD,QAAQ,EAAE,UAAU;QACpB,GAAG,EAAE,CAAC;QACN,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,QAAQ;KACvB;IACD,MAAM,EAAE;QACJ,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,QAAQ;KACvB;IACD,YAAY,EAAE;QACV,IAAI,EAAE,CAAC;QACP,cAAc,EAAE,QAAQ;QACxB,eAAe,EAAE,oBAAoB;QACrC,UAAU,EAAE,QAAQ;KACvB;IACD,YAAY,EAAE;QACV,eAAe,EAAE,OAAO;QACxB,YAAY,EAAE,EAAE;KACnB;CACJ,CAAC,CAAC;AAEI,MAAM,mBAAmB,GAAG,CAAC,UAAmB,EAAE,EAAE;IACvD,OAAO;QACH,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,MAAe,CAAC,CAAC,CAAC,MAAe;KAChE,CAAC;AACN,CAAC,CAAC;AALW,QAAA,mBAAmB,uBAK9B;AAEK,MAAM,eAAe,GAAG,CAAC,IAAgB,EAAE,EAAE;IAChD,MAAM,QAAQ,GAAG;QACb,QAAQ,EAAE,EAAE,SAAS,EAAE,cAAM,CAAC,OAAO,EAAE,OAAO,EAAE,cAAM,CAAC,MAAM,EAAE;QAC/D,KAAK,EAAE,EAAE,SAAS,EAAE,cAAM,CAAC,OAAO,EAAE,OAAO,EAAE,cAAM,CAAC,GAAG,EAAE;QACzD,QAAQ,EAAE,EAAE,SAAS,EAAE,cAAM,CAAC,aAAa,EAAE,OAAO,EAAE,cAAM,CAAC,MAAM,EAAE;QACrE,OAAO,EAAE,EAAE,SAAS,EAAE,cAAM,CAAC,OAAO,EAAE,OAAO,EAAE,cAAM,CAAC,MAAM,EAAE;KACjE,CAAC;IAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC;AAC7C,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../../src/utils/urlUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE3D,wBAAgB,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,CASvE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildWidgetURL = buildWidgetURL;
|
|
4
|
+
const webViewConstants_1 = require("../constants/webViewConstants");
|
|
5
|
+
function buildWidgetURL(key, data) {
|
|
6
|
+
const params = new URLSearchParams(data);
|
|
7
|
+
const baseURL = `${webViewConstants_1.BASE_URL}/${key}/?mode=widget`;
|
|
8
|
+
if (data.transaction_id) {
|
|
9
|
+
return `${baseURL}&${params.toString()}`;
|
|
10
|
+
}
|
|
11
|
+
return `${baseURL}&transaction_id=&${params.toString()}`;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=urlUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../../src/utils/urlUtils.ts"],"names":[],"mappings":";;AAGA,wCASC;AAZD,oEAAyD;AAGzD,SAAgB,cAAc,CAAC,GAAc,EAAE,IAAgB;IAC3D,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,IAA8B,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,GAAG,2BAAQ,IAAI,GAAG,eAAe,CAAC;IAElD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,OAAO,GAAG,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7C,CAAC;IAED,OAAO,GAAG,OAAO,oBAAoB,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;AAC7D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solucx/react-native-solucx-widget",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "The React Native SDK for Solucx Widget",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
6
7
|
"author": " <> ()",
|
|
7
8
|
"homepage": "#readme",
|
|
8
9
|
"scripts": {
|
|
9
|
-
"build": "tsc",
|
|
10
|
+
"build": "tsc --project tsconfig.build.json",
|
|
10
11
|
"prepublishOnly": "npm run build",
|
|
11
12
|
"test": "jest"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
15
|
+
"lib/",
|
|
14
16
|
"src/",
|
|
15
17
|
"README.md"
|
|
16
18
|
],
|
package/src/SoluCXWidget.tsx
CHANGED
|
@@ -6,7 +6,6 @@ import type { SoluCXKey, WidgetData, WidgetOptions, WidgetType, WidgetCallbacks
|
|
|
6
6
|
import { useWidgetState } from "./hooks/useWidgetState";
|
|
7
7
|
import { WidgetEventService } from "./services/widgetEventService";
|
|
8
8
|
import { WidgetValidationService } from "./services/widgetValidationService";
|
|
9
|
-
import { buildWidgetURL } from "./utils/urlUtils";
|
|
10
9
|
import { WEB_VIEW_MESSAGE_LISTENER } from "./constants/webViewConstants";
|
|
11
10
|
import { ModalWidget } from "./components/ModalWidget";
|
|
12
11
|
import { InlineWidget } from "./components/InlineWidget";
|
|
@@ -25,6 +24,9 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({ soluCXKey, type, dat
|
|
|
25
24
|
const webviewRef = useRef<WebView>(null);
|
|
26
25
|
const { width } = Dimensions.get("window");
|
|
27
26
|
|
|
27
|
+
const callbacksRef = useRef(callbacks);
|
|
28
|
+
callbacksRef.current = callbacks;
|
|
29
|
+
|
|
28
30
|
const serializedData = JSON.stringify(data);
|
|
29
31
|
const normalizedData = useMemo(() => data, [serializedData]);
|
|
30
32
|
|
|
@@ -32,15 +34,13 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({ soluCXKey, type, dat
|
|
|
32
34
|
useWidgetState(normalizedData, options, type);
|
|
33
35
|
|
|
34
36
|
const eventService = useMemo(
|
|
35
|
-
() => new WidgetEventService(setIsWidgetVisible, resize, userId,
|
|
37
|
+
() => new WidgetEventService(setIsWidgetVisible, resize, userId, callbacksRef.current),
|
|
36
38
|
[setIsWidgetVisible, resize],
|
|
37
39
|
);
|
|
38
40
|
|
|
39
41
|
const validationService = useMemo(() => new WidgetValidationService(userId), [userId]);
|
|
40
|
-
const isForm = Boolean(normalizedData
|
|
41
|
-
const [widgetUri, setWidgetUri] = useState<string | null>(
|
|
42
|
-
isForm ? buildWidgetURL(soluCXKey, normalizedData) : null,
|
|
43
|
-
);
|
|
42
|
+
const isForm = Boolean(normalizedData?.form_id);
|
|
43
|
+
const [widgetUri, setWidgetUri] = useState<string | null>(null);
|
|
44
44
|
|
|
45
45
|
useEffect(() => {
|
|
46
46
|
loadSavedData();
|
|
@@ -50,12 +50,7 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({ soluCXKey, type, dat
|
|
|
50
50
|
let isActive = true;
|
|
51
51
|
|
|
52
52
|
const prepareWidgetURL = async () => {
|
|
53
|
-
if (
|
|
54
|
-
setWidgetUri(buildWidgetURL(soluCXKey, normalizedData));
|
|
55
|
-
open(); // Show widget in form mode
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
53
|
+
if (!data) return;
|
|
59
54
|
setWidgetUri(null);
|
|
60
55
|
|
|
61
56
|
try {
|
|
@@ -67,18 +62,24 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({ soluCXKey, type, dat
|
|
|
67
62
|
|
|
68
63
|
if (!result.canDisplay) {
|
|
69
64
|
const blockReason = result?.blockReason;
|
|
70
|
-
|
|
65
|
+
callbacksRef.current?.onBlock?.(blockReason);
|
|
71
66
|
setIsWidgetVisible(false);
|
|
72
67
|
return;
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
|
|
70
|
+
callbacksRef.current?.onPreOpen?.(userId);
|
|
76
71
|
open();
|
|
77
72
|
setWidgetUri(widgetUrl);
|
|
78
|
-
|
|
73
|
+
callbacksRef.current?.onOpened?.(userId);
|
|
79
74
|
} catch (error) {
|
|
80
75
|
if (isActive) {
|
|
81
|
-
|
|
76
|
+
let errorMessage = "Unknown error";
|
|
77
|
+
|
|
78
|
+
if (error instanceof Error) errorMessage = error.message;
|
|
79
|
+
else if (typeof error === "string") errorMessage = error;
|
|
80
|
+
else if (error !== null && typeof error === "object") errorMessage = JSON.stringify(error);
|
|
81
|
+
|
|
82
|
+
callbacksRef.current?.onError?.(errorMessage);
|
|
82
83
|
setIsWidgetVisible(false);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
@@ -89,7 +90,7 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({ soluCXKey, type, dat
|
|
|
89
90
|
return () => {
|
|
90
91
|
isActive = false;
|
|
91
92
|
};
|
|
92
|
-
}, [validationService, soluCXKey, normalizedData, isForm, setIsWidgetVisible, options, open, userId
|
|
93
|
+
}, [validationService, soluCXKey, normalizedData, isForm, setIsWidgetVisible, options, open, userId]);
|
|
93
94
|
|
|
94
95
|
const handleWebViewMessage = useCallback(
|
|
95
96
|
async (message: string) => {
|
|
@@ -117,6 +118,11 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({ soluCXKey, type, dat
|
|
|
117
118
|
|
|
118
119
|
const webViewStyle = [{ height: widgetHeight }, { width }];
|
|
119
120
|
|
|
121
|
+
if (!data) {
|
|
122
|
+
callbacksRef.current?.onError?.("Widget data is required but was not provided");
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
120
126
|
if (!widgetUri) {
|
|
121
127
|
return null;
|
|
122
128
|
}
|