customerio-expo-plugin 1.0.0-beta.12 → 1.0.0-beta.13

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.LOCAL_PATH_TO_RN_SDK = exports.LOCAL_PATH_TO_CIO_NSE_FILES = exports.IOS_DEPLOYMENT_TARGET = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.DEFAULT_BUNDLE_VERSION = exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = exports.CIO_TARGET_NAME = exports.CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = exports.CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = exports.CIO_NOTIFICATION_TARGET_NAME = exports.CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = exports.CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX = exports.CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = exports.CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX = exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX = exports.CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = exports.CIO_APPDELEGATEHEADER_SNIPPET = exports.CIO_APPDELEGATEHEADER_REGEX = exports.CIO_APPDELEGATEDECLARATION_REGEX = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = void 0;
6
+ exports.LOCAL_PATH_TO_RN_SDK = exports.LOCAL_PATH_TO_CIO_NSE_FILES = exports.IOS_DEPLOYMENT_TARGET = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.DEFAULT_BUNDLE_VERSION = exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = exports.CIO_TARGET_NAME = exports.CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = exports.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = exports.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX = exports.CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = exports.CIO_NOTIFICATION_TARGET_NAME = exports.CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = exports.CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX = exports.CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = exports.CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX = exports.CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = exports.CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX = exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX = exports.CIO_DEEPLINK_COMMENT_REGEX = exports.CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = exports.CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = exports.CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = exports.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = exports.CIO_APPDELEGATEHEADER_REGEX = exports.CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = exports.CIO_APPDELEGATEDECLARATION_REGEX = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = void 0;
7
7
  exports.getRelativePathToRNSDK = getRelativePathToRNSDK;
8
8
  const finder = require('find-package-json');
9
9
  const path = require('path');
@@ -26,7 +26,7 @@ const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;
26
26
  exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = BUNDLE_SHORT_VERSION_TEMPLATE_REGEX;
27
27
  const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;
28
28
  exports.BUNDLE_VERSION_TEMPLATE_REGEX = BUNDLE_VERSION_TEMPLATE_REGEX;
