insert-affiliate-react-native-sdk 1.13.0 → 1.15.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/dist/DeepLinkIapProvider.d.ts +7 -0
- package/dist/DeepLinkIapProvider.js +109 -93
- package/dist/index.d.ts +1 -1
- package/dist/useDeepLinkIapProvider.d.ts +1 -0
- package/dist/useDeepLinkIapProvider.js +2 -1
- package/package.json +1 -1
- package/readme.md +39 -0
- package/src/DeepLinkIapProvider.tsx +120 -109
- package/src/index.ts +1 -1
- package/src/useDeepLinkIapProvider.tsx +2 -0
|
@@ -56,6 +56,13 @@ const ASYNC_KEYS = {
|
|
|
56
56
|
AFFILIATE_STORED_DATE: '@app_affiliate_stored_date',
|
|
57
57
|
SDK_INIT_REPORTED: '@app_sdk_init_reported',
|
|
58
58
|
REPORTED_AFFILIATE_ASSOCIATIONS: '@app_reported_affiliate_associations',
|
|
59
|
+
SYSTEM_INFO_SENT: '@app_system_info_sent',
|
|
60
|
+
};
|
|
61
|
+
const DEFAULT_LOGGER = {
|
|
62
|
+
debug: (message, ...args) => console.debug(`[Insert Affiliate] ${message}`, ...args),
|
|
63
|
+
info: (message, ...args) => console.log(`[Insert Affiliate] ${message}`, ...args),
|
|
64
|
+
warn: (message, ...args) => console.warn(`[Insert Affiliate] ${message}`, ...args),
|
|
65
|
+
error: (message, ...args) => console.error(`[Insert Affiliate] ${message}`, ...args),
|
|
59
66
|
};
|
|
60
67
|
// STARTING CONTEXT IMPLEMENTATION
|
|
61
68
|
exports.DeepLinkIapContext = (0, react_1.createContext)({
|
|
@@ -76,6 +83,7 @@ exports.DeepLinkIapContext = (0, react_1.createContext)({
|
|
|
76
83
|
setInsertAffiliateIdentifierChangeCallback: (callback) => { },
|
|
77
84
|
handleInsertLinks: (url) => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
78
85
|
initialize: (code, verboseLogging, insertLinksEnabled, insertLinksClipboardEnabled, affiliateAttributionActiveTime, preventAffiliateTransfer) => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
86
|
+
setLogger: (logger) => { },
|
|
79
87
|
isInitialized: false,
|
|
80
88
|
});
|
|
81
89
|
const DeepLinkIapProvider = ({ children, }) => {
|
|
@@ -91,6 +99,8 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
91
99
|
const [preventAffiliateTransfer, setPreventAffiliateTransfer] = (0, react_1.useState)(false);
|
|
92
100
|
const insertAffiliateIdentifierChangeCallbackRef = (0, react_1.useRef)(null);
|
|
93
101
|
const isInitializingRef = (0, react_1.useRef)(false);
|
|
102
|
+
// Logger ref - defaults to console-based logging, can be swapped via setLogger()
|
|
103
|
+
const loggerRef = (0, react_1.useRef)(DEFAULT_LOGGER);
|
|
94
104
|
// Refs for values that need to be current inside callbacks (to avoid stale closures)
|
|
95
105
|
const companyCodeRef = (0, react_1.useRef)(null);
|
|
96
106
|
const verboseLoggingRef = (0, react_1.useRef)(false);
|
|
@@ -126,37 +136,45 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
126
136
|
setPreventAffiliateTransfer(preventAffiliateTransferParam);
|
|
127
137
|
preventAffiliateTransferRef.current = preventAffiliateTransferParam;
|
|
128
138
|
if (verboseLoggingParam) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
loggerRef.current.debug('[VERBOSE] Starting SDK initialization...');
|
|
140
|
+
loggerRef.current.debug('[VERBOSE] Company code provided:', companyCodeParam ? 'Yes' : 'No');
|
|
141
|
+
loggerRef.current.debug('[VERBOSE] Verbose logging enabled');
|
|
132
142
|
}
|
|
133
143
|
if (companyCodeParam && companyCodeParam.trim() !== '') {
|
|
134
144
|
setCompanyCode(companyCodeParam);
|
|
135
145
|
companyCodeRef.current = companyCodeParam;
|
|
136
146
|
yield saveValueInAsync(ASYNC_KEYS.COMPANY_CODE, companyCodeParam);
|
|
137
147
|
setIsInitialized(true);
|
|
138
|
-
|
|
148
|
+
loggerRef.current.info(`SDK initialized with company code: ${companyCodeParam}`);
|
|
139
149
|
if (verboseLoggingParam) {
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
loggerRef.current.debug('[VERBOSE] Company code saved to AsyncStorage');
|
|
151
|
+
loggerRef.current.debug('[VERBOSE] SDK marked as initialized');
|
|
142
152
|
}
|
|
143
153
|
// Report SDK initialization for onboarding verification (fire and forget)
|
|
144
154
|
reportSdkInitIfNeeded(companyCodeParam, verboseLoggingParam);
|
|
145
155
|
}
|
|
146
156
|
else {
|
|
147
|
-
|
|
157
|
+
loggerRef.current.warn('SDK initialized without a company code.');
|
|
148
158
|
setIsInitialized(true);
|
|
149
159
|
if (verboseLoggingParam) {
|
|
150
|
-
|
|
160
|
+
loggerRef.current.debug('[VERBOSE] No company code provided, SDK initialized in limited mode');
|
|
151
161
|
}
|
|
152
162
|
}
|
|
153
163
|
if (insertLinksEnabledParam && react_native_1.Platform.OS === 'ios') {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
164
|
+
const systemInfoSent = yield getValueFromAsync(ASYNC_KEYS.SYSTEM_INFO_SENT);
|
|
165
|
+
verboseLog(`System info sent flag: ${systemInfoSent ? 'true (skipping)' : 'false (will send)'}`);
|
|
166
|
+
if (!systemInfoSent) {
|
|
167
|
+
// Set flag immediately to prevent concurrent init calls from sending twice
|
|
168
|
+
yield saveValueInAsync(ASYNC_KEYS.SYSTEM_INFO_SENT, 'pending');
|
|
169
|
+
try {
|
|
170
|
+
const enhancedSystemInfo = yield getEnhancedSystemInfo();
|
|
171
|
+
yield sendSystemInfoToBackend(enhancedSystemInfo);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
// Remove flag on failure so it retries next launch
|
|
175
|
+
yield async_storage_1.default.removeItem(ASYNC_KEYS.SYSTEM_INFO_SENT);
|
|
176
|
+
verboseLog(`Error sending system info for clipboard check: ${error}`);
|
|
177
|
+
}
|
|
160
178
|
}
|
|
161
179
|
}
|
|
162
180
|
});
|
|
@@ -232,7 +250,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
232
250
|
}
|
|
233
251
|
}
|
|
234
252
|
catch (error) {
|
|
235
|
-
|
|
253
|
+
loggerRef.current.error('Error getting initial URL:', error);
|
|
236
254
|
}
|
|
237
255
|
});
|
|
238
256
|
// Handle URL opening while app is running (equivalent to open url)
|
|
@@ -248,7 +266,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
248
266
|
}
|
|
249
267
|
}
|
|
250
268
|
catch (error) {
|
|
251
|
-
|
|
269
|
+
loggerRef.current.error('Error handling URL change:', error);
|
|
252
270
|
}
|
|
253
271
|
});
|
|
254
272
|
// Platform-specific deep link handler
|
|
@@ -323,7 +341,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
323
341
|
const reset = () => {
|
|
324
342
|
setCompanyCode(null);
|
|
325
343
|
setIsInitialized(false);
|
|
326
|
-
|
|
344
|
+
loggerRef.current.info('SDK has been reset.');
|
|
327
345
|
};
|
|
328
346
|
// MARK: Deep Link Handling
|
|
329
347
|
// Helper function to parse URLs in React Native compatible way
|
|
@@ -512,14 +530,14 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
512
530
|
// Handles Insert Links deep linking - equivalent to iOS handleInsertLinks
|
|
513
531
|
const handleInsertLinksImpl = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
514
532
|
try {
|
|
515
|
-
|
|
533
|
+
loggerRef.current.info(`Attempting to handle URL: ${url}`);
|
|
516
534
|
if (!url || typeof url !== 'string') {
|
|
517
|
-
|
|
535
|
+
loggerRef.current.info('Invalid URL provided to handleInsertLinks');
|
|
518
536
|
return false;
|
|
519
537
|
}
|
|
520
538
|
// Check if deep links are enabled synchronously
|
|
521
539
|
if (!insertLinksEnabled) {
|
|
522
|
-
|
|
540
|
+
loggerRef.current.info('Deep links are disabled, not handling URL');
|
|
523
541
|
return false;
|
|
524
542
|
}
|
|
525
543
|
const urlObj = parseURL(url);
|
|
@@ -534,7 +552,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
534
552
|
return false;
|
|
535
553
|
}
|
|
536
554
|
catch (error) {
|
|
537
|
-
|
|
555
|
+
loggerRef.current.error('Error handling Insert Link:', error);
|
|
538
556
|
verboseLog(`Error in handleInsertLinks: ${error}`);
|
|
539
557
|
return false;
|
|
540
558
|
}
|
|
@@ -550,29 +568,22 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
550
568
|
const companyCode = scheme.substring(3);
|
|
551
569
|
const shortCode = parseShortCodeFromURLString(url);
|
|
552
570
|
if (!shortCode) {
|
|
553
|
-
|
|
571
|
+
loggerRef.current.info(`Failed to parse short code from deep link: ${url}`);
|
|
554
572
|
return false;
|
|
555
573
|
}
|
|
556
|
-
|
|
574
|
+
loggerRef.current.info(`Custom URL scheme detected - Company: ${companyCode}, Short code: ${shortCode}`);
|
|
557
575
|
// Validate company code matches initialized one
|
|
558
576
|
const activeCompanyCode = yield getActiveCompanyCode();
|
|
559
577
|
if (activeCompanyCode && companyCode.toLowerCase() !== activeCompanyCode.toLowerCase()) {
|
|
560
|
-
|
|
578
|
+
loggerRef.current.info(`Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
|
|
561
579
|
}
|
|
562
580
|
// If URL scheme is used, we can straight away store the short code as the referring link
|
|
563
581
|
yield storeInsertAffiliateIdentifier({ link: shortCode, source: 'deep_link_ios' });
|
|
564
|
-
//
|
|
565
|
-
try {
|
|
566
|
-
const enhancedSystemInfo = yield getEnhancedSystemInfo();
|
|
567
|
-
yield sendSystemInfoToBackend(enhancedSystemInfo);
|
|
568
|
-
}
|
|
569
|
-
catch (error) {
|
|
570
|
-
verboseLog(`Error sending system info for deep link: ${error}`);
|
|
571
|
-
}
|
|
582
|
+
// System info not needed here - affiliate code already received via URL scheme
|
|
572
583
|
return true;
|
|
573
584
|
}
|
|
574
585
|
catch (error) {
|
|
575
|
-
|
|
586
|
+
loggerRef.current.error('Error handling custom URL scheme:', error);
|
|
576
587
|
return false;
|
|
577
588
|
}
|
|
578
589
|
});
|
|
@@ -582,22 +593,22 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
582
593
|
// const pathComponents = url.pathname.split('/').filter(segment => segment.length > 0);
|
|
583
594
|
// // Expected format: /V1/companycode/shortcode
|
|
584
595
|
// if (pathComponents.length < 3 || pathComponents[0] !== 'V1') {
|
|
585
|
-
//
|
|
596
|
+
// loggerRef.current.info(`Invalid universal link format: ${url.href}`);
|
|
586
597
|
// return false;
|
|
587
598
|
// }
|
|
588
599
|
// const companyCode = pathComponents[1];
|
|
589
600
|
// const shortCode = pathComponents[2];
|
|
590
|
-
//
|
|
601
|
+
// loggerRef.current.info(`Universal link detected - Company: ${companyCode}, Short code: ${shortCode}`);
|
|
591
602
|
// // Validate company code matches initialized one
|
|
592
603
|
// const activeCompanyCode = await getActiveCompanyCode();
|
|
593
604
|
// if (activeCompanyCode && companyCode.toLowerCase() !== activeCompanyCode.toLowerCase()) {
|
|
594
|
-
//
|
|
605
|
+
// loggerRef.current.info(`Warning: URL company code (${companyCode}) doesn't match initialized company code (${activeCompanyCode})`);
|
|
595
606
|
// }
|
|
596
607
|
// // Process the affiliate attribution
|
|
597
608
|
// await storeInsertAffiliateIdentifier({ link: shortCode });
|
|
598
609
|
// return true;
|
|
599
610
|
// } catch (error) {
|
|
600
|
-
//
|
|
611
|
+
// loggerRef.current.error('Error handling universal link:', error);
|
|
601
612
|
// return false;
|
|
602
613
|
// }
|
|
603
614
|
// };
|
|
@@ -639,7 +650,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
639
650
|
// First try to extract from query parameter (new format: scheme://insert-affiliate?code=SHORTCODE)
|
|
640
651
|
const queryCode = parseShortCodeFromQuery(url);
|
|
641
652
|
if (queryCode) {
|
|
642
|
-
|
|
653
|
+
loggerRef.current.info(`Found short code in query parameter: ${queryCode}`);
|
|
643
654
|
return queryCode;
|
|
644
655
|
}
|
|
645
656
|
// Fall back to path format (legacy: scheme://SHORTCODE)
|
|
@@ -652,7 +663,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
652
663
|
if (shortCode === 'insert-affiliate' || shortCode.startsWith('insert-affiliate?')) {
|
|
653
664
|
return null;
|
|
654
665
|
}
|
|
655
|
-
|
|
666
|
+
loggerRef.current.info(`Found short code in URL path (legacy format): ${shortCode}`);
|
|
656
667
|
return shortCode;
|
|
657
668
|
}
|
|
658
669
|
return null;
|
|
@@ -694,20 +705,20 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
694
705
|
// Helper function for verbose logging (uses ref to avoid stale closures)
|
|
695
706
|
const verboseLog = (message) => {
|
|
696
707
|
if (verboseLoggingRef.current) {
|
|
697
|
-
|
|
708
|
+
loggerRef.current.debug(`[VERBOSE] ${message}`);
|
|
698
709
|
}
|
|
699
710
|
};
|
|
700
711
|
// Helper function to log errors
|
|
701
712
|
const errorLog = (message, type) => {
|
|
702
713
|
switch (type) {
|
|
703
714
|
case 'error':
|
|
704
|
-
|
|
715
|
+
loggerRef.current.error(`ENCOUNTER ERROR ~ ${message}`);
|
|
705
716
|
break;
|
|
706
717
|
case 'warn':
|
|
707
|
-
|
|
718
|
+
loggerRef.current.warn(`ENCOUNTER WARNING ~ ${message}`);
|
|
708
719
|
break;
|
|
709
720
|
default:
|
|
710
|
-
|
|
721
|
+
loggerRef.current.info(`LOGGING ~ ${message}`);
|
|
711
722
|
break;
|
|
712
723
|
}
|
|
713
724
|
};
|
|
@@ -766,7 +777,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
766
777
|
return;
|
|
767
778
|
}
|
|
768
779
|
if (verboseLogging) {
|
|
769
|
-
|
|
780
|
+
loggerRef.current.info('Reporting SDK initialization for onboarding verification...');
|
|
770
781
|
}
|
|
771
782
|
const response = yield fetch('https://api.insertaffiliate.com/V1/onboarding/sdk-init', {
|
|
772
783
|
method: 'POST',
|
|
@@ -778,17 +789,17 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
778
789
|
if (response.ok) {
|
|
779
790
|
yield async_storage_1.default.setItem(ASYNC_KEYS.SDK_INIT_REPORTED, 'true');
|
|
780
791
|
if (verboseLogging) {
|
|
781
|
-
|
|
792
|
+
loggerRef.current.info('SDK initialization reported successfully');
|
|
782
793
|
}
|
|
783
794
|
}
|
|
784
795
|
else if (verboseLogging) {
|
|
785
|
-
|
|
796
|
+
loggerRef.current.info(`SDK initialization report failed with status: ${response.status}`);
|
|
786
797
|
}
|
|
787
798
|
}
|
|
788
799
|
catch (error) {
|
|
789
800
|
// Silently fail - this is non-critical telemetry
|
|
790
801
|
if (verboseLogging) {
|
|
791
|
-
|
|
802
|
+
loggerRef.current.info(`SDK initialization report error: ${error}`);
|
|
792
803
|
}
|
|
793
804
|
}
|
|
794
805
|
});
|
|
@@ -1001,7 +1012,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1001
1012
|
systemInfo.deviceType = 'unknown';
|
|
1002
1013
|
}
|
|
1003
1014
|
if (verboseLogging) {
|
|
1004
|
-
|
|
1015
|
+
loggerRef.current.info('system info:', systemInfo);
|
|
1005
1016
|
}
|
|
1006
1017
|
return systemInfo;
|
|
1007
1018
|
});
|
|
@@ -1137,7 +1148,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1137
1148
|
// Sends enhanced system info to the backend API for deep link event tracking
|
|
1138
1149
|
const sendSystemInfoToBackend = (systemInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1139
1150
|
if (verboseLogging) {
|
|
1140
|
-
|
|
1151
|
+
loggerRef.current.info('Sending system info to backend...');
|
|
1141
1152
|
}
|
|
1142
1153
|
try {
|
|
1143
1154
|
const apiUrlString = 'https://insertaffiliate.link/V1/appDeepLinkEvents';
|
|
@@ -1162,6 +1173,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1162
1173
|
}
|
|
1163
1174
|
// Check for a successful response
|
|
1164
1175
|
if (response.status >= 200 && response.status <= 299) {
|
|
1176
|
+
yield saveValueInAsync(ASYNC_KEYS.SYSTEM_INFO_SENT, 'true');
|
|
1165
1177
|
verboseLog('System info sent successfully');
|
|
1166
1178
|
}
|
|
1167
1179
|
else {
|
|
@@ -1259,12 +1271,12 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1259
1271
|
}
|
|
1260
1272
|
catch (error) {
|
|
1261
1273
|
verboseLog(`Error getting affiliate details: ${error}`);
|
|
1262
|
-
|
|
1274
|
+
loggerRef.current.error('Error getting affiliate details:', error);
|
|
1263
1275
|
return null;
|
|
1264
1276
|
}
|
|
1265
1277
|
});
|
|
1266
1278
|
const setShortCodeImpl = (shortCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1267
|
-
|
|
1279
|
+
loggerRef.current.info('Setting short code.');
|
|
1268
1280
|
yield generateThenSetUserID();
|
|
1269
1281
|
// Validate it is a short code
|
|
1270
1282
|
const capitalisedShortCode = shortCode.toUpperCase();
|
|
@@ -1274,11 +1286,11 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1274
1286
|
if (exists) {
|
|
1275
1287
|
// If affiliate exists, set the Insert Affiliate Identifier
|
|
1276
1288
|
yield storeInsertAffiliateIdentifier({ link: capitalisedShortCode, source: 'short_code_manual' });
|
|
1277
|
-
|
|
1289
|
+
loggerRef.current.info(`Short code ${capitalisedShortCode} validated and stored successfully.`);
|
|
1278
1290
|
return true;
|
|
1279
1291
|
}
|
|
1280
1292
|
else {
|
|
1281
|
-
|
|
1293
|
+
loggerRef.current.warn(`Short code ${capitalisedShortCode} does not exist. Not storing.`);
|
|
1282
1294
|
return false;
|
|
1283
1295
|
}
|
|
1284
1296
|
});
|
|
@@ -1297,13 +1309,13 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1297
1309
|
try {
|
|
1298
1310
|
const shortCode = yield returnInsertAffiliateIdentifierImpl();
|
|
1299
1311
|
if (!shortCode) {
|
|
1300
|
-
|
|
1312
|
+
loggerRef.current.info('No affiliate stored - not saving expected transaction.');
|
|
1301
1313
|
return null;
|
|
1302
1314
|
}
|
|
1303
1315
|
const userAccountToken = yield getOrCreateUserAccountToken();
|
|
1304
|
-
|
|
1316
|
+
loggerRef.current.info('User account token:', userAccountToken);
|
|
1305
1317
|
if (!userAccountToken) {
|
|
1306
|
-
|
|
1318
|
+
loggerRef.current.error('Failed to generate user account token.');
|
|
1307
1319
|
return null;
|
|
1308
1320
|
}
|
|
1309
1321
|
else {
|
|
@@ -1316,12 +1328,12 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1316
1328
|
if ((error === null || error === void 0 ? void 0 : error.code) === 'E_IAP_NOT_AVAILABLE' ||
|
|
1317
1329
|
(error instanceof Error && error.message.includes('E_IAP_NOT_AVAILABLE'))) {
|
|
1318
1330
|
if (isDevelopmentEnvironment) {
|
|
1319
|
-
|
|
1331
|
+
loggerRef.current.warn('IAP not available in development environment. Cannot store expected transaction.');
|
|
1320
1332
|
verboseLog('E_IAP_NOT_AVAILABLE error in returnUserAccountTokenAndStoreExpectedTransaction - gracefully handling in development');
|
|
1321
1333
|
}
|
|
1322
1334
|
return null; // Return null but don't crash
|
|
1323
1335
|
}
|
|
1324
|
-
|
|
1336
|
+
loggerRef.current.error('Error in returnUserAccountTokenAndStoreExpectedTransaction:', error);
|
|
1325
1337
|
return null;
|
|
1326
1338
|
}
|
|
1327
1339
|
;
|
|
@@ -1437,15 +1449,15 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1437
1449
|
});
|
|
1438
1450
|
// MARK: Insert Affiliate Identifier
|
|
1439
1451
|
const setInsertAffiliateIdentifierImpl = (referringLink) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1440
|
-
|
|
1452
|
+
loggerRef.current.info('Setting affiliate identifier.');
|
|
1441
1453
|
verboseLog(`Input referringLink: ${referringLink}`);
|
|
1442
1454
|
try {
|
|
1443
1455
|
verboseLog('Generating or retrieving user ID...');
|
|
1444
1456
|
const customerID = yield generateThenSetUserID();
|
|
1445
|
-
|
|
1457
|
+
loggerRef.current.info('Completed generateThenSetUserID within setInsertAffiliateIdentifier.');
|
|
1446
1458
|
verboseLog(`Customer ID: ${customerID}`);
|
|
1447
1459
|
if (!referringLink) {
|
|
1448
|
-
|
|
1460
|
+
loggerRef.current.warn('Referring link is invalid.');
|
|
1449
1461
|
verboseLog('Referring link is empty or invalid, storing as-is');
|
|
1450
1462
|
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1451
1463
|
return `${referringLink}-${customerID}`;
|
|
@@ -1455,14 +1467,14 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1455
1467
|
const activeCompanyCode = yield getActiveCompanyCode();
|
|
1456
1468
|
verboseLog(`Active company code: ${activeCompanyCode || 'Not found'}`);
|
|
1457
1469
|
if (!activeCompanyCode) {
|
|
1458
|
-
|
|
1470
|
+
loggerRef.current.error('Company code is not set. Please initialize the SDK with a valid company code.');
|
|
1459
1471
|
verboseLog('Company code missing, cannot proceed with API call');
|
|
1460
1472
|
return;
|
|
1461
1473
|
}
|
|
1462
1474
|
// Check if referring link is already a short code, if so save it and stop here.
|
|
1463
1475
|
verboseLog('Checking if referring link is already a short code...');
|
|
1464
1476
|
if (isShortCode(referringLink)) {
|
|
1465
|
-
|
|
1477
|
+
loggerRef.current.info('Referring link is already a short code.');
|
|
1466
1478
|
verboseLog('Link is already a short code, storing directly');
|
|
1467
1479
|
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1468
1480
|
return `${referringLink}-${customerID}`;
|
|
@@ -1473,14 +1485,14 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1473
1485
|
verboseLog('Encoding referring link for API call...');
|
|
1474
1486
|
const encodedAffiliateLink = encodeURIComponent(referringLink);
|
|
1475
1487
|
if (!encodedAffiliateLink) {
|
|
1476
|
-
|
|
1488
|
+
loggerRef.current.error('Failed to encode affiliate link.');
|
|
1477
1489
|
verboseLog('Failed to encode link, storing original');
|
|
1478
1490
|
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
1479
1491
|
return `${referringLink}-${customerID}`;
|
|
1480
1492
|
}
|
|
1481
1493
|
// Create the request URL
|
|
1482
1494
|
const urlString = `https://api.insertaffiliate.com/V1/convert-deep-link-to-short-link?companyId=${activeCompanyCode}&deepLinkUrl=${encodedAffiliateLink}`;
|
|
1483
|
-
|
|
1495
|
+
loggerRef.current.info('urlString .', urlString);
|
|
1484
1496
|
verboseLog('Making API request to convert deep link to short code...');
|
|
1485
1497
|
const response = yield axios_1.default.get(urlString, {
|
|
1486
1498
|
headers: {
|
|
@@ -1491,7 +1503,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1491
1503
|
// Call to the backend for the short code and save the resolse in valid
|
|
1492
1504
|
if (response.status === 200 && response.data.shortLink) {
|
|
1493
1505
|
const shortLink = response.data.shortLink;
|
|
1494
|
-
|
|
1506
|
+
loggerRef.current.info('Short link received:', shortLink);
|
|
1495
1507
|
verboseLog(`Successfully converted to short link: ${shortLink}`);
|
|
1496
1508
|
verboseLog('Storing short link to AsyncStorage...');
|
|
1497
1509
|
yield storeInsertAffiliateIdentifier({ link: shortLink, source: 'referring_link' });
|
|
@@ -1499,7 +1511,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1499
1511
|
return `${shortLink}-${customerID}`;
|
|
1500
1512
|
}
|
|
1501
1513
|
else {
|
|
1502
|
-
|
|
1514
|
+
loggerRef.current.warn('Unexpected response format.');
|
|
1503
1515
|
verboseLog(`Unexpected API response. Status: ${response.status}, Data: ${JSON.stringify(response.data)}`);
|
|
1504
1516
|
verboseLog('Storing original link as fallback');
|
|
1505
1517
|
yield storeInsertAffiliateIdentifier({ link: referringLink, source: 'referring_link' });
|
|
@@ -1507,7 +1519,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1507
1519
|
}
|
|
1508
1520
|
}
|
|
1509
1521
|
catch (error) {
|
|
1510
|
-
|
|
1522
|
+
loggerRef.current.error('Error:', error);
|
|
1511
1523
|
verboseLog(`Error in setInsertAffiliateIdentifier: ${error}`);
|
|
1512
1524
|
}
|
|
1513
1525
|
});
|
|
@@ -1559,11 +1571,11 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1559
1571
|
(jsonIapPurchase === null || jsonIapPurchase === void 0 ? void 0 : jsonIapPurchase.code) === 'E_IAP_NOT_AVAILABLE' ||
|
|
1560
1572
|
(typeof jsonIapPurchase === 'string' && jsonIapPurchase.includes('E_IAP_NOT_AVAILABLE'))) {
|
|
1561
1573
|
if (isDevelopmentEnvironment) {
|
|
1562
|
-
|
|
1574
|
+
loggerRef.current.warn('IAP not available in development environment. This is expected behavior.');
|
|
1563
1575
|
verboseLog('E_IAP_NOT_AVAILABLE error detected in development - gracefully handling');
|
|
1564
1576
|
}
|
|
1565
1577
|
else {
|
|
1566
|
-
|
|
1578
|
+
loggerRef.current.error('IAP not available in production environment. Please check your IAP configuration.');
|
|
1567
1579
|
}
|
|
1568
1580
|
return false; // Return false but don't crash
|
|
1569
1581
|
}
|
|
@@ -1607,11 +1619,11 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1607
1619
|
data: requestBody,
|
|
1608
1620
|
});
|
|
1609
1621
|
if (response.status === 200) {
|
|
1610
|
-
|
|
1622
|
+
loggerRef.current.info('Validation successful:', response.data);
|
|
1611
1623
|
return true;
|
|
1612
1624
|
}
|
|
1613
1625
|
else {
|
|
1614
|
-
|
|
1626
|
+
loggerRef.current.error('Validation failed:', response.data);
|
|
1615
1627
|
return false;
|
|
1616
1628
|
}
|
|
1617
1629
|
}
|
|
@@ -1620,19 +1632,19 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1620
1632
|
if ((error === null || error === void 0 ? void 0 : error.code) === 'E_IAP_NOT_AVAILABLE' ||
|
|
1621
1633
|
(error instanceof Error && error.message.includes('E_IAP_NOT_AVAILABLE'))) {
|
|
1622
1634
|
if (isDevelopmentEnvironment) {
|
|
1623
|
-
|
|
1635
|
+
loggerRef.current.warn('IAP not available in development environment. SDK will continue without purchase validation.');
|
|
1624
1636
|
verboseLog('E_IAP_NOT_AVAILABLE error caught in validatePurchaseWithIapticAPI - gracefully handling in development');
|
|
1625
1637
|
}
|
|
1626
1638
|
else {
|
|
1627
|
-
|
|
1639
|
+
loggerRef.current.error('IAP not available in production environment. Please check your IAP configuration.');
|
|
1628
1640
|
}
|
|
1629
1641
|
return false; // Return false but don't crash
|
|
1630
1642
|
}
|
|
1631
1643
|
if (error instanceof Error) {
|
|
1632
|
-
|
|
1644
|
+
loggerRef.current.error(`validatePurchaseWithIapticAPI Error: ${error.message}`);
|
|
1633
1645
|
}
|
|
1634
1646
|
else {
|
|
1635
|
-
|
|
1647
|
+
loggerRef.current.error(`validatePurchaseWithIapticAPI Unknown Error: ${JSON.stringify(error)}`);
|
|
1636
1648
|
}
|
|
1637
1649
|
return false;
|
|
1638
1650
|
}
|
|
@@ -1641,13 +1653,13 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1641
1653
|
verboseLog(`Storing expected store transaction with token: ${purchaseToken}`);
|
|
1642
1654
|
const activeCompanyCode = yield getActiveCompanyCode();
|
|
1643
1655
|
if (!activeCompanyCode) {
|
|
1644
|
-
|
|
1656
|
+
loggerRef.current.error("Company code is not set. Please initialize the SDK with a valid company code.");
|
|
1645
1657
|
verboseLog("Cannot store transaction: no company code available");
|
|
1646
1658
|
return;
|
|
1647
1659
|
}
|
|
1648
1660
|
const shortCode = yield returnInsertAffiliateIdentifierImpl();
|
|
1649
1661
|
if (!shortCode) {
|
|
1650
|
-
|
|
1662
|
+
loggerRef.current.error("No affiliate identifier found. Please set one before tracking events.");
|
|
1651
1663
|
verboseLog("Cannot store transaction: no affiliate identifier available");
|
|
1652
1664
|
return;
|
|
1653
1665
|
}
|
|
@@ -1659,7 +1671,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1659
1671
|
shortCode,
|
|
1660
1672
|
storedDate: new Date().toISOString(), // ISO8601 format
|
|
1661
1673
|
};
|
|
1662
|
-
|
|
1674
|
+
loggerRef.current.info("Storing expected transaction: ", payload);
|
|
1663
1675
|
verboseLog("Making API call to store expected transaction...");
|
|
1664
1676
|
try {
|
|
1665
1677
|
const response = yield fetch("https://api.insertaffiliate.com/v1/api/app-store-webhook/create-expected-transaction", {
|
|
@@ -1671,17 +1683,17 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1671
1683
|
});
|
|
1672
1684
|
verboseLog(`API response status: ${response.status}`);
|
|
1673
1685
|
if (response.ok) {
|
|
1674
|
-
|
|
1686
|
+
loggerRef.current.info("Expected transaction stored successfully.");
|
|
1675
1687
|
verboseLog("Expected transaction stored successfully on server");
|
|
1676
1688
|
}
|
|
1677
1689
|
else {
|
|
1678
1690
|
const errorText = yield response.text();
|
|
1679
|
-
|
|
1691
|
+
loggerRef.current.error(`Failed to store expected transaction with status code: ${response.status}. Response: ${errorText}`);
|
|
1680
1692
|
verboseLog(`API error response: ${errorText}`);
|
|
1681
1693
|
}
|
|
1682
1694
|
}
|
|
1683
1695
|
catch (error) {
|
|
1684
|
-
|
|
1696
|
+
loggerRef.current.error(`Error storing expected transaction: ${error}`);
|
|
1685
1697
|
verboseLog(`Network error storing transaction: ${error}`);
|
|
1686
1698
|
}
|
|
1687
1699
|
});
|
|
@@ -1691,13 +1703,13 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1691
1703
|
verboseLog(`Tracking event: ${eventName}`);
|
|
1692
1704
|
const activeCompanyCode = yield getActiveCompanyCode();
|
|
1693
1705
|
if (!activeCompanyCode) {
|
|
1694
|
-
|
|
1706
|
+
loggerRef.current.error("Company code is not set. Please initialize the SDK with a valid company code.");
|
|
1695
1707
|
verboseLog("Cannot track event: no company code available");
|
|
1696
1708
|
return Promise.resolve();
|
|
1697
1709
|
}
|
|
1698
|
-
|
|
1710
|
+
loggerRef.current.info("track event called with - companyCode: ", activeCompanyCode);
|
|
1699
1711
|
if (!referrerLink || !userId) {
|
|
1700
|
-
|
|
1712
|
+
loggerRef.current.warn('No affiliate identifier found. Please set one before tracking events.');
|
|
1701
1713
|
verboseLog("Cannot track event: no affiliate identifier available");
|
|
1702
1714
|
return Promise.resolve();
|
|
1703
1715
|
}
|
|
@@ -1715,16 +1727,16 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1715
1727
|
});
|
|
1716
1728
|
verboseLog(`Track event API response status: ${response.status}`);
|
|
1717
1729
|
if (response.status === 200) {
|
|
1718
|
-
|
|
1730
|
+
loggerRef.current.info('Event tracked successfully');
|
|
1719
1731
|
verboseLog("Event tracked successfully on server");
|
|
1720
1732
|
}
|
|
1721
1733
|
else {
|
|
1722
|
-
|
|
1734
|
+
loggerRef.current.error(`Failed to track event with status code: ${response.status}`);
|
|
1723
1735
|
verboseLog(`Track event API error: status ${response.status}, response: ${JSON.stringify(response.data)}`);
|
|
1724
1736
|
}
|
|
1725
1737
|
}
|
|
1726
1738
|
catch (error) {
|
|
1727
|
-
|
|
1739
|
+
loggerRef.current.error('Error tracking event:', error);
|
|
1728
1740
|
verboseLog(`Network error tracking event: ${error}`);
|
|
1729
1741
|
return Promise.reject(error);
|
|
1730
1742
|
}
|
|
@@ -1756,7 +1768,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1756
1768
|
offerCode.includes("errorAffiliateoffercodenotfoundinanycompany") ||
|
|
1757
1769
|
offerCode.includes("errorAffiliateoffercodenotfoundinanycompanyAffiliatelinkwas") ||
|
|
1758
1770
|
offerCode.includes("Routenotfound"))) {
|
|
1759
|
-
|
|
1771
|
+
loggerRef.current.warn(`Offer code not found or invalid: ${offerCode}`);
|
|
1760
1772
|
verboseLog(`Offer code not found or invalid: ${offerCode}`);
|
|
1761
1773
|
return null;
|
|
1762
1774
|
}
|
|
@@ -1765,13 +1777,13 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1765
1777
|
return cleanedOfferCode;
|
|
1766
1778
|
}
|
|
1767
1779
|
else {
|
|
1768
|
-
|
|
1780
|
+
loggerRef.current.error(`Failed to fetch offer code. Status code: ${response.status}, Response: ${JSON.stringify(response.data)}`);
|
|
1769
1781
|
verboseLog(`Failed to fetch offer code. Status code: ${response.status}, Response: ${JSON.stringify(response.data)}`);
|
|
1770
1782
|
return null;
|
|
1771
1783
|
}
|
|
1772
1784
|
}
|
|
1773
1785
|
catch (error) {
|
|
1774
|
-
|
|
1786
|
+
loggerRef.current.error('Error fetching offer code:', error);
|
|
1775
1787
|
verboseLog(`Error fetching offer code: ${error}`);
|
|
1776
1788
|
return null;
|
|
1777
1789
|
}
|
|
@@ -1785,7 +1797,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1785
1797
|
yield saveValueInAsync(ASYNC_KEYS.OFFER_CODE, offerCode);
|
|
1786
1798
|
setOfferCode(offerCode);
|
|
1787
1799
|
verboseLog(`Successfully stored offer code: ${offerCode}`);
|
|
1788
|
-
|
|
1800
|
+
loggerRef.current.info('Offer code retrieved and stored successfully');
|
|
1789
1801
|
return offerCode;
|
|
1790
1802
|
}
|
|
1791
1803
|
else {
|
|
@@ -1797,7 +1809,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1797
1809
|
}
|
|
1798
1810
|
}
|
|
1799
1811
|
catch (error) {
|
|
1800
|
-
|
|
1812
|
+
loggerRef.current.error('Error retrieving and storing offer code:', error);
|
|
1801
1813
|
verboseLog(`Error in retrieveAndStoreOfferCode: ${error}`);
|
|
1802
1814
|
return null;
|
|
1803
1815
|
}
|
|
@@ -1887,6 +1899,9 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1887
1899
|
const handleInsertLinks = (0, react_1.useCallback)((url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1888
1900
|
return handleInsertLinksImplRef.current(url);
|
|
1889
1901
|
}), []);
|
|
1902
|
+
const setLogger = (0, react_1.useCallback)((logger) => {
|
|
1903
|
+
loggerRef.current = logger;
|
|
1904
|
+
}, []);
|
|
1890
1905
|
return (react_1.default.createElement(exports.DeepLinkIapContext.Provider, { value: {
|
|
1891
1906
|
referrerLink,
|
|
1892
1907
|
userId,
|
|
@@ -1905,6 +1920,7 @@ const DeepLinkIapProvider = ({ children, }) => {
|
|
|
1905
1920
|
setInsertAffiliateIdentifierChangeCallback: setInsertAffiliateIdentifierChangeCallbackHandler,
|
|
1906
1921
|
handleInsertLinks,
|
|
1907
1922
|
initialize,
|
|
1923
|
+
setLogger,
|
|
1908
1924
|
isInitialized,
|
|
1909
1925
|
} }, children));
|
|
1910
1926
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import DeepLinkIapProvider from "./DeepLinkIapProvider";
|
|
2
2
|
import useDeepLinkIapProvider from "./useDeepLinkIapProvider";
|
|
3
3
|
export { DeepLinkIapProvider, useDeepLinkIapProvider };
|
|
4
|
-
export type { InsertAffiliateIdentifierChangeCallback, AffiliateDetails } from "./DeepLinkIapProvider";
|
|
4
|
+
export type { InsertAffiliateIdentifierChangeCallback, AffiliateDetails, InsertAffiliateLogger } from "./DeepLinkIapProvider";
|