@magicpixel/rn-mp-client-sdk 1.13.0 → 1.13.20
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/README.md +163 -14
- package/lib/commonjs/common/app-types.js.map +1 -1
- package/lib/commonjs/common/constants.js +11 -2
- package/lib/commonjs/common/constants.js.map +1 -1
- package/lib/commonjs/common/data-store.js +13 -30
- package/lib/commonjs/common/data-store.js.map +1 -1
- package/lib/commonjs/common/deeplink-helper.js +174 -0
- package/lib/commonjs/common/deeplink-helper.js.map +1 -0
- package/lib/commonjs/common/device-info-helper.js +168 -0
- package/lib/commonjs/common/device-info-helper.js.map +1 -0
- package/lib/commonjs/common/event-bus.js +39 -0
- package/lib/commonjs/common/event-bus.js.map +1 -1
- package/lib/commonjs/common/network-service.js +119 -15
- package/lib/commonjs/common/network-service.js.map +1 -1
- package/lib/commonjs/common/reporter.js +28 -10
- package/lib/commonjs/common/reporter.js.map +1 -1
- package/lib/commonjs/common/storage-helper.js +227 -0
- package/lib/commonjs/common/storage-helper.js.map +1 -0
- package/lib/commonjs/common/utils.js +20 -2
- package/lib/commonjs/common/utils.js.map +1 -1
- package/lib/commonjs/eedl/eedl.js +198 -44
- package/lib/commonjs/eedl/eedl.js.map +1 -1
- package/lib/commonjs/index.js +290 -48
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/mp-client-sdk.js +17 -10
- package/lib/commonjs/models/mp-client-sdk.js.map +1 -1
- package/lib/commonjs/processors/data-element.processor.js +51 -7
- package/lib/commonjs/processors/data-element.processor.js.map +1 -1
- package/lib/commonjs/processors/visit-id.processor.js +78 -15
- package/lib/commonjs/processors/visit-id.processor.js.map +1 -1
- package/lib/module/common/app-types.js.map +1 -1
- package/lib/module/common/constants.js +11 -2
- package/lib/module/common/constants.js.map +1 -1
- package/lib/module/common/data-store.js +13 -30
- package/lib/module/common/data-store.js.map +1 -1
- package/lib/module/common/deeplink-helper.js +168 -0
- package/lib/module/common/deeplink-helper.js.map +1 -0
- package/lib/module/common/device-info-helper.js +161 -0
- package/lib/module/common/device-info-helper.js.map +1 -0
- package/lib/module/common/event-bus.js +39 -0
- package/lib/module/common/event-bus.js.map +1 -1
- package/lib/module/common/network-service.js +119 -15
- package/lib/module/common/network-service.js.map +1 -1
- package/lib/module/common/reporter.js +29 -10
- package/lib/module/common/reporter.js.map +1 -1
- package/lib/module/common/storage-helper.js +221 -0
- package/lib/module/common/storage-helper.js.map +1 -0
- package/lib/module/common/utils.js +20 -2
- package/lib/module/common/utils.js.map +1 -1
- package/lib/module/eedl/eedl.js +198 -44
- package/lib/module/eedl/eedl.js.map +1 -1
- package/lib/module/index.js +279 -47
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/mp-client-sdk.js +16 -9
- package/lib/module/models/mp-client-sdk.js.map +1 -1
- package/lib/module/processors/data-element.processor.js +51 -7
- package/lib/module/processors/data-element.processor.js.map +1 -1
- package/lib/module/processors/visit-id.processor.js +78 -15
- package/lib/module/processors/visit-id.processor.js.map +1 -1
- package/lib/typescript/{common → src/common}/app-types.d.ts +29 -9
- package/lib/typescript/{common → src/common}/constants.d.ts +0 -1
- package/lib/typescript/{common → src/common}/data-store.d.ts +3 -8
- package/lib/typescript/src/common/deeplink-helper.d.ts +60 -0
- package/lib/typescript/src/common/device-info-helper.d.ts +54 -0
- package/lib/typescript/src/common/event-bus.d.ts +21 -0
- package/lib/typescript/src/common/network-service.d.ts +32 -0
- package/lib/typescript/src/common/storage-helper.d.ts +47 -0
- package/lib/typescript/{common → src/common}/utils.d.ts +7 -0
- package/lib/typescript/{eedl → src/eedl}/eedl.d.ts +43 -1
- package/lib/typescript/{index.d.ts → src/index.d.ts} +39 -5
- package/lib/typescript/{models → src/models}/mp-client-sdk.d.ts +7 -0
- package/lib/typescript/src/processors/visit-id.processor.d.ts +23 -0
- package/package.json +26 -37
- package/src/common/app-types.ts +32 -10
- package/src/common/constants.ts +0 -6
- package/src/common/data-store.ts +8 -30
- package/src/common/deeplink-helper.ts +181 -0
- package/src/common/device-info-helper.ts +190 -0
- package/src/common/event-bus.ts +39 -0
- package/src/common/network-service.ts +154 -21
- package/src/common/reporter.ts +31 -10
- package/src/common/storage-helper.ts +266 -0
- package/src/common/utils.ts +20 -2
- package/src/eedl/eedl.ts +225 -51
- package/src/index.tsx +332 -67
- package/src/models/mp-client-sdk.ts +8 -0
- package/src/processors/data-element.processor.ts +85 -7
- package/src/processors/visit-id.processor.ts +92 -22
- package/lib/commonjs/processors/trans-function.processor.js +0 -73
- package/lib/commonjs/processors/trans-function.processor.js.map +0 -1
- package/lib/module/processors/trans-function.processor.js +0 -66
- package/lib/module/processors/trans-function.processor.js.map +0 -1
- package/lib/typescript/common/event-bus.d.ts +0 -6
- package/lib/typescript/common/network-service.d.ts +0 -8
- package/lib/typescript/processors/trans-function.processor.d.ts +0 -12
- package/lib/typescript/processors/visit-id.processor.d.ts +0 -9
- package/src/processors/trans-function.processor.ts +0 -85
- /package/lib/typescript/{common → src/common}/logger.d.ts +0 -0
- /package/lib/typescript/{common → src/common}/reporter.d.ts +0 -0
- /package/lib/typescript/{models → src/models}/geo-api-response.d.ts +0 -0
- /package/lib/typescript/{processors → src/processors}/data-element.processor.d.ts +0 -0
- /package/lib/typescript/{processors → src/processors}/geo-location.processor.d.ts +0 -0
- /package/lib/typescript/{processors → src/processors}/qc.processor.d.ts +0 -0
- /package/lib/typescript/{processors → src/processors}/tag.processor.d.ts +0 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DeepLinkType = exports.DeepLinkHelper = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _logger = require("./logger");
|
|
9
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
let DeepLinkType = exports.DeepLinkType = /*#__PURE__*/function (DeepLinkType) {
|
|
13
|
+
DeepLinkType["CUSTOM_SCHEME"] = "custom_scheme";
|
|
14
|
+
// myapp://
|
|
15
|
+
DeepLinkType["UNIVERSAL_LINK"] = "universal_link";
|
|
16
|
+
// https:// (iOS Universal Links)
|
|
17
|
+
DeepLinkType["APP_LINK"] = "app_link";
|
|
18
|
+
// https:// (Android App Links)
|
|
19
|
+
DeepLinkType["HTTP_LINK"] = "http_link"; // http://
|
|
20
|
+
return DeepLinkType;
|
|
21
|
+
}({});
|
|
22
|
+
/**
|
|
23
|
+
* Helper class to automatically detect and handle deeplinks
|
|
24
|
+
*
|
|
25
|
+
* Supports multiple link types:
|
|
26
|
+
* 1. Custom URL Schemes: myapp://product/123
|
|
27
|
+
* 2. Universal Links (iOS): https://my-site.com/product/123
|
|
28
|
+
* 3. App Links (Android): https://my-site.com/product/123
|
|
29
|
+
* 4. HTTP Links: http://my-site.com/product/123
|
|
30
|
+
*
|
|
31
|
+
* Common use cases:
|
|
32
|
+
* - Ad clicks (Facebook, Google, TikTok ads with http/https URLs)
|
|
33
|
+
* - Push notification deep links
|
|
34
|
+
* - Email marketing links
|
|
35
|
+
* - SMS campaign links
|
|
36
|
+
* - QR codes
|
|
37
|
+
*/
|
|
38
|
+
class DeepLinkHelper {
|
|
39
|
+
/**
|
|
40
|
+
* Determine the type of deeplink
|
|
41
|
+
* @param url The URL to analyze
|
|
42
|
+
* @returns The type of deeplink
|
|
43
|
+
*/
|
|
44
|
+
static getLinkType(url) {
|
|
45
|
+
try {
|
|
46
|
+
if (url.startsWith('https://')) {
|
|
47
|
+
// Universal Links (iOS) and App Links (Android) both use HTTPS
|
|
48
|
+
return DeepLinkType.UNIVERSAL_LINK;
|
|
49
|
+
} else if (url.startsWith('http://')) {
|
|
50
|
+
return DeepLinkType.HTTP_LINK;
|
|
51
|
+
} else {
|
|
52
|
+
// Custom URL scheme (e.g., myapp://)
|
|
53
|
+
return DeepLinkType.CUSTOM_SCHEME;
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
_logger.Logger.logError('Error determining link type:', error);
|
|
57
|
+
return DeepLinkType.CUSTOM_SCHEME;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Initialize deeplink detection
|
|
63
|
+
* - Checks if app was opened with initial URL (custom scheme, universal link, or HTTP link)
|
|
64
|
+
* - Sets up listener for deeplinks while app is running
|
|
65
|
+
* @param callback Optional callback to be notified when deeplink is detected
|
|
66
|
+
* @returns The initial URL if app was opened with deeplink, null otherwise
|
|
67
|
+
*/
|
|
68
|
+
static async initialize(callback) {
|
|
69
|
+
try {
|
|
70
|
+
// Store callback if provided
|
|
71
|
+
if (callback) {
|
|
72
|
+
this.onDeepLinkCallback = callback;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Check if app was opened with a deeplink
|
|
76
|
+
// This works for:
|
|
77
|
+
// - Custom schemes: myapp://product/123
|
|
78
|
+
// - Universal Links (iOS): https://my-site.com/product/123
|
|
79
|
+
// - App Links (Android): https://my-site.com/product/123
|
|
80
|
+
// - HTTP links: http://my-site.com/product/123
|
|
81
|
+
const initialUrl = await _reactNative.Linking.getInitialURL();
|
|
82
|
+
if (initialUrl) {
|
|
83
|
+
const linkType = this.getLinkType(initialUrl);
|
|
84
|
+
_logger.Logger.logDbg(`App opened with initial ${linkType}:`, initialUrl);
|
|
85
|
+
this.handleDeepLink(initialUrl);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ALWAYS set up listener for deeplinks while app is running
|
|
89
|
+
// This ensures we can detect deeplinks even if app was opened with initial deeplink
|
|
90
|
+
this.setupListener();
|
|
91
|
+
return initialUrl;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
_logger.Logger.logError('Error initializing deeplink detection:', error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Set up listener for deeplinks received while app is running
|
|
100
|
+
* Works for all link types: custom schemes, universal links, app links, HTTP links
|
|
101
|
+
*/
|
|
102
|
+
static setupListener() {
|
|
103
|
+
// Remove existing listener if any
|
|
104
|
+
if (this.listener) {
|
|
105
|
+
this.listener.remove();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Listen for deeplinks while app is running (e.g., user clicks link while app is open)
|
|
109
|
+
this.listener = _reactNative.Linking.addEventListener('url', event => {
|
|
110
|
+
const linkType = this.getLinkType(event.url);
|
|
111
|
+
_logger.Logger.logDbg(`Deeplink received (${linkType}):`, event.url);
|
|
112
|
+
this.handleDeepLink(event.url);
|
|
113
|
+
});
|
|
114
|
+
_logger.Logger.logDbg('Deeplink listener set up (supports custom schemes, universal/app links, HTTP links)');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Handle deeplink URL - notify callback if registered
|
|
119
|
+
* @param url The deeplink URL
|
|
120
|
+
*/
|
|
121
|
+
static handleDeepLink(url) {
|
|
122
|
+
if (this.onDeepLinkCallback) {
|
|
123
|
+
const linkType = this.getLinkType(url);
|
|
124
|
+
this.onDeepLinkCallback(url, linkType);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Remove deeplink listener and clear callback
|
|
130
|
+
*/
|
|
131
|
+
static cleanup() {
|
|
132
|
+
if (this.listener) {
|
|
133
|
+
this.listener.remove();
|
|
134
|
+
this.listener = null;
|
|
135
|
+
}
|
|
136
|
+
this.onDeepLinkCallback = null;
|
|
137
|
+
_logger.Logger.logDbg('Deeplink listener and callback cleared');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Parse UTM parameters and other campaign data from URL
|
|
142
|
+
* @param url The deeplink URL
|
|
143
|
+
* @returns Object containing campaign parameters
|
|
144
|
+
*/
|
|
145
|
+
static parseCampaignParams(url) {
|
|
146
|
+
try {
|
|
147
|
+
const urlObj = new URL(url);
|
|
148
|
+
const params = {};
|
|
149
|
+
|
|
150
|
+
// Common campaign parameters
|
|
151
|
+
const campaignParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_id', 'gclid',
|
|
152
|
+
// Google Click ID
|
|
153
|
+
'fbclid',
|
|
154
|
+
// Facebook Click ID
|
|
155
|
+
'ttclid',
|
|
156
|
+
// TikTok Click ID
|
|
157
|
+
'campaign_id', 'ad_id', 'adset_id', 'creative_id'];
|
|
158
|
+
campaignParams.forEach(param => {
|
|
159
|
+
const value = urlObj.searchParams.get(param);
|
|
160
|
+
if (value) {
|
|
161
|
+
params[param] = value;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return params;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
_logger.Logger.logError('Error parsing campaign params from URL:', error);
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.DeepLinkHelper = DeepLinkHelper;
|
|
172
|
+
_defineProperty(DeepLinkHelper, "listener", null);
|
|
173
|
+
_defineProperty(DeepLinkHelper, "onDeepLinkCallback", null);
|
|
174
|
+
//# sourceMappingURL=deeplink-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_logger","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","DeepLinkType","exports","DeepLinkHelper","getLinkType","url","startsWith","UNIVERSAL_LINK","HTTP_LINK","CUSTOM_SCHEME","error","Logger","logError","initialize","callback","onDeepLinkCallback","initialUrl","Linking","getInitialURL","linkType","logDbg","handleDeepLink","setupListener","listener","remove","addEventListener","event","cleanup","parseCampaignParams","urlObj","URL","params","campaignParams","forEach","param","searchParams","get"],"sources":["deeplink-helper.ts"],"sourcesContent":["import { Linking } from 'react-native';\nimport { Logger } from './logger';\n\nexport enum DeepLinkType {\n CUSTOM_SCHEME = 'custom_scheme', // myapp://\n UNIVERSAL_LINK = 'universal_link', // https:// (iOS Universal Links)\n APP_LINK = 'app_link', // https:// (Android App Links)\n HTTP_LINK = 'http_link', // http://\n}\n\n/**\n * Helper class to automatically detect and handle deeplinks\n *\n * Supports multiple link types:\n * 1. Custom URL Schemes: myapp://product/123\n * 2. Universal Links (iOS): https://my-site.com/product/123\n * 3. App Links (Android): https://my-site.com/product/123\n * 4. HTTP Links: http://my-site.com/product/123\n *\n * Common use cases:\n * - Ad clicks (Facebook, Google, TikTok ads with http/https URLs)\n * - Push notification deep links\n * - Email marketing links\n * - SMS campaign links\n * - QR codes\n */\nexport class DeepLinkHelper {\n private static listener: any = null;\n private static onDeepLinkCallback:\n | ((url: string, linkType: DeepLinkType) => void)\n | null = null;\n\n /**\n * Determine the type of deeplink\n * @param url The URL to analyze\n * @returns The type of deeplink\n */\n static getLinkType(url: string): DeepLinkType {\n try {\n if (url.startsWith('https://')) {\n // Universal Links (iOS) and App Links (Android) both use HTTPS\n return DeepLinkType.UNIVERSAL_LINK;\n } else if (url.startsWith('http://')) {\n return DeepLinkType.HTTP_LINK;\n } else {\n // Custom URL scheme (e.g., myapp://)\n return DeepLinkType.CUSTOM_SCHEME;\n }\n } catch (error) {\n Logger.logError('Error determining link type:', error);\n return DeepLinkType.CUSTOM_SCHEME;\n }\n }\n\n /**\n * Initialize deeplink detection\n * - Checks if app was opened with initial URL (custom scheme, universal link, or HTTP link)\n * - Sets up listener for deeplinks while app is running\n * @param callback Optional callback to be notified when deeplink is detected\n * @returns The initial URL if app was opened with deeplink, null otherwise\n */\n static async initialize(\n callback?: (url: string, linkType: DeepLinkType) => void\n ): Promise<string | null> {\n try {\n // Store callback if provided\n if (callback) {\n this.onDeepLinkCallback = callback;\n }\n\n // Check if app was opened with a deeplink\n // This works for:\n // - Custom schemes: myapp://product/123\n // - Universal Links (iOS): https://my-site.com/product/123\n // - App Links (Android): https://my-site.com/product/123\n // - HTTP links: http://my-site.com/product/123\n const initialUrl = await Linking.getInitialURL();\n\n if (initialUrl) {\n const linkType = this.getLinkType(initialUrl);\n Logger.logDbg(`App opened with initial ${linkType}:`, initialUrl);\n this.handleDeepLink(initialUrl);\n }\n\n // ALWAYS set up listener for deeplinks while app is running\n // This ensures we can detect deeplinks even if app was opened with initial deeplink\n this.setupListener();\n\n return initialUrl;\n } catch (error) {\n Logger.logError('Error initializing deeplink detection:', error);\n return null;\n }\n }\n\n /**\n * Set up listener for deeplinks received while app is running\n * Works for all link types: custom schemes, universal links, app links, HTTP links\n */\n private static setupListener(): void {\n // Remove existing listener if any\n if (this.listener) {\n this.listener.remove();\n }\n\n // Listen for deeplinks while app is running (e.g., user clicks link while app is open)\n this.listener = Linking.addEventListener('url', (event) => {\n const linkType = this.getLinkType(event.url);\n Logger.logDbg(`Deeplink received (${linkType}):`, event.url);\n this.handleDeepLink(event.url);\n });\n\n Logger.logDbg(\n 'Deeplink listener set up (supports custom schemes, universal/app links, HTTP links)'\n );\n }\n\n /**\n * Handle deeplink URL - notify callback if registered\n * @param url The deeplink URL\n */\n private static handleDeepLink(url: string): void {\n if (this.onDeepLinkCallback) {\n const linkType = this.getLinkType(url);\n this.onDeepLinkCallback(url, linkType);\n }\n }\n\n /**\n * Remove deeplink listener and clear callback\n */\n static cleanup(): void {\n if (this.listener) {\n this.listener.remove();\n this.listener = null;\n }\n this.onDeepLinkCallback = null;\n Logger.logDbg('Deeplink listener and callback cleared');\n }\n\n /**\n * Parse UTM parameters and other campaign data from URL\n * @param url The deeplink URL\n * @returns Object containing campaign parameters\n */\n static parseCampaignParams(url: string): Record<string, string> {\n try {\n const urlObj = new URL(url);\n const params: Record<string, string> = {};\n\n // Common campaign parameters\n const campaignParams = [\n 'utm_source',\n 'utm_medium',\n 'utm_campaign',\n 'utm_term',\n 'utm_content',\n 'utm_id',\n 'gclid', // Google Click ID\n 'fbclid', // Facebook Click ID\n 'ttclid', // TikTok Click ID\n 'campaign_id',\n 'ad_id',\n 'adset_id',\n 'creative_id',\n ];\n\n campaignParams.forEach((param) => {\n const value = urlObj.searchParams.get(param);\n if (value) {\n params[param] = value;\n }\n });\n\n return params;\n } catch (error) {\n Logger.logError('Error parsing campaign params from URL:', error);\n return {};\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAAkC,SAAAE,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AAAA,IAEtB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BA,CAACvB,GAAW,EAA0B;IAC9D,IAAI;MACF,MAAMwB,MAAM,GAAG,IAAIC,GAAG,CAACzB,GAAG,CAAC;MAC3B,MAAM0B,MAA8B,GAAG,CAAC,CAAC;;MAEzC;MACA,MAAMC,cAAc,GAAG,CACrB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,UAAU,EACV,aAAa,EACb,QAAQ,EACR,OAAO;MAAE;MACT,QAAQ;MAAE;MACV,QAAQ;MAAE;MACV,aAAa,EACb,OAAO,EACP,UAAU,EACV,aAAa,CACd;MAEDA,cAAc,CAACC,OAAO,CAAEC,KAAK,IAAK;QAChC,MAAM7C,KAAK,GAAGwC,MAAM,CAACM,YAAY,CAACC,GAAG,CAACF,KAAK,CAAC;QAC5C,IAAI7C,KAAK,EAAE;UACT0C,MAAM,CAACG,KAAK,CAAC,GAAG7C,KAAK;QACvB;MACF,CAAC,CAAC;MAEF,OAAO0C,MAAM;IACf,CAAC,CAAC,OAAOrB,KAAK,EAAE;MACdC,cAAM,CAACC,QAAQ,CAAC,yCAAyC,EAAEF,KAAK,CAAC;MACjE,OAAO,CAAC,CAAC;IACX;EACF;AACF;AAACR,OAAA,CAAAC,cAAA,GAAAA,cAAA;AAAArB,eAAA,CA1JYqB,cAAc,cACM,IAAI;AAAArB,eAAA,CADxBqB,cAAc,wBAId,IAAI","ignoreList":[]}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DeviceInfoHelper = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _logger = require("./logger");
|
|
9
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
+
/**
|
|
13
|
+
* Helper class to automatically detect device and app information
|
|
14
|
+
* Supports both Expo and bare React Native:
|
|
15
|
+
* 1. Tries Expo modules first (works in Expo Go)
|
|
16
|
+
* 2. Falls back to react-native-device-info (for bare RN)
|
|
17
|
+
* 3. Returns safe defaults if neither is available
|
|
18
|
+
*/
|
|
19
|
+
class DeviceInfoHelper {
|
|
20
|
+
/**
|
|
21
|
+
* Try to load Expo modules and react-native-device-info
|
|
22
|
+
* This uses dynamic imports to avoid errors when modules aren't available
|
|
23
|
+
*/
|
|
24
|
+
static async initialize() {
|
|
25
|
+
if (this.initialized) return;
|
|
26
|
+
|
|
27
|
+
// Try to load Expo modules first (works in Expo Go)
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
30
|
+
this.expoApplication = require('expo-application');
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
32
|
+
this.expoDevice = require('expo-device');
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
34
|
+
this.expoConstants = require('expo-constants').default;
|
|
35
|
+
_logger.Logger.logDbg('Using Expo modules for device info');
|
|
36
|
+
} catch (error) {
|
|
37
|
+
_logger.Logger.logDbg('Expo modules not available, will try react-native-device-info');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Fall back to react-native-device-info (for bare RN)
|
|
41
|
+
if (!this.expoApplication) {
|
|
42
|
+
try {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
44
|
+
this.deviceInfo = require('react-native-device-info').default;
|
|
45
|
+
_logger.Logger.logDbg('Using react-native-device-info for device info');
|
|
46
|
+
} catch (error) {
|
|
47
|
+
_logger.Logger.logError('Neither Expo modules nor react-native-device-info available:', error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
this.initialized = true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get comprehensive app and device information
|
|
55
|
+
* All methods are async-safe and handle errors gracefully
|
|
56
|
+
*/
|
|
57
|
+
static async getAppInfo() {
|
|
58
|
+
await this.initialize();
|
|
59
|
+
try {
|
|
60
|
+
// Try Expo modules first
|
|
61
|
+
if (this.expoApplication && this.expoDevice) {
|
|
62
|
+
return await this.getAppInfoFromExpo();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Fall back to react-native-device-info
|
|
66
|
+
if (this.deviceInfo) {
|
|
67
|
+
return await this.getAppInfoFromDeviceInfo();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Return safe fallback values
|
|
71
|
+
return this.getSafeDefaults();
|
|
72
|
+
} catch (error) {
|
|
73
|
+
_logger.Logger.logError('Error getting device info:', error);
|
|
74
|
+
return this.getSafeDefaults();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get device info using Expo modules (works in Expo Go)
|
|
80
|
+
*/
|
|
81
|
+
static async getAppInfoFromExpo() {
|
|
82
|
+
var _Platform$Version;
|
|
83
|
+
const version = this.expoApplication.nativeApplicationVersion || 'unknown';
|
|
84
|
+
const buildNumber = this.expoApplication.nativeBuildVersion || 'unknown';
|
|
85
|
+
const packageName = this.expoApplication.applicationId || 'unknown';
|
|
86
|
+
return {
|
|
87
|
+
// App information
|
|
88
|
+
app_version: version,
|
|
89
|
+
build_number: buildNumber,
|
|
90
|
+
package_name: packageName,
|
|
91
|
+
// Device information
|
|
92
|
+
device_model_name: this.expoDevice.modelName || 'unknown',
|
|
93
|
+
device_manufacturer: this.expoDevice.manufacturer || 'unknown',
|
|
94
|
+
device_id: this.expoConstants.sessionId || 'unknown',
|
|
95
|
+
// OS information
|
|
96
|
+
os_name: _reactNative.Platform.OS,
|
|
97
|
+
os_version: this.expoDevice.osVersion || ((_Platform$Version = _reactNative.Platform.Version) === null || _Platform$Version === void 0 ? void 0 : _Platform$Version.toString()) || 'unknown',
|
|
98
|
+
// Additional useful info
|
|
99
|
+
// DeviceType enum: UNKNOWN=0, PHONE=1, TABLET=2, DESKTOP=3, TV=4
|
|
100
|
+
is_tablet: this.expoDevice.deviceType === 2,
|
|
101
|
+
// DeviceType.TABLET = 2
|
|
102
|
+
is_emulator: !this.expoDevice.isDevice
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get device info using react-native-device-info (for bare RN)
|
|
108
|
+
*/
|
|
109
|
+
static async getAppInfoFromDeviceInfo() {
|
|
110
|
+
const [version, buildNumber, uniqueId, bundleId] = await Promise.all([this.deviceInfo.getVersion(), this.deviceInfo.getBuildNumber(), this.deviceInfo.getUniqueId(), this.deviceInfo.getBundleId()]);
|
|
111
|
+
return {
|
|
112
|
+
// App information
|
|
113
|
+
app_version: version,
|
|
114
|
+
build_number: buildNumber,
|
|
115
|
+
package_name: bundleId,
|
|
116
|
+
// Device information
|
|
117
|
+
device_model_name: this.deviceInfo.getModel(),
|
|
118
|
+
device_manufacturer: this.deviceInfo.getManufacturerSync(),
|
|
119
|
+
device_id: uniqueId,
|
|
120
|
+
// OS information
|
|
121
|
+
os_name: _reactNative.Platform.OS,
|
|
122
|
+
os_version: this.deviceInfo.getSystemVersion(),
|
|
123
|
+
// Additional useful info
|
|
124
|
+
is_tablet: this.deviceInfo.isTablet(),
|
|
125
|
+
is_emulator: await this.deviceInfo.isEmulator()
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Safe default values when no device info library is available
|
|
131
|
+
*/
|
|
132
|
+
static getSafeDefaults() {
|
|
133
|
+
var _Platform$Version2;
|
|
134
|
+
return {
|
|
135
|
+
app_version: 'unknown',
|
|
136
|
+
build_number: 'unknown',
|
|
137
|
+
package_name: 'unknown',
|
|
138
|
+
device_model_name: 'unknown',
|
|
139
|
+
device_manufacturer: 'unknown',
|
|
140
|
+
device_id: 'unknown',
|
|
141
|
+
os_name: _reactNative.Platform.OS,
|
|
142
|
+
os_version: ((_Platform$Version2 = _reactNative.Platform.Version) === null || _Platform$Version2 === void 0 ? void 0 : _Platform$Version2.toString()) || 'unknown',
|
|
143
|
+
is_tablet: false,
|
|
144
|
+
is_emulator: false
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get app version in format: "1.0.0 (123)"
|
|
150
|
+
* Combines version and build number for better tracking
|
|
151
|
+
*/
|
|
152
|
+
static async getFormattedAppVersion() {
|
|
153
|
+
try {
|
|
154
|
+
const info = await this.getAppInfo();
|
|
155
|
+
return `${info.app_version} (${info.build_number})`;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
_logger.Logger.logError('Error getting formatted app version:', error);
|
|
158
|
+
return 'unknown';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.DeviceInfoHelper = DeviceInfoHelper;
|
|
163
|
+
_defineProperty(DeviceInfoHelper, "expoApplication", null);
|
|
164
|
+
_defineProperty(DeviceInfoHelper, "expoDevice", null);
|
|
165
|
+
_defineProperty(DeviceInfoHelper, "expoConstants", null);
|
|
166
|
+
_defineProperty(DeviceInfoHelper, "deviceInfo", null);
|
|
167
|
+
_defineProperty(DeviceInfoHelper, "initialized", false);
|
|
168
|
+
//# sourceMappingURL=device-info-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_logger","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","DeviceInfoHelper","initialize","initialized","expoApplication","expoDevice","expoConstants","default","Logger","logDbg","error","deviceInfo","logError","getAppInfo","getAppInfoFromExpo","getAppInfoFromDeviceInfo","getSafeDefaults","_Platform$Version","version","nativeApplicationVersion","buildNumber","nativeBuildVersion","packageName","applicationId","app_version","build_number","package_name","device_model_name","modelName","device_manufacturer","manufacturer","device_id","sessionId","os_name","Platform","OS","os_version","osVersion","Version","toString","is_tablet","deviceType","is_emulator","isDevice","uniqueId","bundleId","Promise","all","getVersion","getBuildNumber","getUniqueId","getBundleId","getModel","getManufacturerSync","getSystemVersion","isTablet","isEmulator","_Platform$Version2","getFormattedAppVersion","info","exports"],"sources":["device-info-helper.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { Logger } from './logger';\n\ninterface DeviceAppInfo {\n app_version: string;\n build_number: string;\n package_name: string;\n device_model_name: string;\n device_manufacturer: string;\n device_id: string;\n os_name: string;\n os_version: string;\n is_tablet: boolean;\n is_emulator: boolean;\n}\n\n/**\n * Helper class to automatically detect device and app information\n * Supports both Expo and bare React Native:\n * 1. Tries Expo modules first (works in Expo Go)\n * 2. Falls back to react-native-device-info (for bare RN)\n * 3. Returns safe defaults if neither is available\n */\nexport class DeviceInfoHelper {\n private static expoApplication: any = null;\n private static expoDevice: any = null;\n private static expoConstants: any = null;\n private static deviceInfo: any = null;\n private static initialized = false;\n\n /**\n * Try to load Expo modules and react-native-device-info\n * This uses dynamic imports to avoid errors when modules aren't available\n */\n private static async initialize(): Promise<void> {\n if (this.initialized) return;\n\n // Try to load Expo modules first (works in Expo Go)\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n this.expoApplication = require('expo-application');\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n this.expoDevice = require('expo-device');\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n this.expoConstants = require('expo-constants').default;\n Logger.logDbg('Using Expo modules for device info');\n } catch (error) {\n Logger.logDbg(\n 'Expo modules not available, will try react-native-device-info'\n );\n }\n\n // Fall back to react-native-device-info (for bare RN)\n if (!this.expoApplication) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n this.deviceInfo = require('react-native-device-info').default;\n Logger.logDbg('Using react-native-device-info for device info');\n } catch (error) {\n Logger.logError(\n 'Neither Expo modules nor react-native-device-info available:',\n error\n );\n }\n }\n\n this.initialized = true;\n }\n\n /**\n * Get comprehensive app and device information\n * All methods are async-safe and handle errors gracefully\n */\n static async getAppInfo(): Promise<DeviceAppInfo> {\n await this.initialize();\n\n try {\n // Try Expo modules first\n if (this.expoApplication && this.expoDevice) {\n return await this.getAppInfoFromExpo();\n }\n\n // Fall back to react-native-device-info\n if (this.deviceInfo) {\n return await this.getAppInfoFromDeviceInfo();\n }\n\n // Return safe fallback values\n return this.getSafeDefaults();\n } catch (error) {\n Logger.logError('Error getting device info:', error);\n return this.getSafeDefaults();\n }\n }\n\n /**\n * Get device info using Expo modules (works in Expo Go)\n */\n private static async getAppInfoFromExpo(): Promise<DeviceAppInfo> {\n const version = this.expoApplication.nativeApplicationVersion || 'unknown';\n const buildNumber = this.expoApplication.nativeBuildVersion || 'unknown';\n const packageName = this.expoApplication.applicationId || 'unknown';\n\n return {\n // App information\n app_version: version,\n build_number: buildNumber,\n package_name: packageName,\n\n // Device information\n device_model_name: this.expoDevice.modelName || 'unknown',\n device_manufacturer: this.expoDevice.manufacturer || 'unknown',\n device_id: this.expoConstants.sessionId || 'unknown',\n\n // OS information\n os_name: Platform.OS,\n os_version:\n this.expoDevice.osVersion || Platform.Version?.toString() || 'unknown',\n\n // Additional useful info\n // DeviceType enum: UNKNOWN=0, PHONE=1, TABLET=2, DESKTOP=3, TV=4\n is_tablet: this.expoDevice.deviceType === 2, // DeviceType.TABLET = 2\n is_emulator: !this.expoDevice.isDevice,\n };\n }\n\n /**\n * Get device info using react-native-device-info (for bare RN)\n */\n private static async getAppInfoFromDeviceInfo(): Promise<DeviceAppInfo> {\n const [version, buildNumber, uniqueId, bundleId] = await Promise.all([\n this.deviceInfo.getVersion(),\n this.deviceInfo.getBuildNumber(),\n this.deviceInfo.getUniqueId(),\n this.deviceInfo.getBundleId(),\n ]);\n\n return {\n // App information\n app_version: version,\n build_number: buildNumber,\n package_name: bundleId,\n\n // Device information\n device_model_name: this.deviceInfo.getModel(),\n device_manufacturer: this.deviceInfo.getManufacturerSync(),\n device_id: uniqueId,\n\n // OS information\n os_name: Platform.OS,\n os_version: this.deviceInfo.getSystemVersion(),\n\n // Additional useful info\n is_tablet: this.deviceInfo.isTablet(),\n is_emulator: await this.deviceInfo.isEmulator(),\n };\n }\n\n /**\n * Safe default values when no device info library is available\n */\n private static getSafeDefaults(): DeviceAppInfo {\n return {\n app_version: 'unknown',\n build_number: 'unknown',\n package_name: 'unknown',\n device_model_name: 'unknown',\n device_manufacturer: 'unknown',\n device_id: 'unknown',\n os_name: Platform.OS,\n os_version: Platform.Version?.toString() || 'unknown',\n is_tablet: false,\n is_emulator: false,\n };\n }\n\n /**\n * Get app version in format: \"1.0.0 (123)\"\n * Combines version and build number for better tracking\n */\n static async getFormattedAppVersion(): Promise<string> {\n try {\n const info = await this.getAppInfo();\n return `${info.app_version} (${info.build_number})`;\n } catch (error) {\n Logger.logError('Error getting formatted app version:', error);\n return 'unknown';\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAAkC,SAAAE,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,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AAiB,EAAE,SAAS;MAC5BE,mBAAmB,EAAE,SAAS;MAC9BE,SAAS,EAAE,SAAS;MACpBE,OAAO,EAAEC,qBAAQ,CAACC,EAAE;MACpBC,UAAU,EAAE,EAAAqB,kBAAA,GAAAvB,qBAAQ,CAACI,OAAO,cAAAmB,kBAAA,uBAAhBA,kBAAA,CAAkBlB,QAAQ,CAAC,CAAC,KAAI,SAAS;MACrDC,SAAS,EAAE,KAAK;MAChBE,WAAW,EAAE;IACf,CAAC;EACH;;EAEA;AACF;AACA;AACA;EACE,aAAagB,sBAAsBA,CAAA,EAAoB;IACrD,IAAI;MACF,MAAMC,IAAI,GAAG,MAAM,IAAI,CAAC9C,UAAU,CAAC,CAAC;MACpC,OAAO,GAAG8C,IAAI,CAACnC,WAAW,KAAKmC,IAAI,CAAClC,YAAY,GAAG;IACrD,CAAC,CAAC,OAAOf,KAAK,EAAE;MACdF,cAAM,CAACI,QAAQ,CAAC,sCAAsC,EAAEF,KAAK,CAAC;MAC9D,OAAO,SAAS;IAClB;EACF;AACF;AAACkD,OAAA,CAAA3D,gBAAA,GAAAA,gBAAA;AAAAnB,eAAA,CAtKYmB,gBAAgB,qBACW,IAAI;AAAAnB,eAAA,CAD/BmB,gBAAgB,gBAEM,IAAI;AAAAnB,eAAA,CAF1BmB,gBAAgB,mBAGS,IAAI;AAAAnB,eAAA,CAH7BmB,gBAAgB,gBAIM,IAAI;AAAAnB,eAAA,CAJ1BmB,gBAAgB,iBAKE,KAAK","ignoreList":[]}
|
|
@@ -17,6 +17,45 @@ class EventBus {
|
|
|
17
17
|
this.eventRegister.get(eventName).push(callback);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Remove a specific callback for an event
|
|
23
|
+
* @param eventName Event name to remove callback from
|
|
24
|
+
* @param callback The callback function to remove
|
|
25
|
+
*/
|
|
26
|
+
static off(eventName, callback) {
|
|
27
|
+
if (this.eventRegister.has(eventName)) {
|
|
28
|
+
const callbacks = this.eventRegister.get(eventName);
|
|
29
|
+
const index = callbacks.indexOf(callback);
|
|
30
|
+
if (index > -1) {
|
|
31
|
+
callbacks.splice(index, 1);
|
|
32
|
+
_logger.Logger.logDbg(`Removed listener for event: ${eventName}`);
|
|
33
|
+
}
|
|
34
|
+
// Clean up empty arrays
|
|
35
|
+
if (callbacks.length === 0) {
|
|
36
|
+
this.eventRegister.delete(eventName);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Remove all callbacks for a specific event
|
|
43
|
+
* @param eventName Event name to clear all listeners for
|
|
44
|
+
*/
|
|
45
|
+
static clearEvent(eventName) {
|
|
46
|
+
if (this.eventRegister.has(eventName)) {
|
|
47
|
+
this.eventRegister.delete(eventName);
|
|
48
|
+
_logger.Logger.logDbg(`Cleared all listeners for event: ${eventName}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remove all event listeners (used during SDK shutdown)
|
|
54
|
+
*/
|
|
55
|
+
static clearAll() {
|
|
56
|
+
this.eventRegister.clear();
|
|
57
|
+
_logger.Logger.logDbg('Cleared all event listeners');
|
|
58
|
+
}
|
|
20
59
|
static triggerEvent(eventName, payload) {
|
|
21
60
|
if (this.eventRegister.has(eventName)) {
|
|
22
61
|
for (const cb of this.eventRegister.get(eventName)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_logger","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","EventBus","on","eventName","callback","Logger","logDbg","eventRegister","has","set","get","push","
|
|
1
|
+
{"version":3,"names":["_logger","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","EventBus","on","eventName","callback","Logger","logDbg","eventRegister","has","set","get","push","off","callbacks","index","indexOf","splice","length","delete","clearEvent","clearAll","clear","triggerEvent","payload","cb","err","logError","exports","Map"],"sources":["event-bus.ts"],"sourcesContent":["import type { EventBusCallback } from './app-types';\nimport { Logger } from './logger';\n\nexport class EventBus {\n private static eventRegister: Map<string, Array<EventBusCallback>> = new Map<\n string,\n Array<EventBusCallback>\n >();\n\n static on(eventName: string, callback: EventBusCallback): void {\n Logger.logDbg(`Registering Listener for event: ${eventName}`);\n if (!this.eventRegister.has(eventName)) {\n this.eventRegister.set(eventName, [callback]);\n } else {\n this.eventRegister.get(eventName).push(callback);\n }\n }\n\n /**\n * Remove a specific callback for an event\n * @param eventName Event name to remove callback from\n * @param callback The callback function to remove\n */\n static off(eventName: string, callback: EventBusCallback): void {\n if (this.eventRegister.has(eventName)) {\n const callbacks = this.eventRegister.get(eventName);\n const index = callbacks.indexOf(callback);\n if (index > -1) {\n callbacks.splice(index, 1);\n Logger.logDbg(`Removed listener for event: ${eventName}`);\n }\n // Clean up empty arrays\n if (callbacks.length === 0) {\n this.eventRegister.delete(eventName);\n }\n }\n }\n\n /**\n * Remove all callbacks for a specific event\n * @param eventName Event name to clear all listeners for\n */\n static clearEvent(eventName: string): void {\n if (this.eventRegister.has(eventName)) {\n this.eventRegister.delete(eventName);\n Logger.logDbg(`Cleared all listeners for event: ${eventName}`);\n }\n }\n\n /**\n * Remove all event listeners (used during SDK shutdown)\n */\n static clearAll(): void {\n this.eventRegister.clear();\n Logger.logDbg('Cleared all event listeners');\n }\n\n static triggerEvent(eventName: string, payload: any): void {\n if (this.eventRegister.has(eventName)) {\n for (const cb of this.eventRegister.get(eventName)) {\n try {\n Logger.logDbg(\n `Sending event ${eventName} to all listeners. Count = ${\n this.eventRegister.get(eventName).length\n }`\n );\n cb(eventName, payload);\n } catch (err) {\n Logger.logError('Unable to process callback for event: ' + eventName);\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAAkC,SAAA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EoB,OAAO,CAAC;QACxB,CAAC,CAAC,OAAOE,GAAG,EAAE;UACZpB,cAAM,CAACqB,QAAQ,CAAC,wCAAwC,GAAGvB,SAAS,CAAC;QACvE;MACF;IACF;EACF;AACF;AAACwB,OAAA,CAAA1B,QAAA,GAAAA,QAAA;AAAAnB,eAAA,CAtEYmB,QAAQ,mBACkD,IAAI2B,GAAG,CAG1E,CAAC","ignoreList":[]}
|
|
@@ -6,29 +6,133 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.NetworkService = void 0;
|
|
7
7
|
var _logger = require("./logger");
|
|
8
8
|
var _dataStore = require("./data-store");
|
|
9
|
-
|
|
9
|
+
const DEFAULT_RETRY_COUNT = 3;
|
|
10
|
+
const DEFAULT_RETRY_DELAY_MS = 1000;
|
|
11
|
+
const DEFAULT_TIMEOUT_MS = 10000;
|
|
10
12
|
class NetworkService {
|
|
13
|
+
/**
|
|
14
|
+
* Sleep for a specified duration
|
|
15
|
+
*/
|
|
16
|
+
static sleep(ms) {
|
|
17
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Fetch with timeout wrapper
|
|
22
|
+
*/
|
|
23
|
+
static async fetchWithTimeout(url, options, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
...options,
|
|
29
|
+
signal: controller.signal
|
|
30
|
+
});
|
|
31
|
+
return response;
|
|
32
|
+
} finally {
|
|
33
|
+
clearTimeout(timeoutId);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Fetch visitor/identity info from server
|
|
38
|
+
* Returns null if fetch fails (caller should handle retry logic)
|
|
39
|
+
*/
|
|
11
40
|
static async fetchIdlInfo(url) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
41
|
+
try {
|
|
42
|
+
const response = await this.fetchWithTimeout(url, {
|
|
43
|
+
method: 'GET',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'text/plain',
|
|
46
|
+
'cache-control': 'no-store',
|
|
47
|
+
..._dataStore.DataStore.getCommonCookies()
|
|
48
|
+
}
|
|
49
|
+
}, DEFAULT_TIMEOUT_MS);
|
|
50
|
+
if (response && response.ok) {
|
|
51
|
+
return response.json();
|
|
52
|
+
} else {
|
|
53
|
+
_logger.Logger.logError(`Failed to fetch IDL info: ${response === null || response === void 0 ? void 0 : response.status} ${response === null || response === void 0 ? void 0 : response.statusText}`);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
_logger.Logger.logError('Error fetching IDL info:', err);
|
|
16
58
|
return null;
|
|
17
59
|
}
|
|
18
60
|
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Fetch visitor/identity info with retry logic
|
|
64
|
+
* @param url The IDL URL
|
|
65
|
+
* @param retries Number of retries (default: 3)
|
|
66
|
+
* @returns VisitorInfo or null if all retries fail
|
|
67
|
+
*/
|
|
68
|
+
static async fetchIdlInfoWithRetry(url, retries = DEFAULT_RETRY_COUNT) {
|
|
69
|
+
let lastError = null;
|
|
70
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
71
|
+
try {
|
|
72
|
+
_logger.Logger.logDbg(`Fetching IDL info (attempt ${attempt}/${retries})`);
|
|
73
|
+
const result = await this.fetchIdlInfo(url);
|
|
74
|
+
if (result) {
|
|
75
|
+
_logger.Logger.logDbg('IDL info fetched successfully');
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
80
|
+
_logger.Logger.logError(`IDL fetch attempt ${attempt} failed:`, err);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Wait before retry (exponential backoff)
|
|
84
|
+
if (attempt < retries) {
|
|
85
|
+
const delay = DEFAULT_RETRY_DELAY_MS * Math.pow(2, attempt - 1);
|
|
86
|
+
_logger.Logger.logDbg(`Retrying IDL fetch in ${delay}ms...`);
|
|
87
|
+
await this.sleep(delay);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
_logger.Logger.logError(`All ${retries} IDL fetch attempts failed`, lastError);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Refresh client SDK JSON configuration with retry logic
|
|
96
|
+
* @param sdkInitOptions SDK initialization options
|
|
97
|
+
* @returns true if successful, throws Error if all retries fail
|
|
98
|
+
*/
|
|
19
99
|
static async refreshClientSdkJson(sdkInitOptions) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await
|
|
100
|
+
var _lastError;
|
|
101
|
+
const url = `${sdkInitOptions.baseUrl}/${sdkInitOptions.projectId}${sdkInitOptions.env === 'staging' ? '-staging' : ''}.json`;
|
|
102
|
+
let lastError = null;
|
|
103
|
+
for (let attempt = 1; attempt <= DEFAULT_RETRY_COUNT; attempt++) {
|
|
104
|
+
try {
|
|
105
|
+
_logger.Logger.logDbg(`Fetching SDK config (attempt ${attempt}/${DEFAULT_RETRY_COUNT}): ${url}`);
|
|
106
|
+
const response = await this.fetchWithTimeout(url, {
|
|
107
|
+
method: 'GET',
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'text/plain',
|
|
110
|
+
'cache-control': 'no-store'
|
|
111
|
+
}
|
|
112
|
+
}, DEFAULT_TIMEOUT_MS);
|
|
113
|
+
if (response && response.ok) {
|
|
114
|
+
const sdkJson = await response.json();
|
|
115
|
+
_logger.Logger.logDbg('Client SDK config fetched successfully');
|
|
116
|
+
await _dataStore.DataStore.init(sdkJson);
|
|
117
|
+
return; // Success - exit the retry loop
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error(`HTTP ${response === null || response === void 0 ? void 0 : response.status}: ${(response === null || response === void 0 ? void 0 : response.statusText) || 'Unknown error'}`);
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
123
|
+
_logger.Logger.logError(`SDK config fetch attempt ${attempt} failed:`, err);
|
|
124
|
+
|
|
125
|
+
// Wait before retry (exponential backoff)
|
|
126
|
+
if (attempt < DEFAULT_RETRY_COUNT) {
|
|
127
|
+
const delay = DEFAULT_RETRY_DELAY_MS * Math.pow(2, attempt - 1);
|
|
128
|
+
_logger.Logger.logDbg(`Retrying SDK config fetch in ${delay}ms...`);
|
|
129
|
+
await this.sleep(delay);
|
|
130
|
+
}
|
|
27
131
|
}
|
|
28
|
-
} catch (err) {
|
|
29
|
-
_reporter.Reporter.reportError('refreshClientSdk', err);
|
|
30
|
-
// throw new Error('Unable to fetch MagicPixel SDK at this time.');
|
|
31
132
|
}
|
|
133
|
+
|
|
134
|
+
// All retries failed - throw error so caller can handle it
|
|
135
|
+
throw new Error(`Failed to fetch SDK configuration after ${DEFAULT_RETRY_COUNT} attempts: ${(_lastError = lastError) === null || _lastError === void 0 ? void 0 : _lastError.message}`);
|
|
32
136
|
}
|
|
33
137
|
static sendPostRequest(url, body) {
|
|
34
138
|
this.sendNetworkRequest('post', url, body).catch(err => {
|