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