29
- const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = /(- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions(\s|\n)*?\{)((.|\n)*)\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
29
+ const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = /.*\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
30
30
  exports.CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = CIO_DIDFINISHLAUNCHINGMETHOD_REGEX;
31
31
  const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX = /return \[super application:application didFailToRegisterForRemoteNotificationsWithError:error\];/;
32
32
  exports.CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX = CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX;
@@ -36,8 +36,14 @@ const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX = /return \[sup
36
36
  exports.CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX = CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX;
37
37
  const CIO_APPDELEGATEDECLARATION_REGEX = /@implementation AppDelegate(.|\n)/;
38
38
  exports.CIO_APPDELEGATEDECLARATION_REGEX = CIO_APPDELEGATEDECLARATION_REGEX;
39
- const CIO_APPDELEGATEHEADER_REGEX = /@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>/;
39
+ const CIO_APPDELEGATEHEADER_REGEX = /(@interface AppDelegate\s*:\s*EXAppDelegateWrapper\s*)(<([^>]+)>)?/;
40
40
  exports.CIO_APPDELEGATEHEADER_REGEX = CIO_APPDELEGATEHEADER_REGEX;
41
+ const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX = /^\s*RCTBridge\s*\*\s*\w+\s*=\s*\[\s*self\.reactDelegate\s+createBridgeWithDelegate:self\s+launchOptions:launchOptions\s*\];\s*$/gm;
42
+ exports.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;
43
+ const CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX = /^\s*return\s\[\s*super\s*application:\s*application\s*didFinishLaunchingWithOptions\s*:\s*launchOptions\s*\];/gm;
44
+ exports.CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;
45
+ const CIO_DEEPLINK_COMMENT_REGEX = /\sDeep link workaround for app killed state start/gm;
46
+ exports.CIO_DEEPLINK_COMMENT_REGEX = CIO_DEEPLINK_COMMENT_REGEX;
41
47
  const DEFAULT_BUNDLE_VERSION = '1';
42
48
  exports.DEFAULT_BUNDLE_VERSION = DEFAULT_BUNDLE_VERSION;
43
49
  const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
@@ -46,16 +52,21 @@ const CIO_TARGET_NAME = 'CustomerIOSDK';
46
52
  exports.CIO_TARGET_NAME = CIO_TARGET_NAME;
47
53
  const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';
48
54
  exports.CIO_NOTIFICATION_TARGET_NAME = CIO_NOTIFICATION_TARGET_NAME;
49
- const CIO_APPDELEGATEHEADER_SNIPPET = `
50
- #import <UserNotifications/UserNotifications.h>
51
-
52
- @interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>
53
- `;
54
- exports.CIO_APPDELEGATEHEADER_SNIPPET = CIO_APPDELEGATEHEADER_SNIPPET;
55
+ const CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = `#import <UserNotifications/UserNotifications.h>`;
56
+ exports.CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = CIO_APPDELEGATEHEADER_IMPORT_SNIPPET;
57
+ const CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = 'UNUserNotificationCenterDelegate';
58
+ exports.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET;
55
59
  const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `
56
60
  CIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];
57
61
  `;
58
62
  exports.CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET;
63
+ const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = `
64
+ RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:modifiedLaunchOptions];
65
+ `;
66
+ exports.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;
67
+ const CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = `
68
+ return [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];`;
69
+ exports.CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET;
59
70
  const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `
60
71
  [super application:application didFailToRegisterForRemoteNotificationsWithError:error];
61
72
  [pnHandlerObj application:application error:error];
@@ -68,11 +79,31 @@ const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `
68
79
  exports.CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET;
69
80
  const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `
70
81
  // Register for push notifications
71
- [pnHandlerObj registerPushNotification:self];
82
+ [pnHandlerObj registerPushNotification];
83
+ `;
84
+ exports.CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET;
85
+ const CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = `
86
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
87
+ center.delegate = self;
88
+ `;
89
+ exports.CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET;
90
+ const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = `
91
+ // Deep link workaround for app killed state start
92
+ NSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];
93
+ if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
94
+ NSDictionary *pushContent = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
95
+ if (pushContent[@"CIO"] && pushContent[@"CIO"][@"push"] && pushContent[@"CIO"][@"push"][@"link"]) {
96
+ NSString *initialURL = pushContent[@"CIO"][@"push"][@"link"];
97
+ if (!launchOptions[UIApplicationLaunchOptionsURLKey]) {
98
+ modifiedLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];
99
+ }
100
+ }
101
+ }
102
+ //Deep link workaround for app killed state ends
72
103
  `;
73
104
 
74
105
  // Enable push handling - notification response
75
- exports.CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET;
106
+ exports.CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET;
76
107
  const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = `
77
108
  - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
78
109
  [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
@@ -87,11 +118,10 @@ const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `
87
118
  }`;
88
119
  exports.CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET;
89
120
  const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
90
- @objc(registerPushNotification:)
91
- public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {
121
+ @objc(registerPushNotification)
122
+ public func registerPushNotification() {
92
123
 
93
124
  let center = UNUserNotificationCenter.current()
94
- center.delegate = notificationDelegate
95
125
  center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
96
126
  if error == nil{
97
127
  DispatchQueue.main.async {
@@ -1 +1 @@
1
- {"version":3,"names":["finder","require","path","f","__dirname","pluginPackageRoot","next","filename","dirname","LOCAL_PATH_TO_RN_SDK","join","exports","LOCAL_PATH_TO_CIO_NSE_FILES","getRelativePathToRNSDK","currentFile","relative","IOS_DEPLOYMENT_TARGET","GROUP_IDENTIFIER_TEMPLATE_REGEX","BUNDLE_SHORT_VERSION_TEMPLATE_REGEX","BUNDLE_VERSION_TEMPLATE_REGEX","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_APPDELEGATEDECLARATION_REGEX","CIO_APPDELEGATEHEADER_REGEX","DEFAULT_BUNDLE_VERSION","DEFAULT_BUNDLE_SHORT_VERSION","CIO_TARGET_NAME","CIO_NOTIFICATION_TARGET_NAME","CIO_APPDELEGATEHEADER_SNIPPET","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","CIO_REGISTER_PUSHNOTIFICATION_SNIPPET"],"sources":["ios.ts"],"sourcesContent":["const finder = require('find-package-json');\nconst path = require('path');\n\nconst f = finder(__dirname);\nlet pluginPackageRoot = f.next().filename;\n// This is the path to the root of the customerio-expo-plugin package\npluginPackageRoot = path.dirname(pluginPackageRoot);\n\nexport const LOCAL_PATH_TO_RN_SDK = path.join(\n pluginPackageRoot,\n '../customerio-reactnative'\n)\n\nexport const LOCAL_PATH_TO_CIO_NSE_FILES = path.join(\n pluginPackageRoot,\n 'src/helpers/native-files/ios'\n);\n\nexport function getRelativePathToRNSDK(currentFile: string) {\n return path.relative(path.dirname(currentFile), LOCAL_PATH_TO_RN_SDK);\n}\n\nexport const IOS_DEPLOYMENT_TARGET = '13.0';\nexport const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;\nexport const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;\nexport const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;\nexport const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX =\n /(- \\(BOOL\\)application:\\(UIApplication \\*\\)application didFinishLaunchingWithOptions:\\(NSDictionary \\*\\)launchOptions(\\s|\\n)*?\\{)((.|\\n)*)\\[super(\\s)application:application(\\s)didFinishLaunchingWithOptions:launchOptions\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX =\n /return \\[super application:application didFailToRegisterForRemoteNotificationsWithError:error\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX =\n /(- \\(void\\)application:\\(UIApplication \\*\\)application didFailToRegisterForRemoteNotificationsWithError:\\(NSError \\*\\)error(\\s|\\n)*?\\{)(.|\\n){2}.*\\n\\}/;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX =\n /return \\[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\\];/;\n\nexport const CIO_APPDELEGATEDECLARATION_REGEX =\n /@implementation AppDelegate(.|\\n)/;\n\nexport const CIO_APPDELEGATEHEADER_REGEX =\n /@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>/;\nexport const DEFAULT_BUNDLE_VERSION = '1';\nexport const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';\nexport const CIO_TARGET_NAME = 'CustomerIOSDK';\nexport const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';\nexport const CIO_APPDELEGATEHEADER_SNIPPET = `\n#import <UserNotifications/UserNotifications.h>\n\n@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>\n`;\n\nexport const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `\nCIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];\n`;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `\n [super application:application didFailToRegisterForRemoteNotificationsWithError:error];\n [pnHandlerObj application:application error:error];\n`;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `\n [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\n return [pnHandlerObj application:application deviceToken:deviceToken];\n`;\n\nexport const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `\n // Register for push notifications\n [pnHandlerObj registerPushNotification:self];\n`;\n\n// Enable push handling - notification response\nexport const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = `\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {\n [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];\n}`;\n\n// Foreground push handling\nexport const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `\n// show push when the app is in foreground\n- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {\n completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);\n}`;\nexport const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `\n@objc(registerPushNotification:)\n public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {\n\n let center = UNUserNotificationCenter.current()\n center.delegate = notificationDelegate\n center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n if error == nil{\n DispatchQueue.main.async {\n UIApplication.shared.registerForRemoteNotifications()\n }\n }\n }\n }`;\n"],"mappings":";;;;;;;AAAA,MAAMA,MAAM,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAMC,IAAI,GAAGD,OAAO,CAAC,MAAM,CAAC;AAE5B,MAAME,CAAC,GAAGH,MAAM,CAACI,SAAS,CAAC;AAC3B,IAAIC,iBAAiB,GAAGF,CAAC,CAACG,IAAI,CAAC,CAAC,CAACC,QAAQ;AACzC;AACAF,iBAAiB,GAAGH,IAAI,CAACM,OAAO,CAACH,iBAAiB,CAAC;AAE5C,MAAMI,oBAAoB,GAAGP,IAAI,CAACQ,IAAI,CAC3CL,iBAAiB,EACjB,2BACF,CAAC;AAAAM,OAAA,CAAAF,oBAAA,GAAAA,oBAAA;AAEM,MAAMG,2BAA2B,GAAGV,IAAI,CAACQ,IAAI,CAClDL,iBAAiB,EACjB,8BACF,CAAC;AAACM,OAAA,CAAAC,2BAAA,GAAAA,2BAAA;AAEK,SAASC,sBAAsBA,CAACC,WAAmB,EAAE;EAC1D,OAAOZ,IAAI,CAACa,QAAQ,CAACb,IAAI,CAACM,OAAO,CAACM,WAAW,CAAC,EAAEL,oBAAoB,CAAC;AACvE;AAEO,MAAMO,qBAAqB,GAAG,MAAM;AAACL,OAAA,CAAAK,qBAAA,GAAAA,qBAAA;AACrC,MAAMC,+BAA+B,GAAG,wBAAwB;AAACN,OAAA,CAAAM,+BAAA,GAAAA,+BAAA;AACjE,MAAMC,mCAAmC,GAAG,4BAA4B;AAACP,OAAA,CAAAO,mCAAA,GAAAA,mCAAA;AACzE,MAAMC,6BAA6B,GAAG,sBAAsB;AAACR,OAAA,CAAAQ,6BAAA,GAAAA,6BAAA;AAC7D,MAAMC,kCAAkC,GAC7C,gOAAgO;AAACT,OAAA,CAAAS,kCAAA,GAAAA,kCAAA;AAE5N,MAAMC,0DAA0D,GACrE,k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A,GAAAA,iDAAA;AACO,MAAMC,0CAA0C,GAAI;AAC3D;AACA;AACA;AACA,EAAE;AAACzB,OAAA,CAAAyB,0CAAA,GAAAA,0CAAA;AACI,MAAMC,qCAAqC,GAAI;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AAAC1B,OAAA,CAAA0B,qCAAA,GAAAA,qCAAA"}
1
+ {"version":3,"names":["finder","require","path","f","__dirname","pluginPackageRoot","next","filename","dirname","LOCAL_PATH_TO_RN_SDK","join","exports","LOCAL_PATH_TO_CIO_NSE_FILES","getRelativePathToRNSDK","currentFile","relative","IOS_DEPLOYMENT_TARGET","GROUP_IDENTIFIER_TEMPLATE_REGEX","BUNDLE_SHORT_VERSION_TEMPLATE_REGEX","BUNDLE_VERSION_TEMPLATE_REGEX","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_APPDELEGATEDECLARATION_REGEX","CIO_APPDELEGATEHEADER_REGEX","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_DEEPLINK_COMMENT_REGEX","DEFAULT_BUNDLE_VERSION","DEFAULT_BUNDLE_SHORT_VERSION","CIO_TARGET_NAME","CIO_NOTIFICATION_TARGET_NAME","CIO_APPDELEGATEHEADER_IMPORT_SNIPPET","CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET","CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","CIO_REGISTER_PUSHNOTIFICATION_SNIPPET"],"sources":["ios.ts"],"sourcesContent":["const finder = require('find-package-json');\nconst path = require('path');\n\nconst f = finder(__dirname);\nlet pluginPackageRoot = f.next().filename;\n// This is the path to the root of the customerio-expo-plugin package\npluginPackageRoot = path.dirname(pluginPackageRoot);\n\nexport const LOCAL_PATH_TO_RN_SDK = path.join(\n pluginPackageRoot,\n '../customerio-reactnative'\n)\n\nexport const LOCAL_PATH_TO_CIO_NSE_FILES = path.join(\n pluginPackageRoot,\n 'src/helpers/native-files/ios'\n);\n\nexport function getRelativePathToRNSDK(currentFile: string) {\n return path.relative(path.dirname(currentFile), LOCAL_PATH_TO_RN_SDK);\n}\n\nexport const IOS_DEPLOYMENT_TARGET = '13.0';\nexport const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;\nexport const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;\nexport const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;\nexport const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX =\n /.*\\[super(\\s)application:application(\\s)didFinishLaunchingWithOptions:launchOptions\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX =\n /return \\[super application:application didFailToRegisterForRemoteNotificationsWithError:error\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX =\n /(- \\(void\\)application:\\(UIApplication \\*\\)application didFailToRegisterForRemoteNotificationsWithError:\\(NSError \\*\\)error(\\s|\\n)*?\\{)(.|\\n){2}.*\\n\\}/;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX =\n /return \\[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\\];/;\n\nexport const CIO_APPDELEGATEDECLARATION_REGEX =\n /@implementation AppDelegate(.|\\n)/;\n\nexport const CIO_APPDELEGATEHEADER_REGEX =\n /(@interface AppDelegate\\s*:\\s*EXAppDelegateWrapper\\s*)(<([^>]+)>)?/;\n\nexport const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX = \n/^\\s*RCTBridge\\s*\\*\\s*\\w+\\s*=\\s*\\[\\s*self\\.reactDelegate\\s+createBridgeWithDelegate:self\\s+launchOptions:launchOptions\\s*\\];\\s*$/gm;\n\nexport const CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX = \n/^\\s*return\\s\\[\\s*super\\s*application:\\s*application\\s*didFinishLaunchingWithOptions\\s*:\\s*launchOptions\\s*\\];/gm;\n\nexport const CIO_DEEPLINK_COMMENT_REGEX = /\\sDeep link workaround for app killed state start/gm;\nexport const DEFAULT_BUNDLE_VERSION = '1';\nexport const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';\nexport const CIO_TARGET_NAME = 'CustomerIOSDK';\nexport const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';\n\nexport const CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = `#import <UserNotifications/UserNotifications.h>`;\nexport const CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = 'UNUserNotificationCenterDelegate';\nexport const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `\nCIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];\n`;\nexport const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = `\nRCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:modifiedLaunchOptions];\n`;\n\nexport const CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = `\nreturn [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];`\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `\n [super application:application didFailToRegisterForRemoteNotificationsWithError:error];\n [pnHandlerObj application:application error:error];\n`;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `\n [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\n return [pnHandlerObj application:application deviceToken:deviceToken];\n`;\n\nexport const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `\n // Register for push notifications\n [pnHandlerObj registerPushNotification];\n`;\n\nexport const CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = `\n UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];\n center.delegate = self;\n`;\n\nexport const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = `\n// Deep link workaround for app killed state start\nNSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];\n if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {\n NSDictionary *pushContent = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];\n if (pushContent[@\"CIO\"] && pushContent[@\"CIO\"][@\"push\"] && pushContent[@\"CIO\"][@\"push\"][@\"link\"]) {\n NSString *initialURL = pushContent[@\"CIO\"][@\"push\"][@\"link\"];\n if (!launchOptions[UIApplicationLaunchOptionsURLKey]) {\n modifiedLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];\n }\n }\n }\n//Deep link workaround for app killed state ends\n`;\n\n// Enable push handling - notification response\nexport const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = `\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {\n [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];\n}`;\n\n// Foreground push handling\nexport const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `\n// show push when the app is in foreground\n- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {\n completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);\n}`;\nexport const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `\n@objc(registerPushNotification)\n public func registerPushNotification() {\n\n let center = UNUserNotificationCenter.current()\n center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n if error == nil{\n DispatchQueue.main.async {\n UIApplication.shared.registerForRemoteNotifications()\n }\n }\n }\n }`;\n"],"mappings":";;;;;;;AAAA,MAAMA,MAAM,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAMC,IAAI,GAAGD,OAAO,CAAC,MAAM,CAAC;AAE5B,MAAME,CAAC,GAAGH,MAAM,CAACI,SAAS,CAAC;AAC3B,IAAIC,iBAAiB,GAAGF,CAAC,CAACG,IAAI,CAAC,CAAC,CAACC,QAAQ;AACzC;AACAF,iBAAiB,GAAGH,IAAI,CAACM,OAAO,CAACH,iBAAiB,CAAC;AAE5C,MAAMI,oBAAoB,GAAGP,IAAI,CAACQ,IAAI,CAC3CL,iBAAiB,EACjB,2BACF,CAAC;AAAAM,OAAA,CAAAF,oBAAA,GAAAA,oBAAA;AAEM,MAAMG,2BAA2B,GAAGV,IAAI,CAACQ,IAAI,CAClDL,iBAAiB,EACjB,8BACF,CAAC;AAACM,OAAA,CAAAC,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DAAiD,GAAI;AAClE;AACA;AACA,EAAE;;AAEF;AAAAhC,OAAA,CAAAgC,iDAAA,GAAAA,iDAAA;AACO,MAAMC,0CAA0C,GAAI;AAC3D;AACA;AACA;AACA,EAAE;AAACjC,OAAA,CAAAiC,0CAAA,GAAAA,0CAAA;AACI,MAAMC,qCAAqC,GAAI;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AAAClC,OAAA,CAAAkC,qCAAA,GAAAA,qCAAA"}
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.injectCodeBeforeMultiLineRegex = injectCodeBeforeMultiLineRegex;
6
7
  exports.injectCodeByLineNumber = injectCodeByLineNumber;
7
8
  exports.injectCodeByMultiLineRegex = injectCodeByMultiLineRegex;
8
9
  exports.injectCodeByMultiLineRegexAndReplaceLine = injectCodeByMultiLineRegexAndReplaceLine;
9
10
  exports.injectCodeByRegex = injectCodeByRegex;
11
+ exports.matchRegexExists = matchRegexExists;
10
12
  exports.replaceCodeByRegex = replaceCodeByRegex;
11
13
  function injectCodeByRegex(fileContent, lineRegex, snippet) {
12
14
  const lines = fileContent.split('\n');
@@ -20,9 +22,15 @@ function injectCodeByRegex(fileContent, lineRegex, snippet) {
20
22
  function injectCodeByMultiLineRegex(fileContent, lineRegex, snippet) {
21
23
  return fileContent.replace(lineRegex, `$&\n${snippet}`);
22
24
  }
25
+ function injectCodeBeforeMultiLineRegex(fileContent, lineRegex, snippet) {
26
+ return fileContent.replace(lineRegex, `${snippet}\n$&`);
27
+ }
23
28
  function replaceCodeByRegex(fileContent, lineRegex, snippet) {
24
29
  return fileContent.replace(lineRegex, snippet);
25
30
  }
31
+ function matchRegexExists(fileContent, regex) {
32
+ return regex.test(fileContent);
33
+ }
26
34
  function injectCodeByMultiLineRegexAndReplaceLine(fileContent, lineRegex, snippet) {
27
35
  return fileContent.replace(lineRegex, `${snippet}`);
28
36
  }
@@ -1 +1 @@
1
- {"version":3,"names":["injectCodeByRegex","fileContent","lineRegex","snippet","lines","split","index","findIndex","line","test","content","slice","injectCodeByMultiLineRegex","replace","replaceCodeByRegex","injectCodeByMultiLineRegexAndReplaceLine","injectCodeByLineNumber"],"sources":["codeInjection.ts"],"sourcesContent":["export function injectCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n const index = lines.findIndex((line) => lineRegex.test(line));\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n\nexport function injectCodeByMultiLineRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `$&\\n${snippet}`);\n}\n\nexport function replaceCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, snippet);\n}\n\nexport function injectCodeByMultiLineRegexAndReplaceLine(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `${snippet}`);\n}\n\nexport function injectCodeByLineNumber(\n fileContent: string,\n index: number,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n"],"mappings":";;;;;;;;;;AAAO,SAASA,iBAAiBA,CAC/BC,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,MAAMC,KAAK,GAAGF,KAAK,CAACG,SAAS,CAAEC,IAAI,IAAKN,SAAS,CAACO,IAAI,CAACD,IAAI,CAAC,CAAC;EAC7D,IAAIE,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB;AAEO,SAASE,0BAA0BA,CACxCX,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,OAAMC,OAAQ,EAAC,CAAC;AACzD;AAEO,SAASW,kBAAkBA,CAChCb,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAEC,OAAO,CAAC;AAChD;AAEO,SAASY,wCAAwCA,CACtDd,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,GAAEC,OAAQ,EAAC,CAAC;AACrD;AAEO,SAASa,sBAAsBA,CACpCf,WAAmB,EACnBK,KAAa,EACbH,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,IAAIK,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB"}
1
+ {"version":3,"names":["injectCodeByRegex","fileContent","lineRegex","snippet","lines","split","index","findIndex","line","test","content","slice","injectCodeByMultiLineRegex","replace","injectCodeBeforeMultiLineRegex","replaceCodeByRegex","matchRegexExists","regex","injectCodeByMultiLineRegexAndReplaceLine","injectCodeByLineNumber"],"sources":["codeInjection.ts"],"sourcesContent":["export function injectCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n const index = lines.findIndex((line) => lineRegex.test(line));\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n\nexport function injectCodeByMultiLineRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `$&\\n${snippet}`);\n}\n\nexport function injectCodeBeforeMultiLineRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `${snippet}\\n$&`);\n}\n\nexport function replaceCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, snippet);\n}\n\nexport function matchRegexExists(fileContent: string, regex: RegExp) {\n return regex.test(fileContent);\n}\nexport function injectCodeByMultiLineRegexAndReplaceLine(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `${snippet}`);\n}\n\nexport function injectCodeByLineNumber(\n fileContent: string,\n index: number,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n"],"mappings":";;;;;;;;;;;;AAAO,SAASA,iBAAiBA,CAC/BC,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,MAAMC,KAAK,GAAGF,KAAK,CAACG,SAAS,CAAEC,IAAI,IAAKN,SAAS,CAACO,IAAI,CAACD,IAAI,CAAC,CAAC;EAC7D,IAAIE,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB;AAEO,SAASE,0BAA0BA,CACxCX,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,OAAMC,OAAQ,EAAC,CAAC;AACzD;AAEO,SAASW,8BAA8BA,CAC5Cb,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,GAAEC,OAAQ,MAAK,CAAC;AACzD;AAEO,SAASY,kBAAkBA,CAChCd,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAEC,OAAO,CAAC;AAChD;AAEO,SAASa,gBAAgBA,CAACf,WAAmB,EAAEgB,KAAa,EAAE;EACnE,OAAOA,KAAK,CAACR,IAAI,CAACR,WAAW,CAAC;AAChC;AACO,SAASiB,wCAAwCA,CACtDjB,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,GAAEC,OAAQ,EAAC,CAAC;AACrD;AAEO,SAASgB,sBAAsBA,CACpClB,WAAmB,EACnBK,KAAa,EACbH,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,IAAIK,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB"}
@@ -32,7 +32,15 @@ const addNotificationHandlerDeclaration = stringContents => {
32
32
  return stringContents;
33
33
  };
34
34
  const addNotificationConfiguration = stringContents => {
35
- stringContents = (0, _codeInjection.injectCodeByMultiLineRegex)(stringContents, _ios.CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, _ios.CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET);
35
+ stringContents = (0, _codeInjection.injectCodeBeforeMultiLineRegex)(stringContents, _ios.CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, _ios.CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET);
36
+ return stringContents;
37
+ };
38
+ const addUserNotificationCenterConfiguration = stringContents => {
39
+ stringContents = (0, _codeInjection.injectCodeBeforeMultiLineRegex)(stringContents, _ios.CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, _ios.CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET);
40
+ return stringContents;
41
+ };
42
+ const addHandleDeeplinkInKilledStateConfiguration = (stringContents, regex) => {
43
+ stringContents = (0, _codeInjection.injectCodeBeforeMultiLineRegex)(stringContents, regex, _ios.CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET);
36
44
  return stringContents;
37
45
  };
38
46
  const addDidFailToRegisterForRemoteNotificationsWithError = stringContents => {
@@ -48,7 +56,45 @@ const addAdditionalMethodsForPushNotifications = stringContents => {
48
56
  return stringContents;
49
57
  };
50
58
  const addAppdelegateHeaderModification = stringContents => {
51
- stringContents = (0, _codeInjection.injectCodeByMultiLineRegexAndReplaceLine)(stringContents, _ios.CIO_APPDELEGATEHEADER_REGEX, _ios.CIO_APPDELEGATEHEADER_SNIPPET);
59
+ // Add UNUserNotificationCenterDelegate if needed
60
+ stringContents = stringContents.replace(_ios.CIO_APPDELEGATEHEADER_REGEX, (match, interfaceDeclaration, _groupedDelegates, existingDelegates) => {
61
+ if (existingDelegates && existingDelegates.includes(_ios.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET)) {
62
+ // The AppDelegate declaration already includes UNUserNotificationCenterDelegate, so we don't need to modify it
63
+ return match;
64
+ } else if (existingDelegates) {
65
+ // Other delegates exist, append ours
66
+ return `${_ios.CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}
67
+ ${interfaceDeclaration}<${existingDelegates}, ${_ios.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>
68
+ `;
69
+ } else {
70
+ // No delegates exist, add ours
71
+ return `${_ios.CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}
72
+ ${interfaceDeclaration.trim()} <${_ios.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>
73
+ `;
74
+ }
75
+ });
76
+ return stringContents;
77
+ };
78
+ const addHandleDeeplinkInKilledState = stringContents => {
79
+ // Find if the deep link code snippet is already present
80
+ if ((0, _codeInjection.matchRegexExists)(stringContents, _ios.CIO_DEEPLINK_COMMENT_REGEX)) {
81
+ return stringContents;
82
+ }
83
+
84
+ // Check if the app delegate is using RCTBridge or LaunchOptions
85
+ var snippet = undefined;
86
+ var regex = _ios.CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;
87
+ if ((0, _codeInjection.matchRegexExists)(stringContents, _ios.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
88
+ snippet = _ios.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;
89
+ regex = _ios.CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;
90
+ } else if ((0, _codeInjection.matchRegexExists)(stringContents, _ios.CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
91
+ snippet = _ios.CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET;
92
+ }
93
+ // Add code only if the app delegate is using RCTBridge or LaunchOptions
94
+ if (snippet !== undefined) {
95
+ stringContents = addHandleDeeplinkInKilledStateConfiguration(stringContents, regex);
96
+ stringContents = (0, _codeInjection.replaceCodeByRegex)(stringContents, regex, snippet);
97
+ }
52
98
  return stringContents;
53
99
  };
54
100
  const withAppDelegateModifications = (configOuter, props) => {
@@ -68,6 +114,12 @@ const withAppDelegateModifications = (configOuter, props) => {
68
114
  if (props.disableNotificationRegistration !== undefined && props.disableNotificationRegistration === false) {
69
115
  stringContents = addNotificationConfiguration(stringContents);
70
116
  }
117
+ if (props.handleNotificationClick === undefined || props.handleNotificationClick === true) {
118
+ stringContents = addUserNotificationCenterConfiguration(stringContents);
119
+ }
120
+ if (props.handleDeeplinkInKilledState !== undefined && props.handleDeeplinkInKilledState === true) {
121
+ stringContents = addHandleDeeplinkInKilledState(stringContents);
122
+ }
71
123
  stringContents = addAdditionalMethodsForPushNotifications(stringContents);
72
124
  stringContents = addDidFailToRegisterForRemoteNotificationsWithError(stringContents);
73
125
  stringContents = addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);
@@ -1 +1 @@
1
- {"version":3,"names":["_configPlugins","require","_Paths","_ios","_codeInjection","_fileManagement","pushCodeSnippets","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","additionalMethodsForPushNotifications","join","addImport","stringContents","appName","importRegex","addedImport","getImportSnippet","match","endOfMatchIndex","index","undefined","length","injectCodeByLineNumber","addNotificationHandlerDeclaration","injectCodeByMultiLineRegex","CIO_APPDELEGATEDECLARATION_REGEX","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","addNotificationConfiguration","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","addDidFailToRegisterForRemoteNotificationsWithError","injectCodeByMultiLineRegexAndReplaceLine","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","addDidRegisterForRemoteNotificationsWithDeviceToken","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","addAdditionalMethodsForPushNotifications","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","addAppdelegateHeaderModification","CIO_APPDELEGATEHEADER_REGEX","CIO_APPDELEGATEHEADER_SNIPPET","withAppDelegateModifications","configOuter","props","withAppDelegate","config","modResults","contents","regex","RegExp","modRequest","projectName","headerPath","getAppDelegateHeaderFilePath","projectRoot","headerContent","FileManagement","read","write","disableNotificationRegistration","console","log","exports"],"sources":["withAppDelegateModifications.ts"],"sourcesContent":["import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';\nimport { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Paths';\n\nimport {\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_APPDELEGATEHEADER_REGEX,\n CIO_APPDELEGATEHEADER_SNIPPET,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n} from '../helpers/constants/ios';\nimport {\n injectCodeByLineNumber,\n injectCodeByMultiLineRegex,\n injectCodeByMultiLineRegexAndReplaceLine,\n} from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport type { CustomerIOPluginOptionsIOS } from '../types/cio-types';\n\nconst pushCodeSnippets = [\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n];\n\nconst additionalMethodsForPushNotifications = `${pushCodeSnippets.join(\n '\\n'\n)}\\n`; // Join newlines and ensure a newline at the end.\n\nconst addImport = (stringContents: string, appName: string) => {\n const importRegex = /^(#import .*)\\n/gm;\n const addedImport = getImportSnippet(appName);\n\n const match = stringContents.match(importRegex);\n let endOfMatchIndex: number;\n if (!match || match.index === undefined) {\n // No imports found, just add to start of file:\n endOfMatchIndex = 0;\n } else {\n // Add after first import:\n endOfMatchIndex = match.index + match[0].length;\n }\n\n stringContents = injectCodeByLineNumber(\n stringContents,\n endOfMatchIndex,\n addedImport\n ).join('\\n');\n\n return stringContents;\n};\n\nconst addNotificationHandlerDeclaration = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addNotificationConfiguration = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidFailToRegisterForRemoteNotificationsWithError = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidRegisterForRemoteNotificationsWithDeviceToken = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addAdditionalMethodsForPushNotifications = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n additionalMethodsForPushNotifications\n );\n\n return stringContents;\n};\n\nconst addAppdelegateHeaderModification = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_APPDELEGATEHEADER_REGEX,\n CIO_APPDELEGATEHEADER_SNIPPET\n );\n\n return stringContents;\n};\n\nexport const withAppDelegateModifications: ConfigPlugin<\n CustomerIOPluginOptionsIOS\n> = (configOuter, props) => {\n return withAppDelegate(configOuter, async (config) => {\n let stringContents = config.modResults.contents;\n const regex = new RegExp(\n `#import <${config.modRequest.projectName}-Swift.h>`\n );\n const match = stringContents.match(regex);\n\n if (!match) {\n const headerPath = getAppDelegateHeaderFilePath(\n config.modRequest.projectRoot\n );\n let headerContent = await FileManagement.read(headerPath);\n headerContent = addAppdelegateHeaderModification(headerContent);\n FileManagement.write(headerPath, headerContent);\n\n stringContents = addImport(\n stringContents,\n config.modRequest.projectName as string\n );\n stringContents = addNotificationHandlerDeclaration(stringContents);\n\n // any other value would be treated as true, it has to be explicitly false to disable\n if (\n props.disableNotificationRegistration !== undefined &&\n props.disableNotificationRegistration === false\n ) {\n stringContents = addNotificationConfiguration(stringContents);\n }\n stringContents = addAdditionalMethodsForPushNotifications(stringContents);\n stringContents =\n addDidFailToRegisterForRemoteNotificationsWithError(stringContents);\n stringContents =\n addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);\n\n config.modResults.contents = stringContents;\n } else {\n console.log('Customerio AppDelegate changes already exist. Skipping...');\n }\n\n return config;\n });\n};\nfunction getImportSnippet(appName: string) {\n return `\n// Add swift bridge imports\n#import <Ex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GjB,gCAAgC,CAACiB,aAAa,CAAC;MAC/DC,8BAAc,CAACE,KAAK,CAACN,UAAU,EAAEG,aAAa,CAAC;MAE/C5C,cAAc,GAAGD,SAAS,CACxBC,cAAc,EACdkC,MAAM,CAACK,UAAU,CAACC,WACpB,CAAC;MACDxC,cAAc,GAAGW,iCAAiC,CAACX,cAAc,CAAC;;MAElE;MACA,IACEgC,KAAK,CAACgB,+BAA+B,KAAKxC,SAAS,IACnDwB,KAAK,CAACgB,+BAA+B,KAAK,KAAK,EAC/C;QACAhD,cAAc,GAAGe,4BAA4B,CAACf,cAAc,CAAC;MAC/D;MACAA,cAAc,GAAGyB,wCAAwC,CAACzB,cAAc,CAAC;MACzEA,cAAc,GACZkB,mDAAmD,CAAClB,cAAc,CAAC;MACrEA,cAAc,GACZsB,mDAAmD,CAACtB,cAAc,CAAC;MAErEkC,MAAM,CAACC,UAAU,CAACC,QAAQ,GAAGpC,cAAc;IAC7C,CAAC,MAAM;MACLiD,OAAO,CAACC,GAAG,CAAC,2DAA2D,CAAC;IAC1E;IAEA,OAAOhB,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AAACiB,OAAA,CAAArB,4BAAA,GAAAA,4BAAA;AACF,SAAS1B,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAQ;AACV;AACA;AACA,WAAWA,OAAQ;AACnB,GAAG;AACH"}
1
+ {"version":3,"names":["_configPlugins","require","_Paths","_ios","_codeInjection","_fileManagement","pushCodeSnippets","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","additionalMethodsForPushNotifications","join","addImport","stringContents","appName","importRegex","addedImport","getImportSnippet","match","endOfMatchIndex","index","undefined","length","injectCodeByLineNumber","addNotificationHandlerDeclaration","injectCodeByMultiLineRegex","CIO_APPDELEGATEDECLARATION_REGEX","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","addNotificationConfiguration","injectCodeBeforeMultiLineRegex","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","addUserNotificationCenterConfiguration","CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET","addHandleDeeplinkInKilledStateConfiguration","regex","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","addDidFailToRegisterForRemoteNotificationsWithError","injectCodeByMultiLineRegexAndReplaceLine","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","addDidRegisterForRemoteNotificationsWithDeviceToken","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","addAdditionalMethodsForPushNotifications","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","addAppdelegateHeaderModification","replace","CIO_APPDELEGATEHEADER_REGEX","interfaceDeclaration","_groupedDelegates","existingDelegates","includes","CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET","CIO_APPDELEGATEHEADER_IMPORT_SNIPPET","trim","addHandleDeeplinkInKilledState","matchRegexExists","CIO_DEEPLINK_COMMENT_REGEX","snippet","CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET","CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET","replaceCodeByRegex","withAppDelegateModifications","configOuter","props","withAppDelegate","config","modResults","contents","RegExp","modRequest","projectName","headerPath","getAppDelegateHeaderFilePath","projectRoot","headerContent","FileManagement","read","write","disableNotificationRegistration","handleNotificationClick","handleDeeplinkInKilledState","console","log","exports"],"sources":["withAppDelegateModifications.ts"],"sourcesContent":["import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';\nimport { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Paths';\n\nimport {\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_APPDELEGATEHEADER_IMPORT_SNIPPET,\n CIO_APPDELEGATEHEADER_REGEX,\n CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET,\n CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET,\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,\n CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET,\n CIO_DEEPLINK_COMMENT_REGEX,\n} from '../helpers/constants/ios';\nimport {\n injectCodeBeforeMultiLineRegex,\n injectCodeByLineNumber,\n injectCodeByMultiLineRegex,\n injectCodeByMultiLineRegexAndReplaceLine,\n replaceCodeByRegex,\n matchRegexExists\n} from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport type { CustomerIOPluginOptionsIOS } from '../types/cio-types';\n\nconst pushCodeSnippets = [\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n];\n\nconst additionalMethodsForPushNotifications = `${pushCodeSnippets.join(\n '\\n'\n)}\\n`; // Join newlines and ensure a newline at the end.\n\nconst addImport = (stringContents: string, appName: string) => {\n const importRegex = /^(#import .*)\\n/gm;\n const addedImport = getImportSnippet(appName);\n\n const match = stringContents.match(importRegex);\n let endOfMatchIndex: number;\n if (!match || match.index === undefined) {\n // No imports found, just add to start of file:\n endOfMatchIndex = 0;\n } else {\n // Add after first import:\n endOfMatchIndex = match.index + match[0].length;\n }\n\n stringContents = injectCodeByLineNumber(\n stringContents,\n endOfMatchIndex,\n addedImport\n ).join('\\n');\n\n return stringContents;\n};\n\nconst addNotificationHandlerDeclaration = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addNotificationConfiguration = (stringContents: string) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addUserNotificationCenterConfiguration = (stringContents: string) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addHandleDeeplinkInKilledStateConfiguration = (stringContents: string, regex: RegExp) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n regex,\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidFailToRegisterForRemoteNotificationsWithError = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidRegisterForRemoteNotificationsWithDeviceToken = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addAdditionalMethodsForPushNotifications = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n additionalMethodsForPushNotifications\n );\n\n return stringContents;\n};\n\nconst addAppdelegateHeaderModification = (stringContents: string) => {\n // Add UNUserNotificationCenterDelegate if needed\n stringContents = stringContents.replace(\n CIO_APPDELEGATEHEADER_REGEX,\n (match, interfaceDeclaration, _groupedDelegates, existingDelegates) => {\n if (existingDelegates && existingDelegates.includes(CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET)) {\n // The AppDelegate declaration already includes UNUserNotificationCenterDelegate, so we don't need to modify it\n return match;\n } else if (existingDelegates) {\n // Other delegates exist, append ours\n return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}\n${interfaceDeclaration}<${existingDelegates}, ${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>\n`;\n } else {\n // No delegates exist, add ours\n return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}\n${interfaceDeclaration.trim()} <${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>\n`;\n }\n }\n );\n\n return stringContents;\n};\n\nconst addHandleDeeplinkInKilledState = (stringContents: string) => {\n // Find if the deep link code snippet is already present\n if (matchRegexExists(stringContents, CIO_DEEPLINK_COMMENT_REGEX)) {\n return stringContents\n }\n\n // Check if the app delegate is using RCTBridge or LaunchOptions\n var snippet = undefined\n var regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n if (matchRegexExists(stringContents, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {\n snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;\n regex = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n }\n else if (matchRegexExists(stringContents, CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {\n snippet = CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET;\n }\n // Add code only if the app delegate is using RCTBridge or LaunchOptions\n if (snippet !== undefined) {\n stringContents = addHandleDeeplinkInKilledStateConfiguration(stringContents, regex);\n stringContents = replaceCodeByRegex(stringContents, regex, snippet);\n }\n return stringContents\n}\n\nexport const withAppDelegateModifications: ConfigPlugin<\n CustomerIOPluginOptionsIOS\n> = (configOuter, props) => {\n return withAppDelegate(configOuter, async (config) => {\n let stringContents = config.modResults.contents;\n const regex = new RegExp(\n `#import <${config.modRequest.projectName}-Swift.h>`\n );\n const match = stringContents.match(regex);\n\n if (!match) {\n const headerPath = getAppDelegateHeaderFilePath(\n config.modRequest.projectRoot\n );\n let headerContent = await FileManagement.read(headerPath);\n headerContent = addAppdelegateHeaderModification(headerContent);\n FileManagement.write(headerPath, headerContent);\n\n stringContents = addImport(\n stringContents,\n config.modRequest.projectName as string\n );\n stringContents = addNotificationHandlerDeclaration(stringContents);\n\n // any other value would be treated as true, it has to be explicitly false to disable\n if (\n props.disableNotificationRegistration !== undefined &&\n props.disableNotificationRegistration === false\n ) {\n stringContents = addNotificationConfiguration(stringContents);\n }\n if (\n props.handleNotificationClick === undefined ||\n props.handleNotificationClick === true\n ) {\n stringContents = addUserNotificationCenterConfiguration(stringContents);\n }\n\n if (\n props.handleDeeplinkInKilledState !== undefined &&\n props.handleDeeplinkInKilledState === true\n ) {\n stringContents = addHandleDeeplinkInKilledState(stringContents);\n }\n \n stringContents = addAdditionalMethodsForPushNotifications(stringContents);\n stringContents =\n addDidFailToRegisterForRemoteNotificationsWithError(stringContents);\n stringContents =\n addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);\n\n config.modResults.contents = stringContents;\n } else {\n console.log('Customerio AppDelegate changes already exist. Skipping...');\n }\n\n return config;\n });\n};\nfunction getImportSnippet(appName: string) {\n return `\n// Add swift bridge imports\n#import <ExpoModulesCore-Swift.h>\n#import <${appName}-Swift.h>\n `;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,IAAA,GAAAF,OAAA;AAuBA,IAAAG,cAAA,GAAAH,OAAA;AAQA,IAAAI,eAAA,GAAAJ,OAAA;AAGA,MAAMK,gBAAgB,GAAG,CACvBC,sDAAiD,EACjDC,+CAA0C,CAC3C;AAED,MAAMC,qCAAqC,GAAI,GAAEH,gBAAgB,CAACI,IAAI,CACpE,IACF,CAAE,IAAG,CAAC,CAAC;;AAEP,MAAMC,SAAS,GAAGA,CAACC,cAAsB,EAAEC,OAAe,KAAK;EAC7D,MAAMC,WAAW,GAAG,mBAAmB;EACvC,MAAMC,WAAW,GAAGC,gBAAgB,CAACH,OAAO,CAAC;EAE7C,MAAMI,KAAK,GAAGL,cAAc,CAACK,KAAK,CAACH,WAAW,CAAC;EAC/C,IAAII,eAAuB;EAC3B,IAAI,CAACD,KAAK,IAAIA,KAAK,CAACE,KAAK,KAA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B,KAAK9D,SAAS,IAC3C8C,KAAK,CAACgB,uBAAuB,KAAK,IAAI,EACtC;QACAtE,cAAc,GAAGmB,sCAAsC,CAACnB,cAAc,CAAC;MACzE;MAEA,IACEsD,KAAK,CAACiB,2BAA2B,KAAK/D,SAAS,IAC/C8C,KAAK,CAACiB,2BAA2B,KAAK,IAAI,EAC1C;QACAvE,cAAc,GAAG2C,8BAA8B,CAAC3C,cAAc,CAAC;MACjE;MAEAA,cAAc,GAAG+B,wCAAwC,CAAC/B,cAAc,CAAC;MACzEA,cAAc,GACZwB,mDAAmD,CAACxB,cAAc,CAAC;MACrEA,cAAc,GACZ4B,mDAAmD,CAAC5B,cAAc,CAAC;MAErEwD,MAAM,CAACC,UAAU,CAACC,QAAQ,GAAG1D,cAAc;IAC7C,CAAC,MAAM;MACLwE,OAAO,CAACC,GAAG,CAAC,2DAA2D,CAAC;IAC1E;IAEA,OAAOjB,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AAACkB,OAAA,CAAAtB,4BAAA,GAAAA,4BAAA;AACF,SAAShD,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAQ;AACV;AACA;AACA,WAAWA,OAAQ;AACnB,GAAG;AACH"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["cio-types.ts"],"sourcesContent":["// properties set by the user in their app config file (e.g: app.json or app.plugin.js)\nexport type CustomerIOPluginProperties = {\n // (iOS only) Environment name and bundle identifier\n devTeam: string;\n iosDeploymentTarget: string;\n};\n\n// Plugin options for pre-build\nexport type CustomerIOPluginOptionsIOS = {\n iosPath: string;\n devTeam?: string;\n bundleVersion?: string;\n bundleShortVersion?: string;\n bundleIdentifier?: string;\n iosDeploymentTarget?: string;\n appleTeamId?: string;\n appName?: string;\n disableNotificationRegistration?: boolean;\n useFrameworks?: 'static' | 'dynamic';\n pushNotification?: {\n useRichPush: boolean;\n env: {\n siteId: string;\n apiKey: string;\n region: string;\n };\n };\n};\n\nexport type CustomerIOPluginOptionsAndroid = {\n androidPath: string;\n googleServicesFile?: string;\n setHighPriorityPushHandler?: boolean;\n};\n\nexport type CustomerIOPluginOptions = {\n android: CustomerIOPluginOptionsAndroid;\n ios: CustomerIOPluginOptionsIOS;\n};\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["cio-types.ts"],"sourcesContent":["// properties set by the user in their app config file (e.g: app.json or app.plugin.js)\nexport type CustomerIOPluginProperties = {\n // (iOS only) Environment name and bundle identifier\n devTeam: string;\n iosDeploymentTarget: string;\n};\n\n// Plugin options for pre-build\nexport type CustomerIOPluginOptionsIOS = {\n iosPath: string;\n devTeam?: string;\n bundleVersion?: string;\n bundleShortVersion?: string;\n bundleIdentifier?: string;\n iosDeploymentTarget?: string;\n appleTeamId?: string;\n appName?: string;\n disableNotificationRegistration?: boolean;\n handleNotificationClick?:boolean;\n handleDeeplinkInKilledState?:boolean;\n useFrameworks?: 'static' | 'dynamic';\n pushNotification?: {\n useRichPush: boolean;\n env: {\n siteId: string;\n apiKey: string;\n region: string;\n };\n };\n};\n\nexport type CustomerIOPluginOptionsAndroid = {\n androidPath: string;\n googleServicesFile?: string;\n setHighPriorityPushHandler?: boolean;\n};\n\nexport type CustomerIOPluginOptions = {\n android: CustomerIOPluginOptionsAndroid;\n ios: CustomerIOPluginOptionsIOS;\n};\n"],"mappings":""}
@@ -13,24 +13,29 @@ export const IOS_DEPLOYMENT_TARGET = '13.0';
13
13
  export const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;
14
14
  export const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;
15
15
  export const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;
16
- export const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = /(- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions(\s|\n)*?\{)((.|\n)*)\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
16
+ export const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX = /.*\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
17
17
  export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX = /return \[super application:application didFailToRegisterForRemoteNotificationsWithError:error\];/;
18
18
  export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX = /(- \(void\)application:\(UIApplication \*\)application didFailToRegisterForRemoteNotificationsWithError:\(NSError \*\)error(\s|\n)*?\{)(.|\n){2}.*\n\}/;
19
19
  export const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX = /return \[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\];/;
20
20
  export const CIO_APPDELEGATEDECLARATION_REGEX = /@implementation AppDelegate(.|\n)/;
21
- export const CIO_APPDELEGATEHEADER_REGEX = /@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>/;
21
+ export const CIO_APPDELEGATEHEADER_REGEX = /(@interface AppDelegate\s*:\s*EXAppDelegateWrapper\s*)(<([^>]+)>)?/;
22
+ export const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX = /^\s*RCTBridge\s*\*\s*\w+\s*=\s*\[\s*self\.reactDelegate\s+createBridgeWithDelegate:self\s+launchOptions:launchOptions\s*\];\s*$/gm;
23
+ export const CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX = /^\s*return\s\[\s*super\s*application:\s*application\s*didFinishLaunchingWithOptions\s*:\s*launchOptions\s*\];/gm;
24
+ export const CIO_DEEPLINK_COMMENT_REGEX = /\sDeep link workaround for app killed state start/gm;
22
25
  export const DEFAULT_BUNDLE_VERSION = '1';
23
26
  export const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
24
27
  export const CIO_TARGET_NAME = 'CustomerIOSDK';
25
28
  export const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';
26
- export const CIO_APPDELEGATEHEADER_SNIPPET = `
27
- #import <UserNotifications/UserNotifications.h>
28
-
29
- @interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>
30
- `;
29
+ export const CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = `#import <UserNotifications/UserNotifications.h>`;
30
+ export const CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = 'UNUserNotificationCenterDelegate';
31
31
  export const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `
32
32
  CIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];
33
33
  `;
34
+ export const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = `
35
+ RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:modifiedLaunchOptions];
36
+ `;
37
+ export const CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = `
38
+ return [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];`;
34
39
  export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `
35
40
  [super application:application didFailToRegisterForRemoteNotificationsWithError:error];
36
41
  [pnHandlerObj application:application error:error];
@@ -41,7 +46,25 @@ export const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `
41
46
  `;
42
47
  export const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `
43
48
  // Register for push notifications
44
- [pnHandlerObj registerPushNotification:self];
49
+ [pnHandlerObj registerPushNotification];
50
+ `;
51
+ export const CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = `
52
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
53
+ center.delegate = self;
54
+ `;
55
+ export const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = `
56
+ // Deep link workaround for app killed state start
57
+ NSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];
58
+ if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
59
+ NSDictionary *pushContent = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
60
+ if (pushContent[@"CIO"] && pushContent[@"CIO"][@"push"] && pushContent[@"CIO"][@"push"][@"link"]) {
61
+ NSString *initialURL = pushContent[@"CIO"][@"push"][@"link"];
62
+ if (!launchOptions[UIApplicationLaunchOptionsURLKey]) {
63
+ modifiedLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];
64
+ }
65
+ }
66
+ }
67
+ //Deep link workaround for app killed state ends
45
68
  `;
46
69
 
47
70
  // Enable push handling - notification response
@@ -57,11 +80,10 @@ export const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `
57
80
  completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);
58
81
  }`;
59
82
  export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
60
- @objc(registerPushNotification:)
61
- public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {
83
+ @objc(registerPushNotification)
84
+ public func registerPushNotification() {
62
85
 
63
86
  let center = UNUserNotificationCenter.current()
64
- center.delegate = notificationDelegate
65
87
  center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
66
88
  if error == nil{
67
89
  DispatchQueue.main.async {
@@ -1 +1 @@
1
- {"version":3,"names":["finder","require","path","f","__dirname","pluginPackageRoot","next","filename","dirname","LOCAL_PATH_TO_RN_SDK","join","LOCAL_PATH_TO_CIO_NSE_FILES","getRelativePathToRNSDK","currentFile","relative","IOS_DEPLOYMENT_TARGET","GROUP_IDENTIFIER_TEMPLATE_REGEX","BUNDLE_SHORT_VERSION_TEMPLATE_REGEX","BUNDLE_VERSION_TEMPLATE_REGEX","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_APPDELEGATEDECLARATION_REGEX","CIO_APPDELEGATEHEADER_REGEX","DEFAULT_BUNDLE_VERSION","DEFAULT_BUNDLE_SHORT_VERSION","CIO_TARGET_NAME","CIO_NOTIFICATION_TARGET_NAME","CIO_APPDELEGATEHEADER_SNIPPET","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","CIO_REGISTER_PUSHNOTIFICATION_SNIPPET"],"sources":["ios.ts"],"sourcesContent":["const finder = require('find-package-json');\nconst path = require('path');\n\nconst f = finder(__dirname);\nlet pluginPackageRoot = f.next().filename;\n// This is the path to the root of the customerio-expo-plugin package\npluginPackageRoot = path.dirname(pluginPackageRoot);\n\nexport const LOCAL_PATH_TO_RN_SDK = path.join(\n pluginPackageRoot,\n '../customerio-reactnative'\n)\n\nexport const LOCAL_PATH_TO_CIO_NSE_FILES = path.join(\n pluginPackageRoot,\n 'src/helpers/native-files/ios'\n);\n\nexport function getRelativePathToRNSDK(currentFile: string) {\n return path.relative(path.dirname(currentFile), LOCAL_PATH_TO_RN_SDK);\n}\n\nexport const IOS_DEPLOYMENT_TARGET = '13.0';\nexport const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;\nexport const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;\nexport const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;\nexport const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX =\n /(- \\(BOOL\\)application:\\(UIApplication \\*\\)application didFinishLaunchingWithOptions:\\(NSDictionary \\*\\)launchOptions(\\s|\\n)*?\\{)((.|\\n)*)\\[super(\\s)application:application(\\s)didFinishLaunchingWithOptions:launchOptions\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX =\n /return \\[super application:application didFailToRegisterForRemoteNotificationsWithError:error\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX =\n /(- \\(void\\)application:\\(UIApplication \\*\\)application didFailToRegisterForRemoteNotificationsWithError:\\(NSError \\*\\)error(\\s|\\n)*?\\{)(.|\\n){2}.*\\n\\}/;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX =\n /return \\[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\\];/;\n\nexport const CIO_APPDELEGATEDECLARATION_REGEX =\n /@implementation AppDelegate(.|\\n)/;\n\nexport const CIO_APPDELEGATEHEADER_REGEX =\n /@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>/;\nexport const DEFAULT_BUNDLE_VERSION = '1';\nexport const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';\nexport const CIO_TARGET_NAME = 'CustomerIOSDK';\nexport const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';\nexport const CIO_APPDELEGATEHEADER_SNIPPET = `\n#import <UserNotifications/UserNotifications.h>\n\n@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>\n`;\n\nexport const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `\nCIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];\n`;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `\n [super application:application didFailToRegisterForRemoteNotificationsWithError:error];\n [pnHandlerObj application:application error:error];\n`;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `\n [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\n return [pnHandlerObj application:application deviceToken:deviceToken];\n`;\n\nexport const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `\n // Register for push notifications\n [pnHandlerObj registerPushNotification:self];\n`;\n\n// Enable push handling - notification response\nexport const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = `\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {\n [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];\n}`;\n\n// Foreground push handling\nexport const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `\n// show push when the app is in foreground\n- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {\n completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);\n}`;\nexport const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `\n@objc(registerPushNotification:)\n public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {\n\n let center = UNUserNotificationCenter.current()\n center.delegate = notificationDelegate\n center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n if error == nil{\n DispatchQueue.main.async {\n UIApplication.shared.registerForRemoteNotifications()\n }\n }\n }\n }`;\n"],"mappings":"AAAA,MAAMA,MAAM,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAMC,IAAI,GAAGD,OAAO,C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AC;AAED,OAAO,MAAMC,4DAA4D,GAAI;AAC7E;AACA;AACA,CAAC;AAED,OAAO,MAAMC,4DAA4D,GAAI;AAC7E;AACA;AACA,CAAC;AAED,OAAO,MAAMC,2CAA2C,GAAI;AAC5D;AACA;AACA,CAAC;;AAED;AACA,OAAO,MAAMC,iDAAiD,GAAI;AAClE;AACA;AACA,EAAE;;AAEF;AACA,OAAO,MAAMC,0CAA0C,GAAI;AAC3D;AACA;AACA;AACA,EAAE;AACF,OAAO,MAAMC,qCAAqC,GAAI;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI"}
1
+ {"version":3,"names":["finder","require","path","f","__dirname","pluginPackageRoot","next","filename","dirname","LOCAL_PATH_TO_RN_SDK","join","LOCAL_PATH_TO_CIO_NSE_FILES","getRelativePathToRNSDK","currentFile","relative","IOS_DEPLOYMENT_TARGET","GROUP_IDENTIFIER_TEMPLATE_REGEX","BUNDLE_SHORT_VERSION_TEMPLATE_REGEX","BUNDLE_VERSION_TEMPLATE_REGEX","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_APPDELEGATEDECLARATION_REGEX","CIO_APPDELEGATEHEADER_REGEX","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_DEEPLINK_COMMENT_REGEX","DEFAULT_BUNDLE_VERSION","DEFAULT_BUNDLE_SHORT_VERSION","CIO_TARGET_NAME","CIO_NOTIFICATION_TARGET_NAME","CIO_APPDELEGATEHEADER_IMPORT_SNIPPET","CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET","CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","CIO_REGISTER_PUSHNOTIFICATION_SNIPPET"],"sources":["ios.ts"],"sourcesContent":["const finder = require('find-package-json');\nconst path = require('path');\n\nconst f = finder(__dirname);\nlet pluginPackageRoot = f.next().filename;\n// This is the path to the root of the customerio-expo-plugin package\npluginPackageRoot = path.dirname(pluginPackageRoot);\n\nexport const LOCAL_PATH_TO_RN_SDK = path.join(\n pluginPackageRoot,\n '../customerio-reactnative'\n)\n\nexport const LOCAL_PATH_TO_CIO_NSE_FILES = path.join(\n pluginPackageRoot,\n 'src/helpers/native-files/ios'\n);\n\nexport function getRelativePathToRNSDK(currentFile: string) {\n return path.relative(path.dirname(currentFile), LOCAL_PATH_TO_RN_SDK);\n}\n\nexport const IOS_DEPLOYMENT_TARGET = '13.0';\nexport const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;\nexport const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;\nexport const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;\nexport const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX =\n /.*\\[super(\\s)application:application(\\s)didFinishLaunchingWithOptions:launchOptions\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX =\n /return \\[super application:application didFailToRegisterForRemoteNotificationsWithError:error\\];/;\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX =\n /(- \\(void\\)application:\\(UIApplication \\*\\)application didFailToRegisterForRemoteNotificationsWithError:\\(NSError \\*\\)error(\\s|\\n)*?\\{)(.|\\n){2}.*\\n\\}/;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX =\n /return \\[super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken\\];/;\n\nexport const CIO_APPDELEGATEDECLARATION_REGEX =\n /@implementation AppDelegate(.|\\n)/;\n\nexport const CIO_APPDELEGATEHEADER_REGEX =\n /(@interface AppDelegate\\s*:\\s*EXAppDelegateWrapper\\s*)(<([^>]+)>)?/;\n\nexport const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX = \n/^\\s*RCTBridge\\s*\\*\\s*\\w+\\s*=\\s*\\[\\s*self\\.reactDelegate\\s+createBridgeWithDelegate:self\\s+launchOptions:launchOptions\\s*\\];\\s*$/gm;\n\nexport const CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX = \n/^\\s*return\\s\\[\\s*super\\s*application:\\s*application\\s*didFinishLaunchingWithOptions\\s*:\\s*launchOptions\\s*\\];/gm;\n\nexport const CIO_DEEPLINK_COMMENT_REGEX = /\\sDeep link workaround for app killed state start/gm;\nexport const DEFAULT_BUNDLE_VERSION = '1';\nexport const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';\nexport const CIO_TARGET_NAME = 'CustomerIOSDK';\nexport const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';\n\nexport const CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = `#import <UserNotifications/UserNotifications.h>`;\nexport const CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = 'UNUserNotificationCenterDelegate';\nexport const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `\nCIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];\n`;\nexport const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = `\nRCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:modifiedLaunchOptions];\n`;\n\nexport const CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = `\nreturn [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];`\n\nexport const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `\n [super application:application didFailToRegisterForRemoteNotificationsWithError:error];\n [pnHandlerObj application:application error:error];\n`;\n\nexport const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `\n [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\n return [pnHandlerObj application:application deviceToken:deviceToken];\n`;\n\nexport const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `\n // Register for push notifications\n [pnHandlerObj registerPushNotification];\n`;\n\nexport const CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = `\n UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];\n center.delegate = self;\n`;\n\nexport const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = `\n// Deep link workaround for app killed state start\nNSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];\n if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {\n NSDictionary *pushContent = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];\n if (pushContent[@\"CIO\"] && pushContent[@\"CIO\"][@\"push\"] && pushContent[@\"CIO\"][@\"push\"][@\"link\"]) {\n NSString *initialURL = pushContent[@\"CIO\"][@\"push\"][@\"link\"];\n if (!launchOptions[UIApplicationLaunchOptionsURLKey]) {\n modifiedLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];\n }\n }\n }\n//Deep link workaround for app killed state ends\n`;\n\n// Enable push handling - notification response\nexport const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = `\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {\n [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];\n}`;\n\n// Foreground push handling\nexport const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `\n// show push when the app is in foreground\n- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {\n completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);\n}`;\nexport const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `\n@objc(registerPushNotification)\n public func registerPushNotification() {\n\n let center = UNUserNotificationCenter.current()\n center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n if error == nil{\n DispatchQueue.main.async {\n UIApplication.shared.registerForRemoteNotifications()\n }\n }\n }\n }`;\n"],"mappings":"AAAA,MAAMA,MAAM,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAMC,IAAI,GAAGD,OAAO,CAAC,MAAM,CAAC;AAE5B,MAAME,CAAC,GAAGH,MAAM,CAACI,SAAS,CAAC;AAC3B,IAAIC,iBAAiB,GAAGF,CAAC,CAACG,IAAI,CAAC,CAAC,CAACC,QAAQ;AACzC;AACAF,iBAAiB,GAAGH,IAAI,CAACM,OAAO,CAACH,iBAAiB,CAAC;AAEnD,OAAO,MAAMI,oBAAoB,GAAGP,IAAI,CAACQ,IAAI,CAC3CL,iBAAiB,EACjB,2BACF,CAAC;AAED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E;AACA;AACA,CAAC;AAED,OAAO,MAAMC,4DAA4D,GAAI;AAC7E;AACA;AACA,CAAC;AAED,OAAO,MAAMC,2CAA2C,GAAI;AAC5D;AACA;AACA,CAAC;AAED,OAAO,MAAMC,iDAAiD,GAAI;AAClE;AACA;AACA,CAAC;AAED,OAAO,MAAMC,yCAAyC,GAAI;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA,OAAO,MAAMC,iDAAiD,GAAI;AAClE;AACA;AACA,EAAE;;AAEF;AACA,OAAO,MAAMC,0CAA0C,GAAI;AAC3D;AACA;AACA;AACA,EAAE;AACF,OAAO,MAAMC,qCAAqC,GAAI;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI"}
@@ -10,9 +10,15 @@ export function injectCodeByRegex(fileContent, lineRegex, snippet) {
10
10
  export function injectCodeByMultiLineRegex(fileContent, lineRegex, snippet) {
11
11
  return fileContent.replace(lineRegex, `$&\n${snippet}`);
12
12
  }
13
+ export function injectCodeBeforeMultiLineRegex(fileContent, lineRegex, snippet) {
14
+ return fileContent.replace(lineRegex, `${snippet}\n$&`);
15
+ }
13
16
  export function replaceCodeByRegex(fileContent, lineRegex, snippet) {
14
17
  return fileContent.replace(lineRegex, snippet);
15
18
  }
19
+ export function matchRegexExists(fileContent, regex) {
20
+ return regex.test(fileContent);
21
+ }
16
22
  export function injectCodeByMultiLineRegexAndReplaceLine(fileContent, lineRegex, snippet) {
17
23
  return fileContent.replace(lineRegex, `${snippet}`);
18
24
  }
@@ -1 +1 @@
1
- {"version":3,"names":["injectCodeByRegex","fileContent","lineRegex","snippet","lines","split","index","findIndex","line","test","content","slice","injectCodeByMultiLineRegex","replace","replaceCodeByRegex","injectCodeByMultiLineRegexAndReplaceLine","injectCodeByLineNumber"],"sources":["codeInjection.ts"],"sourcesContent":["export function injectCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n const index = lines.findIndex((line) => lineRegex.test(line));\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n\nexport function injectCodeByMultiLineRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `$&\\n${snippet}`);\n}\n\nexport function replaceCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, snippet);\n}\n\nexport function injectCodeByMultiLineRegexAndReplaceLine(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `${snippet}`);\n}\n\nexport function injectCodeByLineNumber(\n fileContent: string,\n index: number,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n"],"mappings":"AAAA,OAAO,SAASA,iBAAiBA,CAC/BC,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,MAAMC,KAAK,GAAGF,KAAK,CAACG,SAAS,CAAEC,IAAI,IAAKN,SAAS,CAACO,IAAI,CAACD,IAAI,CAAC,CAAC;EAC7D,IAAIE,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB;AAEA,OAAO,SAASE,0BAA0BA,CACxCX,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,OAAMC,OAAQ,EAAC,CAAC;AACzD;AAEA,OAAO,SAASW,kBAAkBA,CAChCb,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAEC,OAAO,CAAC;AAChD;AAEA,OAAO,SAASY,wCAAwCA,CACtDd,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,GAAEC,OAAQ,EAAC,CAAC;AACrD;AAEA,OAAO,SAASa,sBAAsBA,CACpCf,WAAmB,EACnBK,KAAa,EACbH,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,IAAIK,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB"}
1
+ {"version":3,"names":["injectCodeByRegex","fileContent","lineRegex","snippet","lines","split","index","findIndex","line","test","content","slice","injectCodeByMultiLineRegex","replace","injectCodeBeforeMultiLineRegex","replaceCodeByRegex","matchRegexExists","regex","injectCodeByMultiLineRegexAndReplaceLine","injectCodeByLineNumber"],"sources":["codeInjection.ts"],"sourcesContent":["export function injectCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n const index = lines.findIndex((line) => lineRegex.test(line));\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n\nexport function injectCodeByMultiLineRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `$&\\n${snippet}`);\n}\n\nexport function injectCodeBeforeMultiLineRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `${snippet}\\n$&`);\n}\n\nexport function replaceCodeByRegex(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, snippet);\n}\n\nexport function matchRegexExists(fileContent: string, regex: RegExp) {\n return regex.test(fileContent);\n}\nexport function injectCodeByMultiLineRegexAndReplaceLine(\n fileContent: string,\n lineRegex: RegExp,\n snippet: string\n) {\n return fileContent.replace(lineRegex, `${snippet}`);\n}\n\nexport function injectCodeByLineNumber(\n fileContent: string,\n index: number,\n snippet: string\n) {\n const lines = fileContent.split('\\n');\n let content: string[] = lines;\n\n if (index > -1) {\n content = [...lines.slice(0, index), snippet, ...lines.slice(index)];\n }\n\n return content;\n}\n"],"mappings":"AAAA,OAAO,SAASA,iBAAiBA,CAC/BC,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,MAAMC,KAAK,GAAGF,KAAK,CAACG,SAAS,CAAEC,IAAI,IAAKN,SAAS,CAACO,IAAI,CAACD,IAAI,CAAC,CAAC;EAC7D,IAAIE,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB;AAEA,OAAO,SAASE,0BAA0BA,CACxCX,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,OAAMC,OAAQ,EAAC,CAAC;AACzD;AAEA,OAAO,SAASW,8BAA8BA,CAC5Cb,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,GAAEC,OAAQ,MAAK,CAAC;AACzD;AAEA,OAAO,SAASY,kBAAkBA,CAChCd,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAEC,OAAO,CAAC;AAChD;AAEA,OAAO,SAASa,gBAAgBA,CAACf,WAAmB,EAAEgB,KAAa,EAAE;EACnE,OAAOA,KAAK,CAACR,IAAI,CAACR,WAAW,CAAC;AAChC;AACA,OAAO,SAASiB,wCAAwCA,CACtDjB,WAAmB,EACnBC,SAAiB,EACjBC,OAAe,EACf;EACA,OAAOF,WAAW,CAACY,OAAO,CAACX,SAAS,EAAG,GAAEC,OAAQ,EAAC,CAAC;AACrD;AAEA,OAAO,SAASgB,sBAAsBA,CACpClB,WAAmB,EACnBK,KAAa,EACbH,OAAe,EACf;EACA,MAAMC,KAAK,GAAGH,WAAW,CAACI,KAAK,CAAC,IAAI,CAAC;EACrC,IAAIK,OAAiB,GAAGN,KAAK;EAE7B,IAAIE,KAAK,GAAG,CAAC,CAAC,EAAE;IACdI,OAAO,GAAG,CAAC,GAAGN,KAAK,CAACO,KAAK,CAAC,CAAC,EAAEL,KAAK,CAAC,EAAEH,OAAO,EAAE,GAAGC,KAAK,CAACO,KAAK,CAACL,KAAK,CAAC,CAAC;EACtE;EAEA,OAAOI,OAAO;AAChB"}
@@ -1,7 +1,7 @@
1
1
  import { withAppDelegate } from '@expo/config-plugins';
2
2
  import { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Paths';
3
- import { CIO_APPDELEGATEDECLARATION_REGEX, CIO_APPDELEGATEHEADER_REGEX, CIO_APPDELEGATEHEADER_SNIPPET, CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET, CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET, CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX, CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET, CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET, CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET } from '../helpers/constants/ios';
4
- import { injectCodeByLineNumber, injectCodeByMultiLineRegex, injectCodeByMultiLineRegexAndReplaceLine } from '../helpers/utils/codeInjection';
3
+ import { CIO_APPDELEGATEDECLARATION_REGEX, CIO_APPDELEGATEHEADER_IMPORT_SNIPPET, CIO_APPDELEGATEHEADER_REGEX, CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET, CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET, CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET, CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET, CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET, CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX, CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET, CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX, CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET, CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET, CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET, CIO_DEEPLINK_COMMENT_REGEX } from '../helpers/constants/ios';
4
+ import { injectCodeBeforeMultiLineRegex, injectCodeByLineNumber, injectCodeByMultiLineRegex, injectCodeByMultiLineRegexAndReplaceLine, replaceCodeByRegex, matchRegexExists } from '../helpers/utils/codeInjection';
5
5
  import { FileManagement } from '../helpers/utils/fileManagement';
6
6
  const pushCodeSnippets = [CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET, CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET];
7
7
  const additionalMethodsForPushNotifications = `${pushCodeSnippets.join('\n')}\n`; // Join newlines and ensure a newline at the end.
@@ -26,7 +26,15 @@ const addNotificationHandlerDeclaration = stringContents => {
26
26
  return stringContents;
27
27
  };
28
28
  const addNotificationConfiguration = stringContents => {
29
- stringContents = injectCodeByMultiLineRegex(stringContents, CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET);
29
+ stringContents = injectCodeBeforeMultiLineRegex(stringContents, CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET);
30
+ return stringContents;
31
+ };
32
+ const addUserNotificationCenterConfiguration = stringContents => {
33
+ stringContents = injectCodeBeforeMultiLineRegex(stringContents, CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET);
34
+ return stringContents;
35
+ };
36
+ const addHandleDeeplinkInKilledStateConfiguration = (stringContents, regex) => {
37
+ stringContents = injectCodeBeforeMultiLineRegex(stringContents, regex, CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET);
30
38
  return stringContents;
31
39
  };
32
40
  const addDidFailToRegisterForRemoteNotificationsWithError = stringContents => {
@@ -42,7 +50,45 @@ const addAdditionalMethodsForPushNotifications = stringContents => {
42
50
  return stringContents;
43
51
  };
44
52
  const addAppdelegateHeaderModification = stringContents => {
45
- stringContents = injectCodeByMultiLineRegexAndReplaceLine(stringContents, CIO_APPDELEGATEHEADER_REGEX, CIO_APPDELEGATEHEADER_SNIPPET);
53
+ // Add UNUserNotificationCenterDelegate if needed
54
+ stringContents = stringContents.replace(CIO_APPDELEGATEHEADER_REGEX, (match, interfaceDeclaration, _groupedDelegates, existingDelegates) => {
55
+ if (existingDelegates && existingDelegates.includes(CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET)) {
56
+ // The AppDelegate declaration already includes UNUserNotificationCenterDelegate, so we don't need to modify it
57
+ return match;
58
+ } else if (existingDelegates) {
59
+ // Other delegates exist, append ours
60
+ return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}
61
+ ${interfaceDeclaration}<${existingDelegates}, ${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>
62
+ `;
63
+ } else {
64
+ // No delegates exist, add ours
65
+ return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}
66
+ ${interfaceDeclaration.trim()} <${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>
67
+ `;
68
+ }
69
+ });
70
+ return stringContents;
71
+ };
72
+ const addHandleDeeplinkInKilledState = stringContents => {
73
+ // Find if the deep link code snippet is already present
74
+ if (matchRegexExists(stringContents, CIO_DEEPLINK_COMMENT_REGEX)) {
75
+ return stringContents;
76
+ }
77
+
78
+ // Check if the app delegate is using RCTBridge or LaunchOptions
79
+ var snippet = undefined;
80
+ var regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;
81
+ if (matchRegexExists(stringContents, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
82
+ snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;
83
+ regex = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;
84
+ } else if (matchRegexExists(stringContents, CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
85
+ snippet = CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET;
86
+ }
87
+ // Add code only if the app delegate is using RCTBridge or LaunchOptions
88
+ if (snippet !== undefined) {
89
+ stringContents = addHandleDeeplinkInKilledStateConfiguration(stringContents, regex);
90
+ stringContents = replaceCodeByRegex(stringContents, regex, snippet);
91
+ }
46
92
  return stringContents;
47
93
  };
48
94
  export const withAppDelegateModifications = (configOuter, props) => {
@@ -62,6 +108,12 @@ export const withAppDelegateModifications = (configOuter, props) => {
62
108
  if (props.disableNotificationRegistration !== undefined && props.disableNotificationRegistration === false) {
63
109
  stringContents = addNotificationConfiguration(stringContents);
64
110
  }
111
+ if (props.handleNotificationClick === undefined || props.handleNotificationClick === true) {
112
+ stringContents = addUserNotificationCenterConfiguration(stringContents);
113
+ }
114
+ if (props.handleDeeplinkInKilledState !== undefined && props.handleDeeplinkInKilledState === true) {
115
+ stringContents = addHandleDeeplinkInKilledState(stringContents);
116
+ }
65
117
  stringContents = addAdditionalMethodsForPushNotifications(stringContents);
66
118
  stringContents = addDidFailToRegisterForRemoteNotificationsWithError(stringContents);
67
119
  stringContents = addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);
@@ -1 +1 @@
1
- {"version":3,"names":["withAppDelegate","getAppDelegateHeaderFilePath","CIO_APPDELEGATEDECLARATION_REGEX","CIO_APPDELEGATEHEADER_REGEX","CIO_APPDELEGATEHEADER_SNIPPET","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","injectCodeByLineNumber","injectCodeByMultiLineRegex","injectCodeByMultiLineRegexAndReplaceLine","FileManagement","pushCodeSnippets","additionalMethodsForPushNotifications","join","addImport","stringContents","appName","importRegex","addedImport","getImportSnippet","match","endOfMatchIndex","index","undefined","length","addNotificationHandlerDeclaration","addNotificationConfiguration","addDidFailToRegisterForRemoteNotificationsWithError","addDidRegisterForRemoteNotificationsWithDeviceToken","addAdditionalMethodsForPushNotifications","addAppdelegateHeaderModification","withAppDelegateModifications","configOuter","props","config","modResults","contents","regex","RegExp","modRequest","projectName","headerPath","projectRoot","headerContent","read","write","disableNotificationRegistration","console","log"],"sources":["withAppDelegateModifications.ts"],"sourcesContent":["import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';\nimport { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Paths';\n\nimport {\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_APPDELEGATEHEADER_REGEX,\n CIO_APPDELEGATEHEADER_SNIPPET,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n} from '../helpers/constants/ios';\nimport {\n injectCodeByLineNumber,\n injectCodeByMultiLineRegex,\n injectCodeByMultiLineRegexAndReplaceLine,\n} from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport type { CustomerIOPluginOptionsIOS } from '../types/cio-types';\n\nconst pushCodeSnippets = [\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n];\n\nconst additionalMethodsForPushNotifications = `${pushCodeSnippets.join(\n '\\n'\n)}\\n`; // Join newlines and ensure a newline at the end.\n\nconst addImport = (stringContents: string, appName: string) => {\n const importRegex = /^(#import .*)\\n/gm;\n const addedImport = getImportSnippet(appName);\n\n const match = stringContents.match(importRegex);\n let endOfMatchIndex: number;\n if (!match || match.index === undefined) {\n // No imports found, just add to start of file:\n endOfMatchIndex = 0;\n } else {\n // Add after first import:\n endOfMatchIndex = match.index + match[0].length;\n }\n\n stringContents = injectCodeByLineNumber(\n stringContents,\n endOfMatchIndex,\n addedImport\n ).join('\\n');\n\n return stringContents;\n};\n\nconst addNotificationHandlerDeclaration = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addNotificationConfiguration = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidFailToRegisterForRemoteNotificationsWithError = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidRegisterForRemoteNotificationsWithDeviceToken = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addAdditionalMethodsForPushNotifications = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n additionalMethodsForPushNotifications\n );\n\n return stringContents;\n};\n\nconst addAppdelegateHeaderModification = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_APPDELEGATEHEADER_REGEX,\n CIO_APPDELEGATEHEADER_SNIPPET\n );\n\n return stringContents;\n};\n\nexport const withAppDelegateModifications: ConfigPlugin<\n CustomerIOPluginOptionsIOS\n> = (configOuter, props) => {\n return withAppDelegate(configOuter, async (config) => {\n let stringContents = config.modResults.contents;\n const regex = new RegExp(\n `#import <${config.modRequest.projectName}-Swift.h>`\n );\n const match = stringContents.match(regex);\n\n if (!match) {\n const headerPath = getAppDelegateHeaderFilePath(\n config.modRequest.projectRoot\n );\n let headerContent = await FileManagement.read(headerPath);\n headerContent = addAppdelegateHeaderModification(headerContent);\n FileManagement.write(headerPath, headerContent);\n\n stringContents = addImport(\n stringContents,\n config.modRequest.projectName as string\n );\n stringContents = addNotificationHandlerDeclaration(stringContents);\n\n // any other value would be treated as true, it has to be explicitly false to disable\n if (\n props.disableNotificationRegistration !== undefined &&\n props.disableNotificationRegistration === false\n ) {\n stringContents = addNotificationConfiguration(stringContents);\n }\n stringContents = addAdditionalMethodsForPushNotifications(stringContents);\n stringContents =\n addDidFailToRegisterForRemoteNotificationsWithError(stringContents);\n stringContents =\n addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);\n\n config.modResults.contents = stringContents;\n } else {\n console.log('Customerio AppDelegate changes already exist. Skipping...');\n }\n\n return config;\n });\n};\nfunction getImportSnippet(appName: string) {\n return `\n// Add swift bridge imports\n#import <ExpoModulesCore-Swift.h>\n#import <${appName}-Swift.h>\n `;\n}\n"],"mappings":"AAAA,SAAuBA,eAAe,QAAQ,sBAAsB;AACpE,SAASC,4BAA4B,QAAQ,sCAAsC;AAEnF,SACEC,gCAAgC,EAChCC,2BAA2B,EAC3BC,6BAA6B,EAC7BC,2CAA2C,EAC3CC,8DAA8D,EAC9DC,0DAA0D,EAC1DC,4DAA4D,EAC5DC,kCAAkC,EAClCC,iDAAiD,EACjDC,0DAA0D,EAC1DC,4DAA4D,EAC5DC,8CAA8C,EAC9CC,0CAA0C,QACrC,0BAA0B;AACjC,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,wCAAwC,QACnC,gCAAgC;AACvC,SAASC,cAAc,QAAQ,iCAAiC;AAGhE,MAAMC,gBAAgB,GAAG,CACvBT,iDAAiD,EACjDI,0CAA0C,CAC3C;AAED,MAAMM,qCAAqC,GAAI,GAAED,gBAAgB,CAACE,IAAI,CACpE,IACF,CAAE,IAAG,CAAC,CAAC;;AAEP,MAAMC,SAAS,GAAGA,CAACC,cAAsB,EAAEC,OAAe,KAAK;EAC7D,MAAMC,WAAW,GAAG,mBAAmB;EACvC,MAAMC,WAAW,GAAGC,gBAAgB,CAACH,OAAO,CAAC;EAE7C,MAAMI,KAAK,GAAGL,c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,2DAA2D,CAAC;IAC1E;IAEA,OAAOd,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AACD,SAASf,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAQ;AACV;AACA;AACA,WAAWA,OAAQ;AACnB,GAAG;AACH"}
1
+ {"version":3,"names":["withAppDelegate","getAppDelegateHeaderFilePath","CIO_APPDELEGATEDECLARATION_REGEX","CIO_APPDELEGATEHEADER_IMPORT_SNIPPET","CIO_APPDELEGATEHEADER_REGEX","CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET","CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET","CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET","CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET","CIO_DEEPLINK_COMMENT_REGEX","injectCodeBeforeMultiLineRegex","injectCodeByLineNumber","injectCodeByMultiLineRegex","injectCodeByMultiLineRegexAndReplaceLine","replaceCodeByRegex","matchRegexExists","FileManagement","pushCodeSnippets","additionalMethodsForPushNotifications","join","addImport","stringContents","appName","importRegex","addedImport","getImportSnippet","match","endOfMatchIndex","index","undefined","length","addNotificationHandlerDeclaration","addNotificationConfiguration","addUserNotificationCenterConfiguration","addHandleDeeplinkInKilledStateConfiguration","regex","addDidFailToRegisterForRemoteNotificationsWithError","addDidRegisterForRemoteNotificationsWithDeviceToken","addAdditionalMethodsForPushNotifications","addAppdelegateHeaderModification","replace","interfaceDeclaration","_groupedDelegates","existingDelegates","includes","trim","addHandleDeeplinkInKilledState","snippet","withAppDelegateModifications","configOuter","props","config","modResults","contents","RegExp","modRequest","projectName","headerPath","projectRoot","headerContent","read","write","disableNotificationRegistration","handleNotificationClick","handleDeeplinkInKilledState","console","log"],"sources":["withAppDelegateModifications.ts"],"sourcesContent":["import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';\nimport { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Paths';\n\nimport {\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_APPDELEGATEHEADER_IMPORT_SNIPPET,\n CIO_APPDELEGATEHEADER_REGEX,\n CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET,\n CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET,\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,\n CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET,\n CIO_DEEPLINK_COMMENT_REGEX,\n} from '../helpers/constants/ios';\nimport {\n injectCodeBeforeMultiLineRegex,\n injectCodeByLineNumber,\n injectCodeByMultiLineRegex,\n injectCodeByMultiLineRegexAndReplaceLine,\n replaceCodeByRegex,\n matchRegexExists\n} from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport type { CustomerIOPluginOptionsIOS } from '../types/cio-types';\n\nconst pushCodeSnippets = [\n CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,\n CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,\n];\n\nconst additionalMethodsForPushNotifications = `${pushCodeSnippets.join(\n '\\n'\n)}\\n`; // Join newlines and ensure a newline at the end.\n\nconst addImport = (stringContents: string, appName: string) => {\n const importRegex = /^(#import .*)\\n/gm;\n const addedImport = getImportSnippet(appName);\n\n const match = stringContents.match(importRegex);\n let endOfMatchIndex: number;\n if (!match || match.index === undefined) {\n // No imports found, just add to start of file:\n endOfMatchIndex = 0;\n } else {\n // Add after first import:\n endOfMatchIndex = match.index + match[0].length;\n }\n\n stringContents = injectCodeByLineNumber(\n stringContents,\n endOfMatchIndex,\n addedImport\n ).join('\\n');\n\n return stringContents;\n};\n\nconst addNotificationHandlerDeclaration = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_APPDELEGATEDECLARATION_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addNotificationConfiguration = (stringContents: string) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addUserNotificationCenterConfiguration = (stringContents: string) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addHandleDeeplinkInKilledStateConfiguration = (stringContents: string, regex: RegExp) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n regex,\n CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidFailToRegisterForRemoteNotificationsWithError = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addDidRegisterForRemoteNotificationsWithDeviceToken = (\n stringContents: string\n) => {\n stringContents = injectCodeByMultiLineRegexAndReplaceLine(\n stringContents,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addAdditionalMethodsForPushNotifications = (stringContents: string) => {\n stringContents = injectCodeByMultiLineRegex(\n stringContents,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,\n additionalMethodsForPushNotifications\n );\n\n return stringContents;\n};\n\nconst addAppdelegateHeaderModification = (stringContents: string) => {\n // Add UNUserNotificationCenterDelegate if needed\n stringContents = stringContents.replace(\n CIO_APPDELEGATEHEADER_REGEX,\n (match, interfaceDeclaration, _groupedDelegates, existingDelegates) => {\n if (existingDelegates && existingDelegates.includes(CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET)) {\n // The AppDelegate declaration already includes UNUserNotificationCenterDelegate, so we don't need to modify it\n return match;\n } else if (existingDelegates) {\n // Other delegates exist, append ours\n return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}\n${interfaceDeclaration}<${existingDelegates}, ${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>\n`;\n } else {\n // No delegates exist, add ours\n return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}\n${interfaceDeclaration.trim()} <${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>\n`;\n }\n }\n );\n\n return stringContents;\n};\n\nconst addHandleDeeplinkInKilledState = (stringContents: string) => {\n // Find if the deep link code snippet is already present\n if (matchRegexExists(stringContents, CIO_DEEPLINK_COMMENT_REGEX)) {\n return stringContents\n }\n\n // Check if the app delegate is using RCTBridge or LaunchOptions\n var snippet = undefined\n var regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n if (matchRegexExists(stringContents, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {\n snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;\n regex = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n }\n else if (matchRegexExists(stringContents, CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {\n snippet = CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET;\n }\n // Add code only if the app delegate is using RCTBridge or LaunchOptions\n if (snippet !== undefined) {\n stringContents = addHandleDeeplinkInKilledStateConfiguration(stringContents, regex);\n stringContents = replaceCodeByRegex(stringContents, regex, snippet);\n }\n return stringContents\n}\n\nexport const withAppDelegateModifications: ConfigPlugin<\n CustomerIOPluginOptionsIOS\n> = (configOuter, props) => {\n return withAppDelegate(configOuter, async (config) => {\n let stringContents = config.modResults.contents;\n const regex = new RegExp(\n `#import <${config.modRequest.projectName}-Swift.h>`\n );\n const match = stringContents.match(regex);\n\n if (!match) {\n const headerPath = getAppDelegateHeaderFilePath(\n config.modRequest.projectRoot\n );\n let headerContent = await FileManagement.read(headerPath);\n headerContent = addAppdelegateHeaderModification(headerContent);\n FileManagement.write(headerPath, headerContent);\n\n stringContents = addImport(\n stringContents,\n config.modRequest.projectName as string\n );\n stringContents = addNotificationHandlerDeclaration(stringContents);\n\n // any other value would be treated as true, it has to be explicitly false to disable\n if (\n props.disableNotificationRegistration !== undefined &&\n props.disableNotificationRegistration === false\n ) {\n stringContents = addNotificationConfiguration(stringContents);\n }\n if (\n props.handleNotificationClick === undefined ||\n props.handleNotificationClick === true\n ) {\n stringContents = addUserNotificationCenterConfiguration(stringContents);\n }\n\n if (\n props.handleDeeplinkInKilledState !== undefined &&\n props.handleDeeplinkInKilledState === true\n ) {\n stringContents = addHandleDeeplinkInKilledState(stringContents);\n }\n \n stringContents = addAdditionalMethodsForPushNotifications(stringContents);\n stringContents =\n addDidFailToRegisterForRemoteNotificationsWithError(stringContents);\n stringContents =\n addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);\n\n config.modResults.contents = stringContents;\n } else {\n console.log('Customerio AppDelegate changes already exist. Skipping...');\n }\n\n return config;\n });\n};\nfunction getImportSnippet(appName: string) {\n return `\n// Add swift bridge imports\n#import <ExpoModulesCore-Swift.h>\n#import <${appName}-Swift.h>\n `;\n}\n"],"mappings":"AAAA,SAAuBA,eAAe,QAAQ,sBAAsB;AACpE,SAASC,4BAA4B,QAAQ,sCAAsC;AAEnF,SACEC,gCAAgC,EACh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,cAAc,CAAC;MAErE8B,MAAM,CAACC,UAAU,CAACC,QAAQ,GAAGhC,cAAc;IAC7C,CAAC,MAAM;MACL4C,OAAO,CAACC,GAAG,CAAC,2DAA2D,CAAC;IAC1E;IAEA,OAAOf,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AACD,SAAS1B,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAQ;AACV;AACA;AACA,WAAWA,OAAQ;AACnB,GAAG;AACH"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["cio-types.ts"],"sourcesContent":["// properties set by the user in their app config file (e.g: app.json or app.plugin.js)\nexport type CustomerIOPluginProperties = {\n // (iOS only) Environment name and bundle identifier\n devTeam: string;\n iosDeploymentTarget: string;\n};\n\n// Plugin options for pre-build\nexport type CustomerIOPluginOptionsIOS = {\n iosPath: string;\n devTeam?: string;\n bundleVersion?: string;\n bundleShortVersion?: string;\n bundleIdentifier?: string;\n iosDeploymentTarget?: string;\n appleTeamId?: string;\n appName?: string;\n disableNotificationRegistration?: boolean;\n useFrameworks?: 'static' | 'dynamic';\n pushNotification?: {\n useRichPush: boolean;\n env: {\n siteId: string;\n apiKey: string;\n region: string;\n };\n };\n};\n\nexport type CustomerIOPluginOptionsAndroid = {\n androidPath: string;\n googleServicesFile?: string;\n setHighPriorityPushHandler?: boolean;\n};\n\nexport type CustomerIOPluginOptions = {\n android: CustomerIOPluginOptionsAndroid;\n ios: CustomerIOPluginOptionsIOS;\n};\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["cio-types.ts"],"sourcesContent":["// properties set by the user in their app config file (e.g: app.json or app.plugin.js)\nexport type CustomerIOPluginProperties = {\n // (iOS only) Environment name and bundle identifier\n devTeam: string;\n iosDeploymentTarget: string;\n};\n\n// Plugin options for pre-build\nexport type CustomerIOPluginOptionsIOS = {\n iosPath: string;\n devTeam?: string;\n bundleVersion?: string;\n bundleShortVersion?: string;\n bundleIdentifier?: string;\n iosDeploymentTarget?: string;\n appleTeamId?: string;\n appName?: string;\n disableNotificationRegistration?: boolean;\n handleNotificationClick?:boolean;\n handleDeeplinkInKilledState?:boolean;\n useFrameworks?: 'static' | 'dynamic';\n pushNotification?: {\n useRichPush: boolean;\n env: {\n siteId: string;\n apiKey: string;\n region: string;\n };\n };\n};\n\nexport type CustomerIOPluginOptionsAndroid = {\n androidPath: string;\n googleServicesFile?: string;\n setHighPriorityPushHandler?: boolean;\n};\n\nexport type CustomerIOPluginOptions = {\n android: CustomerIOPluginOptionsAndroid;\n ios: CustomerIOPluginOptionsIOS;\n};\n"],"mappings":""}
@@ -11,15 +11,23 @@ export declare const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_RE
11
11
  export declare const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX: RegExp;
12
12
  export declare const CIO_APPDELEGATEDECLARATION_REGEX: RegExp;
13
13
  export declare const CIO_APPDELEGATEHEADER_REGEX: RegExp;
14
+ export declare const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX: RegExp;
15
+ export declare const CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX: RegExp;
16
+ export declare const CIO_DEEPLINK_COMMENT_REGEX: RegExp;
14
17
  export declare const DEFAULT_BUNDLE_VERSION = "1";
15
18
  export declare const DEFAULT_BUNDLE_SHORT_VERSION = "1.0";
16
19
  export declare const CIO_TARGET_NAME = "CustomerIOSDK";
17
20
  export declare const CIO_NOTIFICATION_TARGET_NAME = "NotificationService";
18
- export declare const CIO_APPDELEGATEHEADER_SNIPPET = "\n#import <UserNotifications/UserNotifications.h>\n\n@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>\n";
21
+ export declare const CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = "#import <UserNotifications/UserNotifications.h>";
22
+ export declare const CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = "UNUserNotificationCenterDelegate";
19
23
  export declare const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = "\nCIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];\n";
24
+ export declare const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = "\nRCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:modifiedLaunchOptions];\n";
25
+ export declare const CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = "\nreturn [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];";
20
26
  export declare const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = "\n [super application:application didFailToRegisterForRemoteNotificationsWithError:error];\n [pnHandlerObj application:application error:error];\n";
21
27
  export declare const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = "\n [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];\n return [pnHandlerObj application:application deviceToken:deviceToken];\n";
22
- export declare const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = "\n // Register for push notifications\n [pnHandlerObj registerPushNotification:self];\n";
28
+ export declare const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = "\n // Register for push notifications\n [pnHandlerObj registerPushNotification];\n";
29
+ export declare const CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = "\n UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];\n center.delegate = self;\n";
30
+ export declare const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = "\n// Deep link workaround for app killed state start\nNSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];\n if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {\n NSDictionary *pushContent = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];\n if (pushContent[@\"CIO\"] && pushContent[@\"CIO\"][@\"push\"] && pushContent[@\"CIO\"][@\"push\"][@\"link\"]) {\n NSString *initialURL = pushContent[@\"CIO\"][@\"push\"][@\"link\"];\n if (!launchOptions[UIApplicationLaunchOptionsURLKey]) {\n modifiedLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];\n }\n }\n }\n//Deep link workaround for app killed state ends\n";
23
31
  export declare const CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET = "\n- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {\n [pnHandlerObj userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];\n}";
24
32
  export declare const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = "\n// show push when the app is in foreground\n- (void)userNotificationCenter:(UNUserNotificationCenter* )center willPresentNotification:(UNNotification* )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {\n completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);\n}";
25
- export declare const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = "\n@objc(registerPushNotification:)\n public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {\n\n let center = UNUserNotificationCenter.current()\n center.delegate = notificationDelegate\n center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n if error == nil{\n DispatchQueue.main.async {\n UIApplication.shared.registerForRemoteNotifications()\n }\n }\n }\n }";
33
+ export declare const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = "\n@objc(registerPushNotification)\n public func registerPushNotification() {\n\n let center = UNUserNotificationCenter.current()\n center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n if error == nil{\n DispatchQueue.main.async {\n UIApplication.shared.registerForRemoteNotifications()\n }\n }\n }\n }";
@@ -1,5 +1,7 @@
1
1
  export declare function injectCodeByRegex(fileContent: string, lineRegex: RegExp, snippet: string): string[];
2
2
  export declare function injectCodeByMultiLineRegex(fileContent: string, lineRegex: RegExp, snippet: string): string;
3
+ export declare function injectCodeBeforeMultiLineRegex(fileContent: string, lineRegex: RegExp, snippet: string): string;
3
4
  export declare function replaceCodeByRegex(fileContent: string, lineRegex: RegExp, snippet: string): string;
5
+ export declare function matchRegexExists(fileContent: string, regex: RegExp): boolean;
4
6
  export declare function injectCodeByMultiLineRegexAndReplaceLine(fileContent: string, lineRegex: RegExp, snippet: string): string;
5
7
  export declare function injectCodeByLineNumber(fileContent: string, index: number, snippet: string): string[];
@@ -12,6 +12,8 @@ export type CustomerIOPluginOptionsIOS = {
12
12
  appleTeamId?: string;
13
13
  appName?: string;
14
14
  disableNotificationRegistration?: boolean;
15
+ handleNotificationClick?: boolean;
16
+ handleDeeplinkInKilledState?: boolean;
15
17
  useFrameworks?: 'static' | 'dynamic';
16
18
  pushNotification?: {
17
19
  useRichPush: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customerio-expo-plugin",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
4
4
  "description": "Expo config plugin for the Customer IO React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -25,7 +25,7 @@ export const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;
25
25
  export const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;
26
26
  export const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;
27
27
  export const CIO_DIDFINISHLAUNCHINGMETHOD_REGEX =
28
- /(- \(BOOL\)application:\(UIApplication \*\)application didFinishLaunchingWithOptions:\(NSDictionary \*\)launchOptions(\s|\n)*?\{)((.|\n)*)\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
28
+ /.*\[super(\s)application:application(\s)didFinishLaunchingWithOptions:launchOptions\];/;
29
29
 
30
30
  export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX =
31
31
  /return \[super application:application didFailToRegisterForRemoteNotificationsWithError:error\];/;
@@ -40,20 +40,31 @@ export const CIO_APPDELEGATEDECLARATION_REGEX =
40
40
  /@implementation AppDelegate(.|\n)/;
41
41
 
42
42
  export const CIO_APPDELEGATEHEADER_REGEX =
43
- /@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>/;
43
+ /(@interface AppDelegate\s*:\s*EXAppDelegateWrapper\s*)(<([^>]+)>)?/;
44
+
45
+ export const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX =
46
+ /^\s*RCTBridge\s*\*\s*\w+\s*=\s*\[\s*self\.reactDelegate\s+createBridgeWithDelegate:self\s+launchOptions:launchOptions\s*\];\s*$/gm;
47
+
48
+ export const CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX =
49
+ /^\s*return\s\[\s*super\s*application:\s*application\s*didFinishLaunchingWithOptions\s*:\s*launchOptions\s*\];/gm;
50
+
51
+ export const CIO_DEEPLINK_COMMENT_REGEX = /\sDeep link workaround for app killed state start/gm;
44
52
  export const DEFAULT_BUNDLE_VERSION = '1';
45
53
  export const DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
46
54
  export const CIO_TARGET_NAME = 'CustomerIOSDK';
47
55
  export const CIO_NOTIFICATION_TARGET_NAME = 'NotificationService';
48
- export const CIO_APPDELEGATEHEADER_SNIPPET = `
49
- #import <UserNotifications/UserNotifications.h>
50
-
51
- @interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate, UNUserNotificationCenterDelegate>
52
- `;
53
56
 
57
+ export const CIO_APPDELEGATEHEADER_IMPORT_SNIPPET = `#import <UserNotifications/UserNotifications.h>`;
58
+ export const CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET = 'UNUserNotificationCenterDelegate';
54
59
  export const CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET = `
55
60
  CIOAppPushNotificationsHandler* pnHandlerObj = [[CIOAppPushNotificationsHandler alloc] init];
56
61
  `;
62
+ export const CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET = `
63
+ RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:modifiedLaunchOptions];
64
+ `;
65
+
66
+ export const CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET = `
67
+ return [super application:application didFinishLaunchingWithOptions:modifiedLaunchOptions];`
57
68
 
58
69
  export const CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET = `
59
70
  [super application:application didFailToRegisterForRemoteNotificationsWithError:error];
@@ -67,7 +78,27 @@ export const CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET = `
67
78
 
68
79
  export const CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET = `
69
80
  // Register for push notifications
70
- [pnHandlerObj registerPushNotification:self];
81
+ [pnHandlerObj registerPushNotification];
82
+ `;
83
+
84
+ export const CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET = `
85
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
86
+ center.delegate = self;
87
+ `;
88
+
89
+ export const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET = `
90
+ // Deep link workaround for app killed state start
91
+ NSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];
92
+ if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
93
+ NSDictionary *pushContent = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
94
+ if (pushContent[@"CIO"] && pushContent[@"CIO"][@"push"] && pushContent[@"CIO"][@"push"][@"link"]) {
95
+ NSString *initialURL = pushContent[@"CIO"][@"push"][@"link"];
96
+ if (!launchOptions[UIApplicationLaunchOptionsURLKey]) {
97
+ modifiedLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];
98
+ }
99
+ }
100
+ }
101
+ //Deep link workaround for app killed state ends
71
102
  `;
72
103
 
73
104
  // Enable push handling - notification response
@@ -83,11 +114,10 @@ export const CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET = `
83
114
  completionHandler( UNNotificationPresentationOptionAlert + UNNotificationPresentationOptionSound);
84
115
  }`;
85
116
  export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
86
- @objc(registerPushNotification:)
87
- public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {
117
+ @objc(registerPushNotification)
118
+ public func registerPushNotification() {
88
119
 
89
120
  let center = UNUserNotificationCenter.current()
90
- center.delegate = notificationDelegate
91
121
  center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
92
122
  if error == nil{
93
123
  DispatchQueue.main.async {
@@ -22,6 +22,14 @@ export function injectCodeByMultiLineRegex(
22
22
  return fileContent.replace(lineRegex, `$&\n${snippet}`);
23
23
  }
24
24
 
25
+ export function injectCodeBeforeMultiLineRegex(
26
+ fileContent: string,
27
+ lineRegex: RegExp,
28
+ snippet: string
29
+ ) {
30
+ return fileContent.replace(lineRegex, `${snippet}\n$&`);
31
+ }
32
+
25
33
  export function replaceCodeByRegex(
26
34
  fileContent: string,
27
35
  lineRegex: RegExp,
@@ -30,6 +38,9 @@ export function replaceCodeByRegex(
30
38
  return fileContent.replace(lineRegex, snippet);
31
39
  }
32
40
 
41
+ export function matchRegexExists(fileContent: string, regex: RegExp) {
42
+ return regex.test(fileContent);
43
+ }
33
44
  export function injectCodeByMultiLineRegexAndReplaceLine(
34
45
  fileContent: string,
35
46
  lineRegex: RegExp,
@@ -3,23 +3,34 @@ import { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Pat
3
3
 
4
4
  import {
5
5
  CIO_APPDELEGATEDECLARATION_REGEX,
6
+ CIO_APPDELEGATEHEADER_IMPORT_SNIPPET,
6
7
  CIO_APPDELEGATEHEADER_REGEX,
7
- CIO_APPDELEGATEHEADER_SNIPPET,
8
+ CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET,
8
9
  CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET,
10
+ CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET,
11
+ CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET,
9
12
  CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERRORFULL_REGEX,
13
+ CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX,
10
14
  CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,
11
15
  CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,
12
16
  CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,
13
17
  CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,
14
18
  CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,
15
19
  CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,
20
+ CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX,
16
21
  CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,
17
22
  CIO_WILLPRESENTNOTIFICATIONHANDLER_SNIPPET,
23
+ CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET,
24
+ CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET,
25
+ CIO_DEEPLINK_COMMENT_REGEX,
18
26
  } from '../helpers/constants/ios';
19
27
  import {
28
+ injectCodeBeforeMultiLineRegex,
20
29
  injectCodeByLineNumber,
21
30
  injectCodeByMultiLineRegex,
22
31
  injectCodeByMultiLineRegexAndReplaceLine,
32
+ replaceCodeByRegex,
33
+ matchRegexExists
23
34
  } from '../helpers/utils/codeInjection';
24
35
  import { FileManagement } from '../helpers/utils/fileManagement';
25
36
  import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
@@ -67,7 +78,7 @@ const addNotificationHandlerDeclaration = (stringContents: string) => {
67
78
  };
68
79
 
69
80
  const addNotificationConfiguration = (stringContents: string) => {
70
- stringContents = injectCodeByMultiLineRegex(
81
+ stringContents = injectCodeBeforeMultiLineRegex(
71
82
  stringContents,
72
83
  CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,
73
84
  CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET
@@ -76,6 +87,26 @@ const addNotificationConfiguration = (stringContents: string) => {
76
87
  return stringContents;
77
88
  };
78
89
 
90
+ const addUserNotificationCenterConfiguration = (stringContents: string) => {
91
+ stringContents = injectCodeBeforeMultiLineRegex(
92
+ stringContents,
93
+ CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,
94
+ CIO_CONFIGURECIOSDKUSERNOTIFICATIONCENTER_SNIPPET
95
+ );
96
+
97
+ return stringContents;
98
+ };
99
+
100
+ const addHandleDeeplinkInKilledStateConfiguration = (stringContents: string, regex: RegExp) => {
101
+ stringContents = injectCodeBeforeMultiLineRegex(
102
+ stringContents,
103
+ regex,
104
+ CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET
105
+ );
106
+
107
+ return stringContents;
108
+ };
109
+
79
110
  const addDidFailToRegisterForRemoteNotificationsWithError = (
80
111
  stringContents: string
81
112
  ) => {
@@ -111,15 +142,54 @@ const addAdditionalMethodsForPushNotifications = (stringContents: string) => {
111
142
  };
112
143
 
113
144
  const addAppdelegateHeaderModification = (stringContents: string) => {
114
- stringContents = injectCodeByMultiLineRegexAndReplaceLine(
115
- stringContents,
145
+ // Add UNUserNotificationCenterDelegate if needed
146
+ stringContents = stringContents.replace(
116
147
  CIO_APPDELEGATEHEADER_REGEX,
117
- CIO_APPDELEGATEHEADER_SNIPPET
148
+ (match, interfaceDeclaration, _groupedDelegates, existingDelegates) => {
149
+ if (existingDelegates && existingDelegates.includes(CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET)) {
150
+ // The AppDelegate declaration already includes UNUserNotificationCenterDelegate, so we don't need to modify it
151
+ return match;
152
+ } else if (existingDelegates) {
153
+ // Other delegates exist, append ours
154
+ return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}
155
+ ${interfaceDeclaration}<${existingDelegates}, ${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>
156
+ `;
157
+ } else {
158
+ // No delegates exist, add ours
159
+ return `${CIO_APPDELEGATEHEADER_IMPORT_SNIPPET}
160
+ ${interfaceDeclaration.trim()} <${CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET}>
161
+ `;
162
+ }
163
+ }
118
164
  );
119
165
 
120
166
  return stringContents;
121
167
  };
122
168
 
169
+ const addHandleDeeplinkInKilledState = (stringContents: string) => {
170
+ // Find if the deep link code snippet is already present
171
+ if (matchRegexExists(stringContents, CIO_DEEPLINK_COMMENT_REGEX)) {
172
+ return stringContents
173
+ }
174
+
175
+ // Check if the app delegate is using RCTBridge or LaunchOptions
176
+ var snippet = undefined
177
+ var regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;
178
+ if (matchRegexExists(stringContents, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
179
+ snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;
180
+ regex = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;
181
+ }
182
+ else if (matchRegexExists(stringContents, CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
183
+ snippet = CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET;
184
+ }
185
+ // Add code only if the app delegate is using RCTBridge or LaunchOptions
186
+ if (snippet !== undefined) {
187
+ stringContents = addHandleDeeplinkInKilledStateConfiguration(stringContents, regex);
188
+ stringContents = replaceCodeByRegex(stringContents, regex, snippet);
189
+ }
190
+ return stringContents
191
+ }
192
+
123
193
  export const withAppDelegateModifications: ConfigPlugin<
124
194
  CustomerIOPluginOptionsIOS
125
195
  > = (configOuter, props) => {
@@ -151,6 +221,20 @@ export const withAppDelegateModifications: ConfigPlugin<
151
221
  ) {
152
222
  stringContents = addNotificationConfiguration(stringContents);
153
223
  }
224
+ if (
225
+ props.handleNotificationClick === undefined ||
226
+ props.handleNotificationClick === true
227
+ ) {
228
+ stringContents = addUserNotificationCenterConfiguration(stringContents);
229
+ }
230
+
231
+ if (
232
+ props.handleDeeplinkInKilledState !== undefined &&
233
+ props.handleDeeplinkInKilledState === true
234
+ ) {
235
+ stringContents = addHandleDeeplinkInKilledState(stringContents);
236
+ }
237
+
154
238
  stringContents = addAdditionalMethodsForPushNotifications(stringContents);
155
239
  stringContents =
156
240
  addDidFailToRegisterForRemoteNotificationsWithError(stringContents);
@@ -16,6 +16,8 @@ export type CustomerIOPluginOptionsIOS = {
16
16
  appleTeamId?: string;
17
17
  appName?: string;
18
18
  disableNotificationRegistration?: boolean;
19
+ handleNotificationClick?:boolean;
20
+ handleDeeplinkInKilledState?:boolean;
19
21
  useFrameworks?: 'static' | 'dynamic';
20
22
  pushNotification?: {
21
23
  useRichPush: boolean;