customerio-expo-plugin 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -31
- package/plugin/app.plugin.js +1 -1
- package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js +4 -4
- package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js.map +1 -1
- package/plugin/lib/commonjs/android/withCIOAndroid.js +6 -1
- package/plugin/lib/commonjs/android/withCIOAndroid.js.map +1 -1
- package/plugin/lib/commonjs/android/withGoogleServicesJSON.js +1 -1
- package/plugin/lib/commonjs/android/withGoogleServicesJSON.js.map +1 -1
- package/plugin/lib/commonjs/android/withMainApplicationModifications.js +45 -0
- package/plugin/lib/commonjs/android/withMainApplicationModifications.js.map +1 -0
- package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js +1 -1
- package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js.map +1 -1
- package/plugin/lib/commonjs/android/withProjectStrings.js +14 -7
- package/plugin/lib/commonjs/android/withProjectStrings.js.map +1 -1
- package/plugin/lib/commonjs/helpers/constants/android.js +7 -1
- package/plugin/lib/commonjs/helpers/constants/android.js.map +1 -1
- package/plugin/lib/commonjs/helpers/constants/common.js +18 -0
- package/plugin/lib/commonjs/helpers/constants/common.js.map +1 -0
- package/plugin/lib/commonjs/helpers/constants/ios.js +7 -7
- package/plugin/lib/commonjs/helpers/constants/ios.js.map +1 -1
- package/plugin/lib/commonjs/helpers/native-files/android/CustomerIOSDKInitializer.kt +64 -0
- package/plugin/lib/commonjs/helpers/native-files/ios/CustomerIOSDKInitializer.swift +54 -0
- package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js +2 -2
- package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
- package/plugin/lib/commonjs/helpers/utils/patchPluginNativeCode.js +62 -0
- package/plugin/lib/commonjs/helpers/utils/patchPluginNativeCode.js.map +1 -0
- package/plugin/lib/commonjs/index.js +13 -2
- package/plugin/lib/commonjs/index.js.map +1 -1
- package/plugin/lib/commonjs/ios/utils.js +1 -1
- package/plugin/lib/commonjs/ios/utils.js.map +1 -1
- package/plugin/lib/commonjs/ios/withAppDelegateModifications.js +1 -1
- package/plugin/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
- package/plugin/lib/commonjs/ios/withCIOIos.js +17 -11
- package/plugin/lib/commonjs/ios/withCIOIos.js.map +1 -1
- package/plugin/lib/commonjs/ios/withCIOIosSwift.js +133 -49
- package/plugin/lib/commonjs/ios/withCIOIosSwift.js.map +1 -1
- package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js +1 -1
- package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js.map +1 -1
- package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js +17 -19
- package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
- package/plugin/lib/commonjs/ios/withXcodeProject.js +1 -1
- package/plugin/lib/commonjs/ios/withXcodeProject.js.map +1 -1
- package/plugin/lib/commonjs/postInstallHelper.js.map +1 -1
- package/plugin/lib/commonjs/types/cio-types.js.map +1 -1
- package/plugin/lib/commonjs/utils/android.js +109 -0
- package/plugin/lib/commonjs/utils/android.js.map +1 -0
- package/plugin/lib/commonjs/utils/config.js +43 -0
- package/plugin/lib/commonjs/utils/config.js.map +1 -0
- package/plugin/lib/commonjs/utils/plugin.js +49 -0
- package/plugin/lib/commonjs/utils/plugin.js.map +1 -0
- package/plugin/lib/commonjs/utils/validation.js +44 -0
- package/plugin/lib/commonjs/utils/validation.js.map +1 -0
- package/plugin/lib/commonjs/utils/xcode.js +67 -0
- package/plugin/lib/commonjs/utils/xcode.js.map +1 -0
- package/plugin/lib/module/android/withAndroidManifestUpdates.js +4 -4
- package/plugin/lib/module/android/withAndroidManifestUpdates.js.map +1 -1
- package/plugin/lib/module/android/withCIOAndroid.js +6 -1
- package/plugin/lib/module/android/withCIOAndroid.js.map +1 -1
- package/plugin/lib/module/android/withGoogleServicesJSON.js +1 -1
- package/plugin/lib/module/android/withGoogleServicesJSON.js.map +1 -1
- package/plugin/lib/module/android/withMainApplicationModifications.js +38 -0
- package/plugin/lib/module/android/withMainApplicationModifications.js.map +1 -0
- package/plugin/lib/module/android/withNotificationChannelMetadata.js +1 -1
- package/plugin/lib/module/android/withNotificationChannelMetadata.js.map +1 -1
- package/plugin/lib/module/android/withProjectStrings.js +13 -6
- package/plugin/lib/module/android/withProjectStrings.js.map +1 -1
- package/plugin/lib/module/helpers/constants/android.js +6 -0
- package/plugin/lib/module/helpers/constants/android.js.map +1 -1
- package/plugin/lib/module/helpers/constants/common.js +12 -0
- package/plugin/lib/module/helpers/constants/common.js.map +1 -0
- package/plugin/lib/module/helpers/constants/ios.js +6 -6
- package/plugin/lib/module/helpers/constants/ios.js.map +1 -1
- package/plugin/lib/module/helpers/native-files/android/CustomerIOSDKInitializer.kt +64 -0
- package/plugin/lib/module/helpers/native-files/ios/CustomerIOSDKInitializer.swift +54 -0
- package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js +2 -2
- package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
- package/plugin/lib/module/helpers/utils/patchPluginNativeCode.js +57 -0
- package/plugin/lib/module/helpers/utils/patchPluginNativeCode.js.map +1 -0
- package/plugin/lib/module/index.js +14 -2
- package/plugin/lib/module/index.js.map +1 -1
- package/plugin/lib/module/ios/utils.js +1 -2
- package/plugin/lib/module/ios/utils.js.map +1 -1
- package/plugin/lib/module/ios/withAppDelegateModifications.js +3 -3
- package/plugin/lib/module/ios/withAppDelegateModifications.js.map +1 -1
- package/plugin/lib/module/ios/withCIOIos.js +17 -11
- package/plugin/lib/module/ios/withCIOIos.js.map +1 -1
- package/plugin/lib/module/ios/withCIOIosSwift.js +134 -50
- package/plugin/lib/module/ios/withCIOIosSwift.js.map +1 -1
- package/plugin/lib/module/ios/withGoogleServicesJsonFile.js +2 -2
- package/plugin/lib/module/ios/withGoogleServicesJsonFile.js.map +1 -1
- package/plugin/lib/module/ios/withNotificationsXcodeProject.js +18 -20
- package/plugin/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
- package/plugin/lib/module/ios/withXcodeProject.js +1 -1
- package/plugin/lib/module/ios/withXcodeProject.js.map +1 -1
- package/plugin/lib/module/postInstallHelper.js.map +1 -1
- package/plugin/lib/module/types/cio-types.js.map +1 -1
- package/plugin/lib/module/utils/android.js +100 -0
- package/plugin/lib/module/utils/android.js.map +1 -0
- package/plugin/lib/module/utils/config.js +38 -0
- package/plugin/lib/module/utils/config.js.map +1 -0
- package/plugin/lib/module/utils/plugin.js +38 -0
- package/plugin/lib/module/utils/plugin.js.map +1 -0
- package/plugin/lib/module/utils/validation.js +39 -0
- package/plugin/lib/module/utils/validation.js.map +1 -0
- package/plugin/lib/module/utils/xcode.js +60 -0
- package/plugin/lib/module/utils/xcode.js.map +1 -0
- package/plugin/lib/typescript/android/withCIOAndroid.d.ts +2 -2
- package/plugin/lib/typescript/android/withMainApplicationModifications.d.ts +3 -0
- package/plugin/lib/typescript/android/withProjectStrings.d.ts +2 -1
- package/plugin/lib/typescript/helpers/constants/android.d.ts +3 -0
- package/plugin/lib/typescript/helpers/constants/common.d.ts +11 -0
- package/plugin/lib/typescript/helpers/constants/ios.d.ts +3 -1
- package/plugin/lib/typescript/helpers/utils/patchPluginNativeCode.d.ts +7 -0
- package/plugin/lib/typescript/ios/utils.d.ts +2 -2
- package/plugin/lib/typescript/ios/withCIOIos.d.ts +2 -2
- package/plugin/lib/typescript/ios/withCIOIosSwift.d.ts +3 -3
- package/plugin/lib/typescript/types/cio-types.d.ts +46 -6
- package/plugin/lib/typescript/utils/android.d.ts +5 -0
- package/plugin/lib/typescript/utils/config.d.ts +8 -0
- package/plugin/lib/typescript/utils/plugin.d.ts +4 -0
- package/plugin/lib/typescript/utils/validation.d.ts +3 -0
- package/plugin/lib/typescript/utils/xcode.d.ts +28 -0
- package/plugin/src/android/withAndroidManifestUpdates.ts +5 -5
- package/plugin/src/android/withCIOAndroid.ts +7 -1
- package/plugin/src/android/withGoogleServicesJSON.ts +2 -2
- package/plugin/src/android/withMainApplicationModifications.ts +50 -0
- package/plugin/src/android/withNotificationChannelMetadata.ts +7 -3
- package/plugin/src/android/withProjectStrings.ts +20 -10
- package/plugin/src/helpers/constants/android.ts +7 -0
- package/plugin/src/helpers/constants/common.ts +12 -0
- package/plugin/src/helpers/constants/ios.ts +11 -13
- package/plugin/src/helpers/native-files/android/CustomerIOSDKInitializer.kt +64 -0
- package/plugin/src/helpers/native-files/ios/CustomerIOSDKInitializer.swift +54 -0
- package/plugin/src/helpers/utils/injectCIOPodfileCode.ts +8 -7
- package/plugin/src/helpers/utils/patchPluginNativeCode.ts +97 -0
- package/plugin/src/index.ts +18 -2
- package/plugin/src/ios/utils.ts +5 -5
- package/plugin/src/ios/withAppDelegateModifications.ts +11 -8
- package/plugin/src/ios/withCIOIos.ts +19 -11
- package/plugin/src/ios/withCIOIosSwift.ts +195 -73
- package/plugin/src/ios/withGoogleServicesJsonFile.ts +7 -10
- package/plugin/src/ios/withNotificationsXcodeProject.ts +25 -26
- package/plugin/src/ios/withXcodeProject.ts +1 -1
- package/plugin/src/postInstallHelper.js +1 -1
- package/plugin/src/types/cio-types.ts +48 -8
- package/plugin/src/utils/android.ts +112 -0
- package/plugin/src/utils/config.ts +53 -0
- package/plugin/src/utils/plugin.ts +46 -0
- package/plugin/src/utils/validation.ts +54 -0
- package/plugin/src/utils/xcode.ts +74 -0
- package/plugin/lib/commonjs/helpers/constants/globals.d.js +0 -2
- package/plugin/lib/commonjs/helpers/constants/globals.d.js.map +0 -1
- package/plugin/lib/commonjs/helpers/utils/pluginUtils.js +0 -26
- package/plugin/lib/commonjs/helpers/utils/pluginUtils.js.map +0 -1
- package/plugin/lib/module/helpers/constants/globals.d.js +0 -2
- package/plugin/lib/module/helpers/constants/globals.d.js.map +0 -1
- package/plugin/lib/module/helpers/utils/pluginUtils.js +0 -19
- package/plugin/lib/module/helpers/utils/pluginUtils.js.map +0 -1
- package/plugin/lib/typescript/helpers/utils/pluginUtils.d.ts +0 -4
- package/plugin/src/helpers/constants/globals.d.ts +0 -8
- package/plugin/src/helpers/utils/pluginUtils.ts +0 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PLATFORM","getPluginVersion","patchNativeSDKInitializer","rawContent","platform","sdkConfig","_siteId","_migrationSiteId","content","replaceValue","placeholder","value","transform","fallback","ANDROID","undefined","replace","pluginVersion","cdpApiKey","region","configValue","logLevel","autoTrackDeviceAttributes","toString","trackApplicationLifecycleEvents","screenViewUse","siteId","migrationSiteId","trim"],"sources":["patchPluginNativeCode.ts"],"sourcesContent":["import type { NativeSDKConfig } from '../../types/cio-types';\nimport { PLATFORM, type Platform } from '../constants/common';\nimport { getPluginVersion } from '../../utils/plugin';\n\n/**\n * Shared utility function to perform common SDK config replacements\n * for both iOS and Android template files\n */\nexport function patchNativeSDKInitializer(\n rawContent: string,\n platform: Platform,\n sdkConfig: NativeSDKConfig\n): string {\n let content = rawContent;\n\n // Helper function to replace placeholders with platform-specific fallback values\n const replaceValue = <T>(\n placeholder: RegExp,\n value: T | undefined,\n transform: (configValue: T) => string,\n fallback: string = platform === PLATFORM.ANDROID ? 'null' : 'nil'\n ) => {\n if (value !== undefined && value !== null) {\n content = content.replace(placeholder, transform(value));\n } else {\n content = content.replace(placeholder, fallback);\n }\n };\n\n // Replace EXPO_PLUGIN_VERSION with actual plugin version\n const pluginVersion = getPluginVersion();\n content = content.replace(/\\{\\{EXPO_PLUGIN_VERSION\\}\\}/g, pluginVersion);\n\n // Replace CDP API Key (required field)\n content = content.replace(/\\{\\{CDP_API_KEY\\}\\}/g, sdkConfig.cdpApiKey);\n\n // Handle region - use empty string as fallback (nil not supported for region)\n replaceValue(\n /\\{\\{REGION\\}\\}/g,\n sdkConfig.region,\n (configValue) => `\"${configValue}\"`,\n '\"\"'\n );\n\n // Handle logLevel - use nil/null as fallback\n replaceValue(\n /\\{\\{LOG_LEVEL\\}\\}/g,\n sdkConfig.logLevel,\n (configValue) => `\"${configValue}\"`\n );\n\n // Handle optional boolean configurations\n replaceValue(\n /\\{\\{AUTO_TRACK_DEVICE_ATTRIBUTES\\}\\}/g,\n sdkConfig.autoTrackDeviceAttributes,\n (configValue) => configValue.toString()\n );\n\n replaceValue(\n /\\{\\{TRACK_APPLICATION_LIFECYCLE_EVENTS\\}\\}/g,\n sdkConfig.trackApplicationLifecycleEvents,\n (configValue) => configValue.toString()\n );\n\n // Handle screenViewUse - use nil/null as fallback\n replaceValue(\n /\\{\\{SCREEN_VIEW_USE\\}\\}/g,\n sdkConfig.screenViewUse,\n (configValue) => `\"${configValue}\"`\n );\n\n // Handle siteId/migrationSiteId business logic\n let siteId = sdkConfig.siteId;\n let migrationSiteId = sdkConfig.migrationSiteId;\n\n // Business rule: if only siteId provided, copy to migrationSiteId; if only migrationSiteId provided, set siteId to undefined\n if (siteId && !migrationSiteId) {\n migrationSiteId = siteId;\n } else if (migrationSiteId && !siteId) {\n siteId = undefined;\n }\n\n // Replace siteId and migrationSiteId placeholders (trim whitespace and handle empty strings)\n replaceValue(\n /\\{\\{SITE_ID\\}\\}/g,\n siteId?.trim() || undefined,\n (configValue) => `\"${configValue}\"`\n );\n\n replaceValue(\n /\\{\\{MIGRATION_SITE_ID\\}\\}/g,\n migrationSiteId?.trim() || undefined,\n (configValue) => `\"${configValue}\"`\n );\n\n return content;\n}\n"],"mappings":"AACA,SAASA,QAAQ,QAAuB,qBAAqB;AAC7D,SAASC,gBAAgB,QAAQ,oBAAoB;;AAErD;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACvCC,UAAkB,EAClBC,QAAkB,EAClBC,SAA0B,EAClB;EAAA,IAAAC,OAAA,EAAAC,gBAAA;EACR,IAAIC,OAAO,GAAGL,UAAU;;EAExB;EACA,MAAMM,YAAY,GAAGA,CACnBC,WAAmB,EACnBC,KAAoB,EACpBC,SAAqC,EACrCC,QAA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,MAAM,IAAI,CAACC,eAAe,EAAE;IAC9BA,eAAe,GAAGD,MAAM;EAC1B,CAAC,MAAM,IAAIC,eAAe,IAAI,CAACD,MAAM,EAAE;IACrCA,MAAM,GAAGX,SAAS;EACpB;;EAEA;EACAN,YAAY,CACV,kBAAkB,EAClB,EAAAH,OAAA,GAAAoB,MAAM,cAAApB,OAAA,uBAANA,OAAA,CAAQsB,IAAI,CAAC,CAAC,KAAIb,SAAS,EAC1BK,WAAW,IAAK,IAAIA,WAAW,GAClC,CAAC;EAEDX,YAAY,CACV,4BAA4B,EAC5B,EAAAF,gBAAA,GAAAoB,eAAe,cAAApB,gBAAA,uBAAfA,gBAAA,CAAiBqB,IAAI,CAAC,CAAC,KAAIb,SAAS,EACnCK,WAAW,IAAK,IAAIA,WAAW,GAClC,CAAC;EAED,OAAOZ,OAAO;AAChB","ignoreList":[]}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { withCIOAndroid } from './android/withCIOAndroid';
|
|
2
|
+
import { isExpoVersion53OrHigher } from './ios/utils';
|
|
2
3
|
import { withCIOIos } from './ios/withCIOIos';
|
|
4
|
+
import { validateNativeSDKConfig } from './utils/validation';
|
|
5
|
+
|
|
3
6
|
// Entry point for config plugin
|
|
4
7
|
function withCustomerIOPlugin(config, props) {
|
|
8
|
+
// Check if config is being used with unsupported Expo version
|
|
9
|
+
if (props.config && !isExpoVersion53OrHigher(config)) {
|
|
10
|
+
throw new Error('CustomerIO auto initialization (config property) requires Expo SDK 53 or higher. ' + 'Please upgrade to Expo SDK 53+ or use manual initialization instead. ' + 'See documentation for manual setup instructions.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Validate SDK config if provided
|
|
14
|
+
if (props.config) {
|
|
15
|
+
validateNativeSDKConfig(props.config);
|
|
16
|
+
}
|
|
5
17
|
if (props.ios) {
|
|
6
|
-
config = withCIOIos(config, props.ios);
|
|
18
|
+
config = withCIOIos(config, props.config, props.ios);
|
|
7
19
|
}
|
|
8
20
|
if (props.android) {
|
|
9
|
-
config = withCIOAndroid(config, props.android);
|
|
21
|
+
config = withCIOAndroid(config, props.config, props.android);
|
|
10
22
|
}
|
|
11
23
|
return config;
|
|
12
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["withCIOAndroid","withCIOIos","withCustomerIOPlugin","config","props","ios","android"],"sources":["index.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport { withCIOAndroid } from './android/withCIOAndroid';\nimport { withCIOIos } from './ios/withCIOIos';\nimport type { CustomerIOPluginOptions } from './types/cio-types';\n\n// Entry point for config plugin\nfunction withCustomerIOPlugin(\n config: ExpoConfig,\n props: CustomerIOPluginOptions\n) {\n if (props.ios) {\n config = withCIOIos(config, props.ios);\n }\n\n if (props.android) {\n config = withCIOAndroid(config, props.android);\n }\n\n return config;\n}\n\nexport default withCustomerIOPlugin;\n"],"mappings":"AAEA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,UAAU,QAAQ,kBAAkB;
|
|
1
|
+
{"version":3,"names":["withCIOAndroid","isExpoVersion53OrHigher","withCIOIos","validateNativeSDKConfig","withCustomerIOPlugin","config","props","Error","ios","android"],"sources":["index.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport { withCIOAndroid } from './android/withCIOAndroid';\nimport { isExpoVersion53OrHigher } from './ios/utils';\nimport { withCIOIos } from './ios/withCIOIos';\nimport type { CustomerIOPluginOptions } from './types/cio-types';\nimport { validateNativeSDKConfig } from './utils/validation';\n\n// Entry point for config plugin\nfunction withCustomerIOPlugin(\n config: ExpoConfig,\n props: CustomerIOPluginOptions\n) {\n // Check if config is being used with unsupported Expo version\n if (props.config && !isExpoVersion53OrHigher(config)) {\n throw new Error(\n 'CustomerIO auto initialization (config property) requires Expo SDK 53 or higher. ' +\n 'Please upgrade to Expo SDK 53+ or use manual initialization instead. ' +\n 'See documentation for manual setup instructions.'\n );\n }\n\n // Validate SDK config if provided\n if (props.config) {\n validateNativeSDKConfig(props.config);\n }\n\n if (props.ios) {\n config = withCIOIos(config, props.config, props.ios);\n }\n\n if (props.android) {\n config = withCIOAndroid(config, props.config, props.android);\n }\n\n return config;\n}\n\nexport default withCustomerIOPlugin;\n"],"mappings":"AAEA,SAASA,cAAc,QAAQ,0BAA0B;AACzD,SAASC,uBAAuB,QAAQ,aAAa;AACrD,SAASC,UAAU,QAAQ,kBAAkB;AAE7C,SAASC,uBAAuB,QAAQ,oBAAoB;;AAE5D;AACA,SAASC,oBAAoBA,CAC3BC,MAAkB,EAClBC,KAA8B,EAC9B;EACA;EACA,IAAIA,KAAK,CAACD,MAAM,IAAI,CAACJ,uBAAuB,CAACI,MAAM,CAAC,EAAE;IACpD,MAAM,IAAIE,KAAK,CACb,mFAAmF,GACnF,uEAAuE,GACvE,kDACF,CAAC;EACH;;EAEA;EACA,IAAID,KAAK,CAACD,MAAM,EAAE;IAChBF,uBAAuB,CAACG,KAAK,CAACD,MAAM,CAAC;EACvC;EAEA,IAAIC,KAAK,CAACE,GAAG,EAAE;IACbH,MAAM,GAAGH,UAAU,CAACG,MAAM,EAAEC,KAAK,CAACD,MAAM,EAAEC,KAAK,CAACE,GAAG,CAAC;EACtD;EAEA,IAAIF,KAAK,CAACG,OAAO,EAAE;IACjBJ,MAAM,GAAGL,cAAc,CAACK,MAAM,EAAEC,KAAK,CAACD,MAAM,EAAEC,KAAK,CAACG,OAAO,CAAC;EAC9D;EAEA,OAAOJ,MAAM;AACf;AAEA,eAAeD,oBAAoB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["semver","isFcmPushProvider","iosOptions","_iosOptions$pushNotif","pushNotification","provider","isExpoVersion53OrHigher","config","sdkVersion","validVersion","valid","coerce","gte"],"sources":["utils.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"names":["semver","isFcmPushProvider","iosOptions","_iosOptions$pushNotif","pushNotification","provider","isExpoVersion53OrHigher","config","sdkVersion","validVersion","valid","coerce","gte"],"sources":["utils.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\nimport * as semver from 'semver';\nimport type { CustomerIOPluginOptionsIOS } from '../types/cio-types';\n\n/**\n * Returns true if FCM is configured to be used as push provider\n * @param iosOptions The plugin iOS configuration options\n * @returns true if FCM is configured to be used as push provider\n */\nexport const isFcmPushProvider = (\n iosOptions?: CustomerIOPluginOptionsIOS\n): boolean => {\n return iosOptions?.pushNotification?.provider === 'fcm';\n};\n\nexport const isExpoVersion53OrHigher = (config: ExpoConfig): boolean => {\n const sdkVersion = config.sdkVersion || '';\n\n // If sdkVersion is not a valid semver, coerce it to a valid one if possible\n const validVersion = semver.valid(sdkVersion) || semver.coerce(sdkVersion);\n\n // If we couldn't get a valid version, return false\n if (!validVersion) return false;\n\n // Check if the version is greater than or equal to 53.0.0\n return semver.gte(validVersion, '53.0.0');\n};\n"],"mappings":"AACA,OAAO,KAAKA,MAAM,MAAM,QAAQ;AAGhC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAC5BC,UAAuC,IAC3B;EAAA,IAAAC,qBAAA;EACZ,OAAO,CAAAD,UAAU,aAAVA,UAAU,gBAAAC,qBAAA,GAAVD,UAAU,CAAEE,gBAAgB,cAAAD,qBAAA,uBAA5BA,qBAAA,CAA8BE,QAAQ,MAAK,KAAK;AACzD,CAAC;AAED,OAAO,MAAMC,uBAAuB,GAAIC,MAAkB,IAAc;EACtE,MAAMC,UAAU,GAAGD,MAAM,CAACC,UAAU,IAAI,EAAE;;EAE1C;EACA,MAAMC,YAAY,GAAGT,MAAM,CAACU,KAAK,CAACF,UAAU,CAAC,IAAIR,MAAM,CAACW,MAAM,CAACH,UAAU,CAAC;;EAE1E;EACA,IAAI,CAACC,YAAY,EAAE,OAAO,KAAK;;EAE/B;EACA,OAAOT,MAAM,CAACY,GAAG,CAACH,YAAY,EAAE,QAAQ,CAAC;AAC3C,CAAC","ignoreList":[]}
|
|
@@ -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_IMPORT_SNIPPET, CIO_APPDELEGATEHEADER_REGEX, CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET, CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET, CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET,
|
|
4
|
-
import { injectCodeBeforeMultiLineRegex, injectCodeByLineNumber, injectCodeByMultiLineRegex, injectCodeByMultiLineRegexAndReplaceLine,
|
|
3
|
+
import { CIO_APPDELEGATEDECLARATION_REGEX, CIO_APPDELEGATEHEADER_IMPORT_SNIPPET, CIO_APPDELEGATEHEADER_REGEX, CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET, CIO_CONFIGURECIOSDKPUSHNOTIFICATION_SNIPPET, CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET, CIO_DEEPLINK_COMMENT_REGEX, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX, CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET, CIO_DIDFINISHLAUNCHINGMETHOD_REGEX, CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX, CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET, CIO_INITIALIZECIOSDK_SNIPPET, CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX, CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET, CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET } from '../helpers/constants/ios';
|
|
4
|
+
import { injectCodeBeforeMultiLineRegex, injectCodeByLineNumber, injectCodeByMultiLineRegex, injectCodeByMultiLineRegexAndReplaceLine, matchRegexExists, replaceCodeByRegex } from '../helpers/utils/codeInjection';
|
|
5
5
|
import { FileManagement } from '../helpers/utils/fileManagement';
|
|
6
6
|
import { isFcmPushProvider } from './utils';
|
|
7
7
|
const addImport = (stringContents, appName) => {
|
|
@@ -85,7 +85,7 @@ const addHandleDeeplinkInKilledState = stringContents => {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// Check if the app delegate is using RCTBridge or LaunchOptions
|
|
88
|
-
let snippet
|
|
88
|
+
let snippet;
|
|
89
89
|
let regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;
|
|
90
90
|
if (matchRegexExists(stringContents, CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX)) {
|
|
91
91
|
snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;
|
|
@@ -1 +1 @@
|
|
|
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_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET","CIO_DEEPLINK_COMMENT_REGEX","CIO_INITIALIZECIOSDK_SNIPPET","injectCodeBeforeMultiLineRegex","injectCodeByLineNumber","injectCodeByMultiLineRegex","injectCodeByMultiLineRegexAndReplaceLine","replaceCodeByRegex","matchRegexExists","FileManagement","isFcmPushProvider","addImport","stringContents","appName","importRegex","addedImport","getImportSnippet","match","endOfMatchIndex","index","undefined","length","addNotificationHandlerDeclaration","addNotificationConfiguration","addInitializeNativeCioSdk","addHandleDeeplinkInKilledStateConfiguration","regex","addDidFailToRegisterForRemoteNotificationsWithError","addDidRegisterForRemoteNotificationsWithDeviceToken","addExpoNotificationsHeaderModification","addFirebaseDelegateForwardDeclarationIfNeeded","addAppdelegateHeaderModification","replace","interfaceDeclaration","_groupedDelegates","existingDelegates","includes","trim","addHandleDeeplinkInKilledState","snippet","withAppDelegateModifications","configOuter","props","config","modResults","contents","RegExp","modRequest","projectName","_props$pushNotificati","_props$pushNotificati2","headerPath","projectRoot","headerContent","read","write","pushNotification","disableNotificationRegistration","handleDeeplinkInKilledState","console","log"],"sources":["withAppDelegateModifications.ts"],"sourcesContent":["import type { ConfigPlugin } from '@expo/config-plugins';\nimport { 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_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,\n CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,\n CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET,\n CIO_DEEPLINK_COMMENT_REGEX,\n CIO_INITIALIZECIOSDK_SNIPPET,\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';\nimport { isFcmPushProvider } from './utils';\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 );\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 addInitializeNativeCioSdk = (stringContents: string) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_INITIALIZECIOSDK_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addHandleDeeplinkInKilledStateConfiguration = (\n stringContents: string,\n regex: RegExp\n) => {\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\n// Adds required import for Expo Notifications package in AppDelegate.\n// Required to call functions from the package.\nconst addExpoNotificationsHeaderModification = (stringContents: string) => {\n stringContents = injectCodeByLineNumber(\n stringContents,\n 0,\n `\n#if __has_include(<EXNotifications/EXNotificationCenterDelegate.h>)\n#import <EXNotifications/EXNotificationCenterDelegate.h>\n#endif\n`\n );\n\n return stringContents;\n};\n\nconst addFirebaseDelegateForwardDeclarationIfNeeded = (stringContents: string) => {\n stringContents = injectCodeByLineNumber(\n stringContents,\n 0,\n '@protocol FIRMessagingDelegate;'\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 (\n existingDelegates &&\n existingDelegates.includes(\n CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET\n )\n ) {\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 let snippet = undefined;\n let regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n if (\n matchRegexExists(\n stringContents,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX\n )\n ) {\n snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;\n regex = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n } else if (\n matchRegexExists(\n stringContents,\n CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX\n )\n ) {\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(\n stringContents,\n regex\n );\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 // unless this property is explicity set to true, push notification\n // registration will be added to the AppDelegate\n if (props.pushNotification?.disableNotificationRegistration !== true) {\n stringContents = addNotificationConfiguration(stringContents);\n }\n\n stringContents = addInitializeNativeCioSdk(stringContents);\n\n if (props.pushNotification?.handleDeeplinkInKilledState === true) {\n stringContents = addHandleDeeplinkInKilledState(stringContents);\n }\n\n stringContents =\n addDidFailToRegisterForRemoteNotificationsWithError(stringContents);\n stringContents =\n addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);\n\n if (isFcmPushProvider(props)) {\n stringContents = addFirebaseDelegateForwardDeclarationIfNeeded(stringContents);\n }\n\n stringContents = addExpoNotificationsHeaderModification(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":"AACA,SAASA,eAAe,QAAQ,sBAAsB;AACtD,SAASC,4BAA4B,QAAQ,sCAAsC;AAEnF,SACEC,gCAAgC,EAChCC,oCAAoC,EACpCC,2BAA2B,EAC3BC,sDAAsD,EACtDC,2CAA2C,EAC3CC,yCAAyC,EACzCC,4CAA4C,EAC5CC,0DAA0D,EAC1DC,4DAA4D,EAC5DC,kCAAkC,EAClCC,0DAA0D,EAC1DC,4DAA4D,EAC5DC,gDAAgD,EAChDC,8CAA8C,EAC9CC,yCAAyC,EACzCC,8CAA8C,EAC9CC,0BAA0B,EAC1BC,4BAA4B,QACvB,0BAA0B;AACjC,SACEC,8BAA8B,EAC9BC,sBAAsB,EACtBC,0BAA0B,EAC1BC,wCAAwC,EACxCC,kBAAkB,EAClBC,gBAAgB,QACX,gCAAgC;AACvC,SAASC,cAAc,QAAQ,iCAAiC;AAEhE,SAASC,iBAAiB,QAAQ,SAAS;AAE3C,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,KAAKC,SAAS,EAAE;IACvC;IACAF,eAAe,GAAG,CAAC;EACrB,CAAC,MAAM;IACL;IACAA,eAAe,GAAGD,KAAK,CAACE,KAAK,GAAGF,KAAK,CAAC,CAAC,CAAC,CAACI,MAAM;EACjD;EAEAT,cAAc,GAAGR,sBAAsB,CACrCQ,cAAc,EACdM,eAAe,EACfH,WACF,C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9C,cAAc,GAAG0B,8BAA8B,CAAC1B,cAAc,CAAC;MACjE;MAEAA,cAAc,GACZe,mDAAmD,CAACf,cAAc,CAAC;MACrEA,cAAc,GACZgB,mDAAmD,CAAChB,cAAc,CAAC;MAErE,IAAIF,iBAAiB,CAACgC,KAAK,CAAC,EAAE;QAC5B9B,cAAc,GAAGkB,6CAA6C,CAAClB,cAAc,CAAC;MAChF;MAEAA,cAAc,GAAGiB,sCAAsC,CAACjB,cAAc,CAAC;MAEvE+B,MAAM,CAACC,UAAU,CAACC,QAAQ,GAAGjC,cAAc;IAC7C,CAAC,MAAM;MACL+C,OAAO,CAACC,GAAG,CAAC,2DAA2D,CAAC;IAC1E;IAEA,OAAOjB,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AACD,SAAS3B,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAO;AACT;AACA;AACA,WAAWA,OAAO;AAClB,GAAG;AACH","ignoreList":[]}
|
|
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_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","CIO_DEEPLINK_COMMENT_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","CIO_DIDFINISHLAUNCHINGMETHOD_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","CIO_INITIALIZECIOSDK_SNIPPET","CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET","CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX","CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET","injectCodeBeforeMultiLineRegex","injectCodeByLineNumber","injectCodeByMultiLineRegex","injectCodeByMultiLineRegexAndReplaceLine","matchRegexExists","replaceCodeByRegex","FileManagement","isFcmPushProvider","addImport","stringContents","appName","importRegex","addedImport","getImportSnippet","match","endOfMatchIndex","index","undefined","length","addNotificationHandlerDeclaration","addNotificationConfiguration","addInitializeNativeCioSdk","addHandleDeeplinkInKilledStateConfiguration","regex","addDidFailToRegisterForRemoteNotificationsWithError","addDidRegisterForRemoteNotificationsWithDeviceToken","addExpoNotificationsHeaderModification","addFirebaseDelegateForwardDeclarationIfNeeded","addAppdelegateHeaderModification","replace","interfaceDeclaration","_groupedDelegates","existingDelegates","includes","trim","addHandleDeeplinkInKilledState","snippet","withAppDelegateModifications","configOuter","props","config","modResults","contents","RegExp","modRequest","projectName","_props$pushNotificati","_props$pushNotificati2","headerPath","projectRoot","headerContent","read","write","pushNotification","disableNotificationRegistration","handleDeeplinkInKilledState","console","log"],"sources":["withAppDelegateModifications.ts"],"sourcesContent":["import type { ConfigPlugin } from '@expo/config-plugins';\nimport { 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_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET,\n CIO_DEEPLINK_COMMENT_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX,\n CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX,\n CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET,\n CIO_INITIALIZECIOSDK_SNIPPET,\n CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_LAUNCHOPTIONS_MODIFIEDOPTIONS_SNIPPET,\n CIO_PUSHNOTIFICATIONHANDLERDECLARATION_SNIPPET,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET,\n} from '../helpers/constants/ios';\nimport {\n injectCodeBeforeMultiLineRegex,\n injectCodeByLineNumber,\n injectCodeByMultiLineRegex,\n injectCodeByMultiLineRegexAndReplaceLine,\n matchRegexExists,\n replaceCodeByRegex,\n} from '../helpers/utils/codeInjection';\nimport { FileManagement } from '../helpers/utils/fileManagement';\nimport type { CustomerIOPluginOptionsIOS } from '../types/cio-types';\nimport { isFcmPushProvider } from './utils';\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 );\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 addInitializeNativeCioSdk = (stringContents: string) => {\n stringContents = injectCodeBeforeMultiLineRegex(\n stringContents,\n CIO_DIDFINISHLAUNCHINGMETHOD_REGEX,\n CIO_INITIALIZECIOSDK_SNIPPET\n );\n\n return stringContents;\n};\n\nconst addHandleDeeplinkInKilledStateConfiguration = (\n stringContents: string,\n regex: RegExp\n) => {\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\n// Adds required import for Expo Notifications package in AppDelegate.\n// Required to call functions from the package.\nconst addExpoNotificationsHeaderModification = (stringContents: string) => {\n stringContents = injectCodeByLineNumber(\n stringContents,\n 0,\n `\n#if __has_include(<EXNotifications/EXNotificationCenterDelegate.h>)\n#import <EXNotifications/EXNotificationCenterDelegate.h>\n#endif\n`\n );\n\n return stringContents;\n};\n\nconst addFirebaseDelegateForwardDeclarationIfNeeded = (\n stringContents: string\n) => {\n stringContents = injectCodeByLineNumber(\n stringContents,\n 0,\n '@protocol FIRMessagingDelegate;'\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 (\n existingDelegates &&\n existingDelegates.includes(\n CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET\n )\n ) {\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 let snippet;\n let regex = CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n if (\n matchRegexExists(\n stringContents,\n CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX\n )\n ) {\n snippet = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_SNIPPET;\n regex = CIO_RCTBRIDGE_DEEPLINK_MODIFIEDOPTIONS_REGEX;\n } else if (\n matchRegexExists(\n stringContents,\n CIO_LAUNCHOPTIONS_DEEPLINK_MODIFIEDOPTIONS_REGEX\n )\n ) {\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(\n stringContents,\n regex\n );\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 // unless this property is explicity set to true, push notification\n // registration will be added to the AppDelegate\n if (props.pushNotification?.disableNotificationRegistration !== true) {\n stringContents = addNotificationConfiguration(stringContents);\n }\n\n stringContents = addInitializeNativeCioSdk(stringContents);\n\n if (props.pushNotification?.handleDeeplinkInKilledState === true) {\n stringContents = addHandleDeeplinkInKilledState(stringContents);\n }\n\n stringContents =\n addDidFailToRegisterForRemoteNotificationsWithError(stringContents);\n stringContents =\n addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);\n\n if (isFcmPushProvider(props)) {\n stringContents =\n addFirebaseDelegateForwardDeclarationIfNeeded(stringContents);\n }\n\n stringContents = addExpoNotificationsHeaderModification(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 <Exp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AmD,CAAChB,cAAc,CAAC;MAErE,IAAIF,iBAAiB,CAACgC,KAAK,CAAC,EAAE;QAC5B9B,cAAc,GACZkB,6CAA6C,CAAClB,cAAc,CAAC;MACjE;MAEAA,cAAc,GAAGiB,sCAAsC,CAACjB,cAAc,CAAC;MAEvE+B,MAAM,CAACC,UAAU,CAACC,QAAQ,GAAGjC,cAAc;IAC7C,CAAC,MAAM;MACL+C,OAAO,CAACC,GAAG,CAAC,2DAA2D,CAAC;IAC1E;IAEA,OAAOjB,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AACD,SAAS3B,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAO;AACT;AACA;AACA,WAAWA,OAAO;AAClB,GAAG;AACH","ignoreList":[]}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
import { mergeConfigWithEnvValues } from '../utils/config';
|
|
2
|
+
import { isExpoVersion53OrHigher } from './utils';
|
|
1
3
|
import { withAppDelegateModifications } from './withAppDelegateModifications';
|
|
4
|
+
import { withCIOIosSwift } from './withCIOIosSwift';
|
|
5
|
+
import { withGoogleServicesJsonFile } from './withGoogleServicesJsonFile';
|
|
2
6
|
import { withCioNotificationsXcodeProject } from './withNotificationsXcodeProject';
|
|
3
7
|
import { withCioXcodeProject } from './withXcodeProject';
|
|
4
|
-
|
|
5
|
-
import { withCIOIosSwift } from './withCIOIosSwift';
|
|
6
|
-
import { isExpoVersion53OrHigher } from './utils';
|
|
7
|
-
export function withCIOIos(config, props) {
|
|
8
|
-
const cioProps = mergeDeprecatedPropertiesAndLogWarnings(props);
|
|
8
|
+
export function withCIOIos(config, sdkConfig, props) {
|
|
9
9
|
const isSwiftProject = isExpoVersion53OrHigher(config);
|
|
10
|
-
|
|
10
|
+
const platformConfig = mergeDeprecatedPropertiesAndLogWarnings(props);
|
|
11
|
+
if (platformConfig.pushNotification) {
|
|
11
12
|
if (isSwiftProject) {
|
|
12
|
-
config = withCIOIosSwift(config,
|
|
13
|
+
config = withCIOIosSwift(config, sdkConfig, platformConfig);
|
|
13
14
|
} else {
|
|
14
|
-
|
|
15
|
+
// Auto initialization is only supported in Swift projects (Expo SDK 53+)
|
|
16
|
+
// Legacy Objective-C projects only support push notifications
|
|
17
|
+
config = withAppDelegateModifications(config, platformConfig);
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
config =
|
|
18
|
-
config =
|
|
19
|
+
platformConfig.pushNotification.env = platformConfig.pushNotification.env || mergeConfigWithEnvValues(platformConfig, sdkConfig);
|
|
20
|
+
config = withCioNotificationsXcodeProject(config, platformConfig);
|
|
21
|
+
config = withCioXcodeProject(config, platformConfig);
|
|
22
|
+
config = withGoogleServicesJsonFile(config, platformConfig);
|
|
23
|
+
} else if (sdkConfig && isSwiftProject) {
|
|
24
|
+
config = withCIOIosSwift(config, sdkConfig, platformConfig);
|
|
19
25
|
}
|
|
20
26
|
return config;
|
|
21
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["mergeConfigWithEnvValues","isExpoVersion53OrHigher","withAppDelegateModifications","withCIOIosSwift","withGoogleServicesJsonFile","withCioNotificationsXcodeProject","withCioXcodeProject","withCIOIos","config","sdkConfig","props","isSwiftProject","platformConfig","mergeDeprecatedPropertiesAndLogWarnings","pushNotification","env","deprecatedTopLevelProperties","showPushAppInForeground","autoTrackPushEvents","handleDeeplinkInKilledState","disableNotificationRegistration","autoFetchDeviceToken","Object","entries","forEach","key","value","undefined","console","warn","propKey"],"sources":["withCIOIos.ts"],"sourcesContent":["import type { ExpoConfig } from '@expo/config-types';\n\nimport type {\n CustomerIOPluginOptionsIOS,\n CustomerIOPluginPushNotificationOptions,\n NativeSDKConfig,\n} from '../types/cio-types';\nimport { mergeConfigWithEnvValues } from '../utils/config';\nimport { isExpoVersion53OrHigher } from './utils';\nimport { withAppDelegateModifications } from './withAppDelegateModifications';\nimport { withCIOIosSwift } from './withCIOIosSwift';\nimport { withGoogleServicesJsonFile } from './withGoogleServicesJsonFile';\nimport { withCioNotificationsXcodeProject } from './withNotificationsXcodeProject';\nimport { withCioXcodeProject } from './withXcodeProject';\n\nexport function withCIOIos(\n config: ExpoConfig,\n sdkConfig: NativeSDKConfig | undefined,\n props: CustomerIOPluginOptionsIOS\n) {\n const isSwiftProject = isExpoVersion53OrHigher(config);\n const platformConfig = mergeDeprecatedPropertiesAndLogWarnings(props);\n\n if (platformConfig.pushNotification) {\n if (isSwiftProject) {\n config = withCIOIosSwift(config, sdkConfig, platformConfig);\n } else {\n // Auto initialization is only supported in Swift projects (Expo SDK 53+)\n // Legacy Objective-C projects only support push notifications\n config = withAppDelegateModifications(config, platformConfig);\n }\n\n platformConfig.pushNotification.env = platformConfig.pushNotification.env\n || mergeConfigWithEnvValues(platformConfig, sdkConfig);\n config = withCioNotificationsXcodeProject(config, platformConfig);\n config = withCioXcodeProject(config, platformConfig);\n config = withGoogleServicesJsonFile(config, platformConfig);\n } else if (sdkConfig && isSwiftProject) {\n config = withCIOIosSwift(config, sdkConfig, platformConfig);\n }\n\n return config;\n}\n\n/** The basic purpose of this function is to centralize where we handle the deprecation\n by merging the deprecated properties into the new ios.pushNotification.* properties\n and logging a warning if they are set. This way, we can remove the deprecated properties\n from the top level of the ios object in the future, and update this function\n while the rest of the plugin code remains unchanged.\n*/\nconst mergeDeprecatedPropertiesAndLogWarnings = (\n props: CustomerIOPluginOptionsIOS\n) => {\n // The deprecatedTopLevelProperties maps the top level properties\n // that are deprecated to the new ios.pushNotification.* properties\n // that should be used instead. The deprecated properties are\n // still available for backwards compatibility, but they will\n // be removed in the future.\n\n const deprecatedTopLevelProperties = {\n showPushAppInForeground: props.showPushAppInForeground,\n autoTrackPushEvents: props.autoTrackPushEvents,\n handleDeeplinkInKilledState: props.handleDeeplinkInKilledState,\n disableNotificationRegistration: props.disableNotificationRegistration,\n autoFetchDeviceToken: props.autoFetchDeviceToken,\n };\n\n // loop over all the deprecated properties and log a warning if they are set\n Object.entries(deprecatedTopLevelProperties).forEach(([key, value]) => {\n if (value !== undefined) {\n console.warn(\n `The ios.${key} property is deprecated. Please use ios.pushNotification.${key} instead.`\n );\n\n if (props.pushNotification === undefined) {\n props.pushNotification = {} as CustomerIOPluginPushNotificationOptions;\n }\n const propKey = key as keyof CustomerIOPluginPushNotificationOptions;\n if (props.pushNotification[propKey] === undefined) {\n props.pushNotification = {\n ...props.pushNotification,\n [propKey]: value,\n };\n } else {\n console.warn(\n `The ios.${key} property is deprecated. Since the value of ios.pushNotification.${key} is set, it will be used.`\n );\n }\n }\n });\n\n return props;\n};\n"],"mappings":"AAOA,SAASA,wBAAwB,QAAQ,iBAAiB;AAC1D,SAASC,uBAAuB,QAAQ,SAAS;AACjD,SAASC,4BAA4B,QAAQ,gCAAgC;AAC7E,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,0BAA0B,QAAQ,8BAA8B;AACzE,SAASC,gCAAgC,QAAQ,iCAAiC;AAClF,SAASC,mBAAmB,QAAQ,oBAAoB;AAExD,OAAO,SAASC,UAAUA,CACxBC,MAAkB,EAClBC,SAAsC,EACtCC,KAAiC,EACjC;EACA,MAAMC,cAAc,GAAGV,uBAAuB,CAACO,MAAM,CAAC;EACtD,MAAMI,cAAc,GAAGC,uCAAuC,CAACH,KAAK,CAAC;EAErE,IAAIE,cAAc,CAACE,gBAAgB,EAAE;IACnC,IAAIH,cAAc,EAAE;MAClBH,MAAM,GAAGL,eAAe,CAACK,MAAM,EAAEC,SAAS,EAAEG,cAAc,CAAC;IAC7D,CAAC,MAAM;MACL;MACA;MACAJ,MAAM,GAAGN,4BAA4B,CAACM,MAAM,EAAEI,cAAc,CAAC;IAC/D;IAEAA,cAAc,CAACE,gBAAgB,CAACC,GAAG,GAAGH,cAAc,CAACE,gBAAgB,CAACC,GAAG,IACpEf,wBAAwB,CAACY,cAAc,EAAEH,SAAS,CAAC;IACxDD,MAAM,GAAGH,gCAAgC,CAACG,MAAM,EAAEI,cAAc,CAAC;IACjEJ,MAAM,GAAGF,m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F,CAAC;MACH;IACF;EACF,CAAC,CAAC;EAEF,OAAOf,KAAK;AACd,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { withAppDelegate, withXcodeProject } from '@expo/config-plugins';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PLATFORM } from '../helpers/constants/common';
|
|
4
|
+
import { CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET, CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX, CIO_NATIVE_SDK_INITIALIZE_CALL, CIO_NATIVE_SDK_INITIALIZE_SNIPPET, CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2, CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER } from '../helpers/constants/ios';
|
|
5
5
|
import { replaceCodeByRegex } from '../helpers/utils/codeInjection';
|
|
6
|
+
import { FileManagement } from '../helpers/utils/fileManagement';
|
|
7
|
+
import { patchNativeSDKInitializer } from '../helpers/utils/patchPluginNativeCode';
|
|
8
|
+
import { getIosNativeFilesPath } from '../utils/plugin';
|
|
9
|
+
import { copyFileToXcode, getOrCreateCustomerIOGroup } from '../utils/xcode';
|
|
6
10
|
import { isFcmPushProvider } from './utils';
|
|
7
11
|
|
|
8
12
|
// Constants
|
|
@@ -12,39 +16,56 @@ const CIO_SDK_APP_DELEGATE_HANDLER_FILENAME = `${CIO_SDK_APP_DELEGATE_HANDLER_CL
|
|
|
12
16
|
/**
|
|
13
17
|
* Copy and configure the CioSdkAppDelegateHandler.swift file
|
|
14
18
|
*/
|
|
15
|
-
const copyAndConfigureAppDelegateHandler = (config, props) => {
|
|
16
|
-
var _props$pushNotificati, _props$pushNotificati2, _props$pushNotificati3, _props$pushNotificati4;
|
|
17
|
-
const projectRoot = config.modRequest.projectRoot;
|
|
18
|
-
const iosProjectRoot = path.join(projectRoot, 'ios');
|
|
19
|
-
const useFcm = isFcmPushProvider(props);
|
|
20
|
-
|
|
21
|
-
// Source path for the handler file
|
|
22
|
-
const handlerSourcePath = path.join(LOCAL_PATH_TO_CIO_NSE_FILES, useFcm ? 'fcm' : 'apn', CIO_SDK_APP_DELEGATE_HANDLER_FILENAME);
|
|
23
|
-
|
|
19
|
+
const copyAndConfigureAppDelegateHandler = (config, sdkConfig, props) => {
|
|
24
20
|
// Destination path in the iOS project
|
|
25
21
|
const projectName = config.modRequest.projectName || '';
|
|
26
22
|
if (!projectName) {
|
|
27
|
-
console.warn('Project name is undefined, cannot copy
|
|
23
|
+
console.warn('Project name is undefined, cannot copy CustomerIO files');
|
|
28
24
|
return config;
|
|
29
25
|
}
|
|
30
|
-
const handlerDestPath = path.join(iosProjectRoot, projectName, CIO_SDK_APP_DELEGATE_HANDLER_FILENAME);
|
|
31
|
-
FileManagement.copyFile(handlerSourcePath, handlerDestPath);
|
|
32
26
|
|
|
33
|
-
// Add
|
|
27
|
+
// Add files to the Xcode project
|
|
34
28
|
const xcodeProject = config.modResults;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
const projectRoot = config.modRequest.projectRoot;
|
|
30
|
+
const iosProjectRoot = path.join(projectRoot, 'ios');
|
|
31
|
+
const group = getOrCreateCustomerIOGroup(xcodeProject, projectName);
|
|
32
|
+
if (props.pushNotification) {
|
|
33
|
+
// Copy CioSdkAppDelegateHandler.swift for full push notification + auto-init support
|
|
34
|
+
copyAndConfigurePushAppDelegateHandler({
|
|
35
|
+
xcodeProject,
|
|
36
|
+
group,
|
|
37
|
+
iosProjectRoot,
|
|
38
|
+
projectName,
|
|
39
|
+
sdkConfig,
|
|
40
|
+
props
|
|
41
|
+
});
|
|
42
|
+
} else if (sdkConfig) {
|
|
43
|
+
// Copy only CustomerIOSDKInitializer.swift for auto-init without push notifications
|
|
44
|
+
copyAndConfigureNativeSDKInitializer({
|
|
45
|
+
xcodeProject,
|
|
46
|
+
group,
|
|
47
|
+
iosProjectRoot,
|
|
48
|
+
projectName,
|
|
49
|
+
sdkConfig
|
|
45
50
|
});
|
|
46
|
-
xcodeProject.addToPbxGroup(group, classesKey);
|
|
47
51
|
}
|
|
52
|
+
return config;
|
|
53
|
+
};
|
|
54
|
+
const copyAndConfigurePushAppDelegateHandler = ({
|
|
55
|
+
xcodeProject,
|
|
56
|
+
group,
|
|
57
|
+
iosProjectRoot,
|
|
58
|
+
projectName,
|
|
59
|
+
sdkConfig,
|
|
60
|
+
props
|
|
61
|
+
}) => {
|
|
62
|
+
var _props$pushNotificati, _props$pushNotificati2, _props$pushNotificati3, _props$pushNotificati4;
|
|
63
|
+
const useFcm = isFcmPushProvider(props);
|
|
64
|
+
|
|
65
|
+
// Source path for the handler file
|
|
66
|
+
const handlerSourcePath = path.join(getIosNativeFilesPath(), useFcm ? 'fcm' : 'apn', CIO_SDK_APP_DELEGATE_HANDLER_FILENAME);
|
|
67
|
+
const handlerDestPath = path.join(iosProjectRoot, projectName, CIO_SDK_APP_DELEGATE_HANDLER_FILENAME);
|
|
68
|
+
FileManagement.copyFile(handlerSourcePath, handlerDestPath);
|
|
48
69
|
|
|
49
70
|
// Add the file to the Xcode project
|
|
50
71
|
xcodeProject.addSourceFile(`${projectName}/${CIO_SDK_APP_DELEGATE_HANDLER_FILENAME}`, null, group);
|
|
@@ -63,25 +84,69 @@ const copyAndConfigureAppDelegateHandler = (config, props) => {
|
|
|
63
84
|
handlerFileContent = replaceCodeByRegex(handlerFileContent, /\{\{AUTO_FETCH_DEVICE_TOKEN\}\}/, autoFetchDeviceToken.toString());
|
|
64
85
|
const showPushAppInForeground = ((_props$pushNotificati4 = props.pushNotification) === null || _props$pushNotificati4 === void 0 ? void 0 : _props$pushNotificati4.showPushAppInForeground) !== false;
|
|
65
86
|
handlerFileContent = replaceCodeByRegex(handlerFileContent, /\{\{SHOW_PUSH_APP_IN_FOREGROUND\}\}/, showPushAppInForeground.toString());
|
|
87
|
+
|
|
88
|
+
// Add auto initialization if sdkConfig is provided
|
|
89
|
+
if (sdkConfig) {
|
|
90
|
+
// Also copy CustomerIOSDKInitializer.swift for auto-initialization
|
|
91
|
+
copyAndConfigureNativeSDKInitializer({
|
|
92
|
+
xcodeProject,
|
|
93
|
+
group,
|
|
94
|
+
iosProjectRoot,
|
|
95
|
+
projectName,
|
|
96
|
+
sdkConfig
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Inject auto initialization call before MessagingPush initialization
|
|
100
|
+
handlerFileContent = handlerFileContent.replace(CIO_MESSAGING_PUSH_APP_DELEGATE_INIT_REGEX, CIO_NATIVE_SDK_INITIALIZE_SNIPPET + '$1');
|
|
101
|
+
}
|
|
66
102
|
FileManagement.writeFile(handlerDestPath, handlerFileContent);
|
|
67
|
-
return config;
|
|
68
103
|
};
|
|
69
|
-
|
|
70
|
-
|
|
104
|
+
const copyAndConfigureNativeSDKInitializer = ({
|
|
105
|
+
xcodeProject,
|
|
106
|
+
group,
|
|
107
|
+
iosProjectRoot,
|
|
108
|
+
projectName,
|
|
109
|
+
sdkConfig
|
|
110
|
+
}) => {
|
|
111
|
+
const filename = 'CustomerIOSDKInitializer.swift';
|
|
112
|
+
const sourcePath = path.join(getIosNativeFilesPath(), filename);
|
|
113
|
+
// Add the CustomerIOSDKInitializer.swift file to the same Xcode group as CioSdkAppDelegateHandler
|
|
114
|
+
copyFileToXcode({
|
|
115
|
+
xcodeProject,
|
|
116
|
+
iosProjectRoot,
|
|
117
|
+
projectName,
|
|
118
|
+
sourceFilePath: sourcePath,
|
|
119
|
+
targetFileName: filename,
|
|
120
|
+
transform: content => patchNativeSDKInitializer(content, PLATFORM.IOS, sdkConfig),
|
|
121
|
+
customerIOGroup: group
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
export const withCIOIosSwift = (configOuter, sdkConfig, props) => {
|
|
125
|
+
// First, copy required swift files to iOS folder and add it to Xcode project
|
|
71
126
|
configOuter = withXcodeProject(configOuter, async config => {
|
|
72
|
-
return copyAndConfigureAppDelegateHandler(config, props);
|
|
127
|
+
return copyAndConfigureAppDelegateHandler(config, sdkConfig, props);
|
|
73
128
|
});
|
|
74
129
|
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
130
|
+
// Modify the AppDelegate based on configuration
|
|
131
|
+
if (props.pushNotification) {
|
|
132
|
+
// With push notifications: delegate to CioSdkAppDelegateHandler for both push and auto-init
|
|
133
|
+
return withAppDelegate(configOuter, async config => {
|
|
134
|
+
return modifyAppDelegateWithPushAppDelegateHandler(config, props);
|
|
135
|
+
});
|
|
136
|
+
} else if (sdkConfig) {
|
|
137
|
+
// Without push notifications: directly inject auto initialization into AppDelegate
|
|
138
|
+
return withAppDelegate(configOuter, async config => {
|
|
139
|
+
return modifyAppDelegateWithNativeSDKInitializer(config);
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
return configOuter;
|
|
143
|
+
}
|
|
79
144
|
};
|
|
80
145
|
|
|
81
146
|
/**
|
|
82
147
|
* Modify the AppDelegate to integrate with Customer.io SDK
|
|
83
148
|
*/
|
|
84
|
-
const
|
|
149
|
+
const modifyAppDelegateWithPushAppDelegateHandler = (config, props) => {
|
|
85
150
|
var _props$pushNotificati5;
|
|
86
151
|
const appDelegateContent = config.modResults.contents;
|
|
87
152
|
|
|
@@ -95,7 +160,7 @@ const modifyAppDelegate = (config, props) => {
|
|
|
95
160
|
let modifiedContent = addHandlerPropertyDeclaration(appDelegateContent);
|
|
96
161
|
|
|
97
162
|
// Modify didFinishLaunchingWithOptions to initialize and call the handler
|
|
98
|
-
modifiedContent = modifyDidFinishLaunchingWithOptions(modifiedContent);
|
|
163
|
+
modifiedContent = modifyDidFinishLaunchingWithOptions(modifiedContent, ` cioSdkHandler.application(application, didFinishLaunchingWithOptions: launchOptions)\n\n `);
|
|
99
164
|
|
|
100
165
|
// Add didRegisterForRemoteNotificationsWithDeviceToken implementation
|
|
101
166
|
modifiedContent = addDidRegisterForRemoteNotificationsWithDeviceToken(modifiedContent);
|
|
@@ -111,6 +176,26 @@ const modifyAppDelegate = (config, props) => {
|
|
|
111
176
|
return config;
|
|
112
177
|
};
|
|
113
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Modify the AppDelegate to integrate with Customer.io SDK
|
|
181
|
+
*/
|
|
182
|
+
const modifyAppDelegateWithNativeSDKInitializer = (config
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
) => {
|
|
185
|
+
const appDelegateContent = config.modResults.contents;
|
|
186
|
+
|
|
187
|
+
// Check if modifications have already been applied
|
|
188
|
+
if (appDelegateContent.includes(CIO_NATIVE_SDK_INITIALIZE_CALL)) {
|
|
189
|
+
console.log('CustomerIO Swift AppDelegate changes already exist. Skipping...');
|
|
190
|
+
return config;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Modify didFinishLaunchingWithOptions to initialize and call the handler
|
|
194
|
+
const modifiedContent = modifyDidFinishLaunchingWithOptions(appDelegateContent, CIO_NATIVE_SDK_INITIALIZE_SNIPPET);
|
|
195
|
+
config.modResults.contents = modifiedContent;
|
|
196
|
+
return config;
|
|
197
|
+
};
|
|
198
|
+
|
|
114
199
|
/**
|
|
115
200
|
* Check if a method exists in the AppDelegate content
|
|
116
201
|
* @param content The AppDelegate content
|
|
@@ -134,15 +219,15 @@ const addHandlerPropertyDeclaration = content => {
|
|
|
134
219
|
console.warn('Could not find AppDelegate class declaration');
|
|
135
220
|
return content;
|
|
136
221
|
}
|
|
137
|
-
const position = match.index + match[0].length;
|
|
222
|
+
const position = (match.index ?? 0) + match[0].length;
|
|
138
223
|
return content.substring(0, position) + `\n let cioSdkHandler = ${CIO_SDK_APP_DELEGATE_HANDLER_CLASS}()\n` + content.substring(position);
|
|
139
224
|
};
|
|
140
225
|
|
|
141
226
|
/**
|
|
142
|
-
* Modify didFinishLaunchingWithOptions to
|
|
143
|
-
*
|
|
227
|
+
* Modify didFinishLaunchingWithOptions to inject Customer.io code
|
|
228
|
+
* Injects the provided code (either handler call or auto initialization) before the return statement
|
|
144
229
|
*/
|
|
145
|
-
const modifyDidFinishLaunchingWithOptions = content => {
|
|
230
|
+
const modifyDidFinishLaunchingWithOptions = (content, codeToInject) => {
|
|
146
231
|
// Find the return statement in didFinishLaunchingWithOptions
|
|
147
232
|
// Always look for launchOptions since modifiedLaunchOptions is only set later
|
|
148
233
|
const returnStatementRegex = /return\s+super\.application\s*\(\s*application\s*,\s*didFinishLaunchingWithOptions\s*:\s*launchOptions\s*\)/;
|
|
@@ -152,10 +237,9 @@ const modifyDidFinishLaunchingWithOptions = content => {
|
|
|
152
237
|
return content;
|
|
153
238
|
}
|
|
154
239
|
|
|
155
|
-
//
|
|
156
|
-
const insertPosition = returnStatementMatch.index;
|
|
157
|
-
|
|
158
|
-
return content.substring(0, insertPosition) + handlerCallCode + content.substring(insertPosition);
|
|
240
|
+
// Inject Customer.io code before the return statement
|
|
241
|
+
const insertPosition = returnStatementMatch.index ?? 0;
|
|
242
|
+
return content.substring(0, insertPosition) + codeToInject + content.substring(insertPosition);
|
|
159
243
|
};
|
|
160
244
|
|
|
161
245
|
/**
|
|
@@ -190,7 +274,7 @@ const addDidRegisterForRemoteNotificationsWithDeviceToken = content => {
|
|
|
190
274
|
}
|
|
191
275
|
|
|
192
276
|
// Insert the method inside the class
|
|
193
|
-
const position = classEndMatch.index;
|
|
277
|
+
const position = classEndMatch.index ?? 0;
|
|
194
278
|
return content.substring(0, position) + '\n // Handle device token registration\n' + ' public override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\n' + ' // Call CustomerIO SDK handler\n' + ' cioSdkHandler.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\n' + ' super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)\n' + ' }\n' + content.substring(position);
|
|
195
279
|
}
|
|
196
280
|
};
|
|
@@ -227,7 +311,7 @@ const addDidFailToRegisterForRemoteNotificationsWithError = content => {
|
|
|
227
311
|
}
|
|
228
312
|
|
|
229
313
|
// Insert the method inside the class
|
|
230
|
-
const position = classEndMatch.index;
|
|
314
|
+
const position = classEndMatch.index ?? 0;
|
|
231
315
|
return content.substring(0, position) + '\n // Handle remote notification registration errors\n' + ' public override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {\n' + ' // Call CustomerIO SDK handler\n' + ' cioSdkHandler.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\n' + ' super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)\n' + ' }\n' + content.substring(position);
|
|
232
316
|
}
|
|
233
317
|
};
|
|
@@ -239,7 +323,7 @@ const addDidFailToRegisterForRemoteNotificationsWithError = content => {
|
|
|
239
323
|
*/
|
|
240
324
|
const addHandleDeeplinkInKilledState = content => {
|
|
241
325
|
// Check if deep link code snippet is already present
|
|
242
|
-
const deepLinkMarker =
|
|
326
|
+
const deepLinkMarker = 'Deep link workaround for app killed state start';
|
|
243
327
|
if (content.includes(deepLinkMarker)) {
|
|
244
328
|
return content;
|
|
245
329
|
}
|
|
@@ -248,13 +332,13 @@ const addHandleDeeplinkInKilledState = content => {
|
|
|
248
332
|
const returnStatementRegex = /return\s+super\.application\s*\(\s*application\s*,\s*didFinishLaunchingWithOptions\s*:\s*launchOptions\s*\)/;
|
|
249
333
|
const returnStatementMatch = content.match(returnStatementRegex);
|
|
250
334
|
if (!returnStatementMatch) {
|
|
251
|
-
console.warn(
|
|
335
|
+
console.warn('Could not find return statement with launchOptions');
|
|
252
336
|
return content;
|
|
253
337
|
}
|
|
254
338
|
|
|
255
339
|
// Create the replacement code with deep link handling and modified return statement
|
|
256
|
-
const modifiedReturnStatement =
|
|
257
|
-
const replacementCode = CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET +
|
|
340
|
+
const modifiedReturnStatement = 'return super.application(application, didFinishLaunchingWithOptions: modifiedLaunchOptions)';
|
|
341
|
+
const replacementCode = CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET + '\n\n ' + modifiedReturnStatement;
|
|
258
342
|
|
|
259
343
|
// Replace the return statement with deep link handling code and modified return statement
|
|
260
344
|
return content.replace(returnStatementRegex, replacementCode);
|