customerio-expo-plugin 3.4.0 → 3.5.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 +2 -1
- package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js +64 -59
- package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js.map +1 -1
- package/plugin/lib/commonjs/android/withAppGoogleServices.js +10 -7
- package/plugin/lib/commonjs/android/withAppGoogleServices.js.map +1 -1
- package/plugin/lib/commonjs/android/withGoogleServicesJSON.js +18 -21
- package/plugin/lib/commonjs/android/withGoogleServicesJSON.js.map +1 -1
- package/plugin/lib/commonjs/android/withLocationGradleProperties.js +16 -12
- package/plugin/lib/commonjs/android/withLocationGradleProperties.js.map +1 -1
- package/plugin/lib/commonjs/android/withMainApplicationModifications.js +19 -12
- package/plugin/lib/commonjs/android/withMainApplicationModifications.js.map +1 -1
- package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js +2 -1
- package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js.map +1 -1
- package/plugin/lib/commonjs/android/withProjectBuildGradle.js +29 -25
- package/plugin/lib/commonjs/android/withProjectBuildGradle.js.map +1 -1
- package/plugin/lib/commonjs/android/withProjectGoogleServices.js +9 -5
- package/plugin/lib/commonjs/android/withProjectGoogleServices.js.map +1 -1
- package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js +63 -31
- package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
- package/plugin/lib/commonjs/ios/withAppDelegateModifications.js +47 -33
- package/plugin/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
- package/plugin/lib/commonjs/ios/withCIOIosSwift.js +26 -42
- package/plugin/lib/commonjs/ios/withCIOIosSwift.js.map +1 -1
- package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js +46 -30
- package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js.map +1 -1
- package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js +192 -122
- package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
- package/plugin/lib/module/android/withAndroidManifestUpdates.js +61 -58
- package/plugin/lib/module/android/withAndroidManifestUpdates.js.map +1 -1
- package/plugin/lib/module/android/withAppGoogleServices.js +9 -7
- package/plugin/lib/module/android/withAppGoogleServices.js.map +1 -1
- package/plugin/lib/module/android/withGoogleServicesJSON.js +17 -21
- package/plugin/lib/module/android/withGoogleServicesJSON.js.map +1 -1
- package/plugin/lib/module/android/withLocationGradleProperties.js +15 -12
- package/plugin/lib/module/android/withLocationGradleProperties.js.map +1 -1
- package/plugin/lib/module/android/withMainApplicationModifications.js +18 -12
- package/plugin/lib/module/android/withMainApplicationModifications.js.map +1 -1
- package/plugin/lib/module/android/withNotificationChannelMetadata.js +1 -1
- package/plugin/lib/module/android/withNotificationChannelMetadata.js.map +1 -1
- package/plugin/lib/module/android/withProjectBuildGradle.js +28 -25
- package/plugin/lib/module/android/withProjectBuildGradle.js.map +1 -1
- package/plugin/lib/module/android/withProjectGoogleServices.js +8 -5
- package/plugin/lib/module/android/withProjectGoogleServices.js.map +1 -1
- package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js +61 -31
- package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
- package/plugin/lib/module/ios/withAppDelegateModifications.js +45 -33
- package/plugin/lib/module/ios/withAppDelegateModifications.js.map +1 -1
- package/plugin/lib/module/ios/withCIOIosSwift.js +24 -42
- package/plugin/lib/module/ios/withCIOIosSwift.js.map +1 -1
- package/plugin/lib/module/ios/withGoogleServicesJsonFile.js +45 -30
- package/plugin/lib/module/ios/withGoogleServicesJsonFile.js.map +1 -1
- package/plugin/lib/module/ios/withNotificationsXcodeProject.js +187 -122
- package/plugin/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
- package/plugin/lib/typescript/android/withAndroidManifestUpdates.d.ts +2 -0
- package/plugin/lib/typescript/android/withAppGoogleServices.d.ts +1 -0
- package/plugin/lib/typescript/android/withGoogleServicesJSON.d.ts +1 -0
- package/plugin/lib/typescript/android/withLocationGradleProperties.d.ts +2 -0
- package/plugin/lib/typescript/android/withMainApplicationModifications.d.ts +6 -0
- package/plugin/lib/typescript/android/withNotificationChannelMetadata.d.ts +5 -0
- package/plugin/lib/typescript/android/withProjectBuildGradle.d.ts +9 -0
- package/plugin/lib/typescript/android/withProjectGoogleServices.d.ts +1 -0
- package/plugin/lib/typescript/helpers/utils/injectCIOPodfileCode.d.ts +14 -0
- package/plugin/lib/typescript/ios/withAppDelegateModifications.d.ts +13 -0
- package/plugin/lib/typescript/ios/withCIOIosSwift.d.ts +11 -0
- package/plugin/lib/typescript/ios/withGoogleServicesJsonFile.d.ts +14 -1
- package/plugin/lib/typescript/ios/withNotificationsXcodeProject.d.ts +53 -2
- package/plugin/src/android/withAndroidManifestUpdates.ts +83 -73
- package/plugin/src/android/withAppGoogleServices.ts +13 -11
- package/plugin/src/android/withGoogleServicesJSON.ts +30 -28
- package/plugin/src/android/withLocationGradleProperties.ts +23 -17
- package/plugin/src/android/withMainApplicationModifications.ts +25 -15
- package/plugin/src/android/withNotificationChannelMetadata.ts +1 -1
- package/plugin/src/android/withProjectBuildGradle.ts +37 -27
- package/plugin/src/android/withProjectGoogleServices.ts +14 -9
- package/plugin/src/helpers/utils/injectCIOPodfileCode.ts +83 -48
- package/plugin/src/ios/withAppDelegateModifications.ts +61 -48
- package/plugin/src/ios/withCIOIosSwift.ts +33 -50
- package/plugin/src/ios/withGoogleServicesJsonFile.ts +66 -48
- package/plugin/src/ios/withNotificationsXcodeProject.ts +257 -207
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_configPlugins","require","_utils","shouldDisableAndroid16Support","config","androidOptions","disableAndroid16Support","undefined","isExpoVersion53OrLower","
|
|
1
|
+
{"version":3,"names":["_configPlugins","require","_utils","shouldDisableAndroid16Support","config","androidOptions","disableAndroid16Support","undefined","isExpoVersion53OrLower","modifyProjectBuildGradleAndroid16Support","contents","options","includes","resolutionStrategy","replace","withProjectBuildGradle","withExpoProjectBuildGradle","modResults"],"sources":["withProjectBuildGradle.ts"],"sourcesContent":["import { withProjectBuildGradle as withExpoProjectBuildGradle } from '@expo/config-plugins';\nimport type { ExpoConfig } from '@expo/config-types';\nimport { isExpoVersion53OrLower } from '../ios/utils';\nimport type { CustomerIOPluginOptionsAndroid } from '../types/cio-types';\n\n/**\n * Determines if the androidx dependency fix should be applied based on config and Expo version.\n * The fix disables Android 16 support by downgrading androidx dependencies.\n * @param config The Expo config\n * @param androidOptions The Android plugin options\n * @returns true if the fix should be applied (Android 16 disabled)\n */\nfunction shouldDisableAndroid16Support(\n config: ExpoConfig,\n androidOptions?: CustomerIOPluginOptionsAndroid\n): boolean {\n // If user explicitly sets the option, respect their choice\n if (androidOptions?.disableAndroid16Support !== undefined) {\n return androidOptions.disableAndroid16Support;\n }\n\n // Auto-detect: Disable Android 16 for Expo SDK 53 or lower, enable for 54+\n return isExpoVersion53OrLower(config);\n}\n\n/**\n * Pure string transform: injects an androidx resolution-strategy block into the\n * project-level build.gradle's `allprojects { ... }` section when\n * `disableAndroid16Support` is true. Idempotent — returns input unchanged if the\n * snippet is already present, or if the flag is false.\n */\nexport function modifyProjectBuildGradleAndroid16Support(\n contents: string,\n options: { disableAndroid16Support: boolean }\n): string {\n if (!options.disableAndroid16Support) {\n return contents;\n }\n\n if (contents.includes('androidx.core:core-ktx:1.13.1')) {\n return contents;\n }\n\n const resolutionStrategy = `\n configurations.all {\n resolutionStrategy {\n // Disable Android 16 support by forcing older androidx versions\n // Compatible with API 35 and AGP 8.8.2 (prevents API 36/AGP 8.9.1+ requirement)\n force 'androidx.core:core-ktx:1.13.1'\n force 'androidx.lifecycle:lifecycle-process:2.8.7'\n }\n }`;\n\n return contents.replace(\n /allprojects\\s*\\{/,\n `allprojects {${resolutionStrategy}`\n );\n}\n\n/**\n * Adds dependency resolution strategy to force specific androidx versions.\n * This disables Android 16 support for apps using Expo SDK 53 or older gradle versions.\n *\n * The fix prevents newer androidx versions that require Android API 36 and AGP 8.9.1+\n * from being pulled in. Expo SDK 53 uses Android API 35 and AGP 8.8.2, so we force\n * compatible versions.\n *\n * Expo SDK 54+ should support newer gradle versions and won't need this fix.\n */\nexport function withProjectBuildGradle(\n config: ExpoConfig,\n androidOptions?: CustomerIOPluginOptionsAndroid\n): ExpoConfig {\n return withExpoProjectBuildGradle(config, (config) => {\n config.modResults.contents = modifyProjectBuildGradleAndroid16Support(\n config.modResults.contents,\n { disableAndroid16Support: shouldDisableAndroid16Support(config, androidOptions) }\n );\n return config;\n });\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,6BAA6BA,CACpCC,MAAkB,EAClBC,cAA+C,EACtC;EACT;EACA,IAAI,CAAAA,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEC,uBAAuB,MAAKC,SAAS,EAAE;IACzD,OAAOF,cAAc,CAACC,uBAAuB;EAC/C;;EAEA;EACA,OAAO,IAAAE,6BAAsB,EAACJ,MAAM,CAAC;AACvC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASK,wCAAwCA,CACtDC,QAAgB,EAChBC,OAA6C,EACrC;EACR,IAAI,CAACA,OAAO,CAACL,uBAAuB,EAAE;IACpC,OAAOI,QAAQ;EACjB;EAEA,IAAIA,QAAQ,CAACE,QAAQ,CAAC,+BAA+B,CAAC,EAAE;IACtD,OAAOF,QAAQ;EACjB;EAEA,MAAMG,kBAAkB,GAAG;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;EAEJ,OAAOH,QAAQ,CAACI,OAAO,CACrB,kBAAkB,EAClB,gBAAgBD,kBAAkB,EACpC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,sBAAsBA,CACpCX,MAAkB,EAClBC,cAA+C,EACnC;EACZ,OAAO,IAAAW,qCAA0B,EAACZ,MAAM,EAAGA,MAAM,IAAK;IACpDA,MAAM,CAACa,UAAU,CAACP,QAAQ,GAAGD,wCAAwC,CACnEL,MAAM,CAACa,UAAU,CAACP,QAAQ,EAC1B;MAAEJ,uBAAuB,EAAEH,6BAA6B,CAACC,MAAM,EAAEC,cAAc;IAAE,CACnF,CAAC;IACD,OAAOD,MAAM;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.modifyProjectBuildGradleForGoogleServices = modifyProjectBuildGradleForGoogleServices;
|
|
6
7
|
exports.withProjectGoogleServices = void 0;
|
|
7
8
|
var _configPlugins = require("@expo/config-plugins");
|
|
8
9
|
var _android = require("./../helpers/constants/android");
|
|
10
|
+
function modifyProjectBuildGradleForGoogleServices(contents) {
|
|
11
|
+
const regex = new RegExp(_android.CIO_PROJECT_GOOGLE_SNIPPET);
|
|
12
|
+
if (regex.test(contents)) {
|
|
13
|
+
return contents;
|
|
14
|
+
}
|
|
15
|
+
return contents.replace(_android.CIO_PROJECT_BUILDSCRIPTS_REGEX, `$1\n${_android.CIO_PROJECT_GOOGLE_SNIPPET}`);
|
|
16
|
+
}
|
|
9
17
|
const withProjectGoogleServices = configOuter => {
|
|
10
18
|
return (0, _configPlugins.withProjectBuildGradle)(configOuter, props => {
|
|
11
|
-
|
|
12
|
-
const match = props.modResults.contents.match(regex);
|
|
13
|
-
if (!match) {
|
|
14
|
-
props.modResults.contents = props.modResults.contents.replace(_android.CIO_PROJECT_BUILDSCRIPTS_REGEX, `$1\n${_android.CIO_PROJECT_GOOGLE_SNIPPET}`);
|
|
15
|
-
}
|
|
19
|
+
props.modResults.contents = modifyProjectBuildGradleForGoogleServices(props.modResults.contents);
|
|
16
20
|
return props;
|
|
17
21
|
});
|
|
18
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_configPlugins","require","_android","
|
|
1
|
+
{"version":3,"names":["_configPlugins","require","_android","modifyProjectBuildGradleForGoogleServices","contents","regex","RegExp","CIO_PROJECT_GOOGLE_SNIPPET","test","replace","CIO_PROJECT_BUILDSCRIPTS_REGEX","withProjectGoogleServices","configOuter","withProjectBuildGradle","props","modResults","exports"],"sources":["withProjectGoogleServices.ts"],"sourcesContent":["import type { ConfigPlugin } from '@expo/config-plugins';\nimport { withProjectBuildGradle } from '@expo/config-plugins';\n\nimport {\n CIO_PROJECT_BUILDSCRIPTS_REGEX,\n CIO_PROJECT_GOOGLE_SNIPPET,\n} from './../helpers/constants/android';\nimport type { CustomerIOPluginOptionsAndroid } from './../types/cio-types';\n\nexport function modifyProjectBuildGradleForGoogleServices(contents: string): string {\n const regex = new RegExp(CIO_PROJECT_GOOGLE_SNIPPET);\n if (regex.test(contents)) {\n return contents;\n }\n return contents.replace(\n CIO_PROJECT_BUILDSCRIPTS_REGEX,\n `$1\\n${CIO_PROJECT_GOOGLE_SNIPPET}`\n );\n}\n\nexport const withProjectGoogleServices: ConfigPlugin<\n CustomerIOPluginOptionsAndroid\n> = (configOuter) => {\n return withProjectBuildGradle(configOuter, (props) => {\n props.modResults.contents = modifyProjectBuildGradleForGoogleServices(\n props.modResults.contents\n );\n return props;\n });\n};\n"],"mappings":";;;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAMO,SAASE,yCAAyCA,CAACC,QAAgB,EAAU;EAClF,MAAMC,KAAK,GAAG,IAAIC,MAAM,CAACC,mCAA0B,CAAC;EACpD,IAAIF,KAAK,CAACG,IAAI,CAACJ,QAAQ,CAAC,EAAE;IACxB,OAAOA,QAAQ;EACjB;EACA,OAAOA,QAAQ,CAACK,OAAO,CACrBC,uCAA8B,EAC9B,OAAOH,mCAA0B,EACnC,CAAC;AACH;AAEO,MAAMI,yBAEZ,GAAIC,WAAW,IAAK;EACnB,OAAO,IAAAC,qCAAsB,EAACD,WAAW,EAAGE,KAAK,IAAK;IACpDA,KAAK,CAACC,UAAU,CAACX,QAAQ,GAAGD,yCAAyC,CACnEW,KAAK,CAACC,UAAU,CAACX,QACnB,CAAC;IACD,OAAOU,KAAK;EACd,CAAC,CAAC;AACJ,CAAC;AAACE,OAAA,CAAAL,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.appendNotificationTargetToPodfile = appendNotificationTargetToPodfile;
|
|
6
7
|
exports.buildHostAppPodSnippet = buildHostAppPodSnippet;
|
|
7
8
|
exports.injectCIONotificationPodfileCode = injectCIONotificationPodfileCode;
|
|
8
9
|
exports.injectCIOPodfileCode = injectCIOPodfileCode;
|
|
10
|
+
exports.injectHostAppPodfileCode = injectHostAppPodfileCode;
|
|
9
11
|
var _logger = require("../../utils/logger");
|
|
10
12
|
var _ios = require("../constants/ios");
|
|
11
13
|
var _codeInjection = require("./codeInjection");
|
|
@@ -35,47 +37,77 @@ function buildHostAppPodSnippet(iosPath, isFcmPushProvider, options) {
|
|
|
35
37
|
const pushSubspec = isFcmPushProvider ? 'fcm' : 'apn';
|
|
36
38
|
return `pod 'customerio-reactnative', :subspecs => ['${pushSubspec}', 'location'], :path => '${resolvedPath}'`;
|
|
37
39
|
}
|
|
40
|
+
const HOST_APP_BLOCK_START = '# --- CustomerIO Host App START ---';
|
|
41
|
+
const HOST_APP_BLOCK_END = '# --- CustomerIO Host App END ---';
|
|
42
|
+
const NOTIFICATION_BLOCK_START = '# --- CustomerIO Notification START ---';
|
|
43
|
+
const NOTIFICATION_BLOCK_END = '# --- CustomerIO Notification END ---';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Pure string transform: given the existing Podfile contents, returns the
|
|
47
|
+
* Podfile with the CustomerIO host-app block injected before the Expo
|
|
48
|
+
* `post_install do |installer|` anchor. Idempotent — returns input unchanged
|
|
49
|
+
* if the block is already present.
|
|
50
|
+
*/
|
|
51
|
+
function injectHostAppPodfileCode(podfileContent, iosPath, isFcmPushProvider, options) {
|
|
52
|
+
if (podfileContent.match(new RegExp(HOST_APP_BLOCK_START))) {
|
|
53
|
+
return podfileContent;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// We need to decide what line of code in the Podfile to insert our native code.
|
|
57
|
+
// The "post_install" line is always present in an Expo project Podfile so it's reliable.
|
|
58
|
+
// Find that line in the Podfile and then we will insert our code above that line.
|
|
59
|
+
const lineInPodfileToInjectSnippetBefore = /post_install do \|installer\|/;
|
|
60
|
+
const podLine = buildHostAppPodSnippet(iosPath, isFcmPushProvider, options);
|
|
61
|
+
const snippetToInjectInPodfile = `
|
|
62
|
+
${HOST_APP_BLOCK_START}
|
|
63
|
+
${podLine}
|
|
64
|
+
${HOST_APP_BLOCK_END}
|
|
65
|
+
`.trim();
|
|
66
|
+
return (0, _codeInjection.injectCodeByRegex)(podfileContent, lineInPodfileToInjectSnippetBefore, snippetToInjectInPodfile).join('\n');
|
|
67
|
+
}
|
|
38
68
|
async function injectCIOPodfileCode(iosPath, isFcmPushProvider, options) {
|
|
39
|
-
const blockStart = '# --- CustomerIO Host App START ---';
|
|
40
|
-
const blockEnd = '# --- CustomerIO Host App END ---';
|
|
41
69
|
const filename = `${iosPath}/Podfile`;
|
|
42
70
|
const podfile = await _fileManagement.FileManagement.read(filename);
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
// The "post_install" line is always present in an Expo project Podfile so it's reliable.
|
|
47
|
-
// Find that line in the Podfile and then we will insert our code above that line.
|
|
48
|
-
const lineInPodfileToInjectSnippetBefore = /post_install do \|installer\|/;
|
|
49
|
-
const podLine = buildHostAppPodSnippet(iosPath, isFcmPushProvider, options);
|
|
50
|
-
const snippetToInjectInPodfile = `
|
|
51
|
-
${blockStart}
|
|
52
|
-
${podLine}
|
|
53
|
-
${blockEnd}
|
|
54
|
-
`.trim();
|
|
55
|
-
_fileManagement.FileManagement.write(filename, (0, _codeInjection.injectCodeByRegex)(podfile, lineInPodfileToInjectSnippetBefore, snippetToInjectInPodfile).join('\n'));
|
|
71
|
+
const next = injectHostAppPodfileCode(podfile, iosPath, isFcmPushProvider, options);
|
|
72
|
+
if (next !== podfile) {
|
|
73
|
+
_fileManagement.FileManagement.write(filename, next);
|
|
56
74
|
} else {
|
|
57
75
|
_logger.logger.info('CustomerIO Podfile snippets already exists. Skipping...');
|
|
58
76
|
}
|
|
59
77
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Pure string transform: given the existing Podfile contents, returns the
|
|
81
|
+
* Podfile with the rich-push NotificationService target block appended at
|
|
82
|
+
* the end. Idempotent — returns input unchanged if the block is already
|
|
83
|
+
* present.
|
|
84
|
+
*/
|
|
85
|
+
function appendNotificationTargetToPodfile(podfileContent, iosPath, isFcmPushProvider, useFrameworks) {
|
|
86
|
+
if (podfileContent.match(new RegExp(NOTIFICATION_BLOCK_START))) {
|
|
87
|
+
return podfileContent;
|
|
88
|
+
}
|
|
89
|
+
const snippetToAppend = `
|
|
90
|
+
${NOTIFICATION_BLOCK_START}
|
|
72
91
|
target 'NotificationService' do
|
|
73
|
-
${
|
|
74
|
-
pod 'customerio-reactnative-richpush/${
|
|
92
|
+
${useFrameworks === 'static' ? 'use_frameworks! :linkage => :static' : ''}
|
|
93
|
+
pod 'customerio-reactnative-richpush/${isFcmPushProvider ? 'fcm' : 'apn'}', :path => '${(0, _ios.getRelativePathToRNSDK)(iosPath)}'
|
|
75
94
|
end
|
|
76
|
-
${
|
|
95
|
+
${NOTIFICATION_BLOCK_END}
|
|
77
96
|
`.trim();
|
|
78
|
-
|
|
97
|
+
|
|
98
|
+
// Mirror FileManagement.append: append directly with no separator (real
|
|
99
|
+
// Podfiles end with a trailing newline, so the appended block starts on a
|
|
100
|
+
// fresh line in practice).
|
|
101
|
+
return `${podfileContent}${snippetToAppend}`;
|
|
102
|
+
}
|
|
103
|
+
async function injectCIONotificationPodfileCode(iosPath, useFrameworks, isFcmPushProvider) {
|
|
104
|
+
const filename = `${iosPath}/Podfile`;
|
|
105
|
+
const podfile = await _fileManagement.FileManagement.read(filename);
|
|
106
|
+
const next = appendNotificationTargetToPodfile(podfile, iosPath, isFcmPushProvider, useFrameworks);
|
|
107
|
+
if (next !== podfile) {
|
|
108
|
+
// FileManagement.append matches what the previous direct-append did.
|
|
109
|
+
// Slice off the leading content (already on disk) and append only the new tail.
|
|
110
|
+
_fileManagement.FileManagement.append(filename, next.slice(podfile.length));
|
|
79
111
|
}
|
|
80
112
|
}
|
|
81
113
|
//# sourceMappingURL=injectCIOPodfileCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_logger","require","_ios","_codeInjection","_fileManagement","buildHostAppPodSnippet","iosPath","isFcmPushProvider","options","resolvedPath","getRelativePathToRNSDK","locationEnabled","hasPush","subspec","pushSubspec","
|
|
1
|
+
{"version":3,"names":["_logger","require","_ios","_codeInjection","_fileManagement","buildHostAppPodSnippet","iosPath","isFcmPushProvider","options","resolvedPath","getRelativePathToRNSDK","locationEnabled","hasPush","subspec","pushSubspec","HOST_APP_BLOCK_START","HOST_APP_BLOCK_END","NOTIFICATION_BLOCK_START","NOTIFICATION_BLOCK_END","injectHostAppPodfileCode","podfileContent","match","RegExp","lineInPodfileToInjectSnippetBefore","podLine","snippetToInjectInPodfile","trim","injectCodeByRegex","join","injectCIOPodfileCode","filename","podfile","FileManagement","read","next","write","logger","info","appendNotificationTargetToPodfile","useFrameworks","snippetToAppend","injectCIONotificationPodfileCode","append","slice","length"],"sources":["injectCIOPodfileCode.ts"],"sourcesContent":["import type { CustomerIOPluginOptionsIOS } from '../../types/cio-types';\nimport { logger } from '../../utils/logger';\nimport { getRelativePathToRNSDK } from '../constants/ios';\nimport { injectCodeByRegex } from './codeInjection';\nimport { FileManagement } from './fileManagement';\n\nexport type InjectCIOPodfileOptions = {\n /** When true, add the location subspec. When false/omit, use single push subspec only. */\n locationEnabled?: boolean;\n /** When false and locationEnabled, inject only :subspecs => ['location']. When true, use push + location. */\n hasPush?: boolean;\n};\n\n/** Builds the host-app pod snippet for the Podfile.\n *\n * The :path is resolved at prebuild time by `getRelativePathToRNSDK`,\n * which dispatches on the installed React Native version so the path\n * matches what RN pod autolinking will emit (lexical for RN <0.80,\n * realpath for RN >=0.80). Baking the resolved string directly avoids\n * any Ruby/install-time logic in the Podfile and keeps the snippet\n * trivially diff-able.\n *\n * Exported for tests.\n */\nexport function buildHostAppPodSnippet(\n iosPath: string,\n isFcmPushProvider: boolean,\n options?: InjectCIOPodfileOptions\n): string {\n const resolvedPath = getRelativePathToRNSDK(iosPath);\n const locationEnabled = options?.locationEnabled === true;\n const hasPush = options?.hasPush !== false;\n\n if (!locationEnabled) {\n const subspec = isFcmPushProvider ? 'fcm' : 'apn';\n return `pod 'customerio-reactnative/${subspec}', :path => '${resolvedPath}'`;\n }\n if (!hasPush) {\n return `pod 'customerio-reactnative', :subspecs => ['location'], :path => '${resolvedPath}'`;\n }\n const pushSubspec = isFcmPushProvider ? 'fcm' : 'apn';\n return `pod 'customerio-reactnative', :subspecs => ['${pushSubspec}', 'location'], :path => '${resolvedPath}'`;\n}\n\nconst HOST_APP_BLOCK_START = '# --- CustomerIO Host App START ---';\nconst HOST_APP_BLOCK_END = '# --- CustomerIO Host App END ---';\nconst NOTIFICATION_BLOCK_START = '# --- CustomerIO Notification START ---';\nconst NOTIFICATION_BLOCK_END = '# --- CustomerIO Notification END ---';\n\n/**\n * Pure string transform: given the existing Podfile contents, returns the\n * Podfile with the CustomerIO host-app block injected before the Expo\n * `post_install do |installer|` anchor. Idempotent — returns input unchanged\n * if the block is already present.\n */\nexport function injectHostAppPodfileCode(\n podfileContent: string,\n iosPath: string,\n isFcmPushProvider: boolean,\n options?: InjectCIOPodfileOptions\n): string {\n if (podfileContent.match(new RegExp(HOST_APP_BLOCK_START))) {\n return podfileContent;\n }\n\n // We need to decide what line of code in the Podfile to insert our native code.\n // The \"post_install\" line is always present in an Expo project Podfile so it's reliable.\n // Find that line in the Podfile and then we will insert our code above that line.\n const lineInPodfileToInjectSnippetBefore = /post_install do \\|installer\\|/;\n const podLine = buildHostAppPodSnippet(iosPath, isFcmPushProvider, options);\n\n const snippetToInjectInPodfile = `\n${HOST_APP_BLOCK_START}\n ${podLine}\n${HOST_APP_BLOCK_END}\n`.trim();\n\n return injectCodeByRegex(\n podfileContent,\n lineInPodfileToInjectSnippetBefore,\n snippetToInjectInPodfile,\n ).join('\\n');\n}\n\nexport async function injectCIOPodfileCode(\n iosPath: string,\n isFcmPushProvider: boolean,\n options?: InjectCIOPodfileOptions\n) {\n const filename = `${iosPath}/Podfile`;\n const podfile = await FileManagement.read(filename);\n const next = injectHostAppPodfileCode(podfile, iosPath, isFcmPushProvider, options);\n if (next !== podfile) {\n FileManagement.write(filename, next);\n } else {\n logger.info('CustomerIO Podfile snippets already exists. Skipping...');\n }\n}\n\n/**\n * Pure string transform: given the existing Podfile contents, returns the\n * Podfile with the rich-push NotificationService target block appended at\n * the end. Idempotent — returns input unchanged if the block is already\n * present.\n */\nexport function appendNotificationTargetToPodfile(\n podfileContent: string,\n iosPath: string,\n isFcmPushProvider: boolean,\n useFrameworks: CustomerIOPluginOptionsIOS['useFrameworks'],\n): string {\n if (podfileContent.match(new RegExp(NOTIFICATION_BLOCK_START))) {\n return podfileContent;\n }\n\n const snippetToAppend = `\n${NOTIFICATION_BLOCK_START}\ntarget 'NotificationService' do\n ${useFrameworks === 'static' ? 'use_frameworks! :linkage => :static' : ''}\n pod 'customerio-reactnative-richpush/${isFcmPushProvider ? 'fcm' : 'apn'}', :path => '${getRelativePathToRNSDK(iosPath)}'\nend\n${NOTIFICATION_BLOCK_END}\n`.trim();\n\n // Mirror FileManagement.append: append directly with no separator (real\n // Podfiles end with a trailing newline, so the appended block starts on a\n // fresh line in practice).\n return `${podfileContent}${snippetToAppend}`;\n}\n\nexport async function injectCIONotificationPodfileCode(\n iosPath: string,\n useFrameworks: CustomerIOPluginOptionsIOS['useFrameworks'],\n isFcmPushProvider: boolean\n) {\n const filename = `${iosPath}/Podfile`;\n const podfile = await FileManagement.read(filename);\n const next = appendNotificationTargetToPodfile(\n podfile,\n iosPath,\n isFcmPushProvider,\n useFrameworks,\n );\n if (next !== podfile) {\n // FileManagement.append matches what the previous direct-append did.\n // Slice off the leading content (already on disk) and append only the new tail.\n FileManagement.append(filename, next.slice(podfile.length));\n }\n}\n"],"mappings":";;;;;;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,sBAAsBA,CACpCC,OAAe,EACfC,iBAA0B,EAC1BC,OAAiC,EACzB;EACR,MAAMC,YAAY,GAAG,IAAAC,2BAAsB,EAACJ,OAAO,CAAC;EACpD,MAAMK,eAAe,GAAG,CAAAH,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEG,eAAe,MAAK,IAAI;EACzD,MAAMC,OAAO,GAAG,CAAAJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEI,OAAO,MAAK,KAAK;EAE1C,IAAI,CAACD,eAAe,EAAE;IACpB,MAAME,OAAO,GAAGN,iBAAiB,GAAG,KAAK,GAAG,KAAK;IACjD,OAAO,+BAA+BM,OAAO,gBAAgBJ,YAAY,GAAG;EAC9E;EACA,IAAI,CAACG,OAAO,EAAE;IACZ,OAAO,sEAAsEH,YAAY,GAAG;EAC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ports.modifyAppDelegateContents = modifyAppDelegateContents;
|
|
7
|
+
exports.modifyAppDelegateHeader = modifyAppDelegateHeader;
|
|
6
8
|
exports.withAppDelegateModifications = void 0;
|
|
7
9
|
var _configPlugins = require("@expo/config-plugins");
|
|
8
10
|
var _Paths = require("@expo/config-plugins/build/ios/Paths");
|
|
@@ -65,9 +67,13 @@ const addFirebaseDelegateForwardDeclarationIfNeeded = stringContents => {
|
|
|
65
67
|
stringContents = (0, _codeInjection.injectCodeByLineNumber)(stringContents, 0, '@protocol FIRMessagingDelegate;');
|
|
66
68
|
return stringContents;
|
|
67
69
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Pure string transform: ensures the AppDelegate header (Objective-C path) declares
|
|
73
|
+
* `UNUserNotificationCenterDelegate` and imports `UserNotifications`. Idempotent.
|
|
74
|
+
*/
|
|
75
|
+
function modifyAppDelegateHeader(headerContent) {
|
|
76
|
+
return headerContent.replace(_ios.CIO_APPDELEGATEHEADER_REGEX, (match, interfaceDeclaration, _groupedDelegates, existingDelegates) => {
|
|
71
77
|
if (existingDelegates && existingDelegates.includes(_ios.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_CENTER_SNIPPET)) {
|
|
72
78
|
// The AppDelegate declaration already includes UNUserNotificationCenterDelegate, so we don't need to modify it
|
|
73
79
|
return match;
|
|
@@ -83,8 +89,7 @@ ${interfaceDeclaration.trim()} <${_ios.CIO_APPDELEGATEHEADER_USER_NOTIFICATION_C
|
|
|
83
89
|
`;
|
|
84
90
|
}
|
|
85
91
|
});
|
|
86
|
-
|
|
87
|
-
};
|
|
92
|
+
}
|
|
88
93
|
const addHandleDeeplinkInKilledState = stringContents => {
|
|
89
94
|
// Find if the deep link code snippet is already present
|
|
90
95
|
if ((0, _codeInjection.matchRegexExists)(stringContents, _ios.CIO_DEEPLINK_COMMENT_REGEX)) {
|
|
@@ -107,39 +112,48 @@ const addHandleDeeplinkInKilledState = stringContents => {
|
|
|
107
112
|
}
|
|
108
113
|
return stringContents;
|
|
109
114
|
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Pure string transform: produces the modified Objective-C AppDelegate.m / AppDelegate.mm
|
|
118
|
+
* contents wired with the Customer.io push pipeline (imports, declarations, notification
|
|
119
|
+
* configuration, registration callbacks, optional killed-state deep-link, FCM forward decl,
|
|
120
|
+
* Expo notifications header). The caller is responsible for the AppDelegate header file
|
|
121
|
+
* (.h) — see `modifyAppDelegateHeader`.
|
|
122
|
+
*/
|
|
123
|
+
function modifyAppDelegateContents(contents, projectName, props) {
|
|
124
|
+
var _props$pushNotificati, _props$pushNotificati2;
|
|
125
|
+
let next = addImport(contents, projectName);
|
|
126
|
+
next = addNotificationHandlerDeclaration(next);
|
|
127
|
+
|
|
128
|
+
// unless this property is explicity set to true, push notification
|
|
129
|
+
// registration will be added to the AppDelegate
|
|
130
|
+
if (((_props$pushNotificati = props.pushNotification) === null || _props$pushNotificati === void 0 ? void 0 : _props$pushNotificati.disableNotificationRegistration) !== true) {
|
|
131
|
+
next = addNotificationConfiguration(next);
|
|
132
|
+
}
|
|
133
|
+
next = addInitializeNativeCioSdk(next);
|
|
134
|
+
if (((_props$pushNotificati2 = props.pushNotification) === null || _props$pushNotificati2 === void 0 ? void 0 : _props$pushNotificati2.handleDeeplinkInKilledState) === true) {
|
|
135
|
+
next = addHandleDeeplinkInKilledState(next);
|
|
136
|
+
}
|
|
137
|
+
next = addDidFailToRegisterForRemoteNotificationsWithError(next);
|
|
138
|
+
next = addDidRegisterForRemoteNotificationsWithDeviceToken(next);
|
|
139
|
+
if ((0, _utils.isFcmPushProvider)(props)) {
|
|
140
|
+
next = addFirebaseDelegateForwardDeclarationIfNeeded(next);
|
|
141
|
+
}
|
|
142
|
+
next = addExpoNotificationsHeaderModification(next);
|
|
143
|
+
return next;
|
|
144
|
+
}
|
|
110
145
|
const withAppDelegateModifications = (configOuter, props) => {
|
|
111
146
|
return (0, _configPlugins.withAppDelegate)(configOuter, async config => {
|
|
112
|
-
|
|
147
|
+
const stringContents = config.modResults.contents;
|
|
113
148
|
const regex = new RegExp(`#import <${config.modRequest.projectName}-Swift.h>`);
|
|
114
|
-
|
|
115
|
-
if (!match) {
|
|
116
|
-
var _props$pushNotificati, _props$pushNotificati2;
|
|
117
|
-
const headerPath = (0, _Paths.getAppDelegateHeaderFilePath)(config.modRequest.projectRoot);
|
|
118
|
-
let headerContent = await _fileManagement.FileManagement.read(headerPath);
|
|
119
|
-
headerContent = addAppdelegateHeaderModification(headerContent);
|
|
120
|
-
_fileManagement.FileManagement.write(headerPath, headerContent);
|
|
121
|
-
stringContents = addImport(stringContents, config.modRequest.projectName);
|
|
122
|
-
stringContents = addNotificationHandlerDeclaration(stringContents);
|
|
123
|
-
|
|
124
|
-
// unless this property is explicity set to true, push notification
|
|
125
|
-
// registration will be added to the AppDelegate
|
|
126
|
-
if (((_props$pushNotificati = props.pushNotification) === null || _props$pushNotificati === void 0 ? void 0 : _props$pushNotificati.disableNotificationRegistration) !== true) {
|
|
127
|
-
stringContents = addNotificationConfiguration(stringContents);
|
|
128
|
-
}
|
|
129
|
-
stringContents = addInitializeNativeCioSdk(stringContents);
|
|
130
|
-
if (((_props$pushNotificati2 = props.pushNotification) === null || _props$pushNotificati2 === void 0 ? void 0 : _props$pushNotificati2.handleDeeplinkInKilledState) === true) {
|
|
131
|
-
stringContents = addHandleDeeplinkInKilledState(stringContents);
|
|
132
|
-
}
|
|
133
|
-
stringContents = addDidFailToRegisterForRemoteNotificationsWithError(stringContents);
|
|
134
|
-
stringContents = addDidRegisterForRemoteNotificationsWithDeviceToken(stringContents);
|
|
135
|
-
if ((0, _utils.isFcmPushProvider)(props)) {
|
|
136
|
-
stringContents = addFirebaseDelegateForwardDeclarationIfNeeded(stringContents);
|
|
137
|
-
}
|
|
138
|
-
stringContents = addExpoNotificationsHeaderModification(stringContents);
|
|
139
|
-
config.modResults.contents = stringContents;
|
|
140
|
-
} else {
|
|
149
|
+
if (stringContents.match(regex)) {
|
|
141
150
|
_logger.logger.info('Customerio AppDelegate changes already exist. Skipping...');
|
|
151
|
+
return config;
|
|
142
152
|
}
|
|
153
|
+
const headerPath = (0, _Paths.getAppDelegateHeaderFilePath)(config.modRequest.projectRoot);
|
|
154
|
+
const headerContent = await _fileManagement.FileManagement.read(headerPath);
|
|
155
|
+
_fileManagement.FileManagement.write(headerPath, modifyAppDelegateHeader(headerContent));
|
|
156
|
+
config.modResults.contents = modifyAppDelegateContents(stringContents, config.modRequest.projectName, props);
|
|
143
157
|
return config;
|
|
144
158
|
});
|
|
145
159
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_configPlugins","require","_Paths","_ios","_codeInjection","_fileManagement","_logger","_utils","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","addInitializeNativeCioSdk","CIO_INITIALIZECIOSDK_SNIPPET","addHandleDeeplinkInKilledStateConfiguration","regex","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","addDidFailToRegisterForRemoteNotificationsWithError","injectCodeByMultiLineRegexAndReplaceLine","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","addDidRegisterForRemoteNotificationsWithDeviceToken","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","addExpoNotificationsHeaderModification","addFirebaseDelegateForwardDeclarationIfNeeded","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","_props$pushNotificati","_props$pushNotificati2","headerPath","getAppDelegateHeaderFilePath","projectRoot","headerContent","FileManagement","read","write","pushNotification","disableNotificationRegistration","handleDeeplinkInKilledState","isFcmPushProvider","logger","info","exports"],"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 { logger } from '../utils/logger';\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 logger.info('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,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,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;EACf,CAAC,CAAC;AACJ,CAAC;AAACqB,OAAA,CAAAzB,4BAAA,GAAAA,4BAAA;AACF,SAAShD,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAO;AACT;AACA;AACA,WAAWA,OAAO;AAClB,GAAG;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_configPlugins","require","_Paths","_ios","_codeInjection","_fileManagement","_logger","_utils","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","addInitializeNativeCioSdk","CIO_INITIALIZECIOSDK_SNIPPET","addHandleDeeplinkInKilledStateConfiguration","regex","CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SNIPPET","addDidFailToRegisterForRemoteNotificationsWithError","injectCodeByMultiLineRegexAndReplaceLine","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_REGEX","CIO_DIDFAILTOREGISTERFORREMOTENOTIFICATIONSWITHERROR_SNIPPET","addDidRegisterForRemoteNotificationsWithDeviceToken","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_REGEX","CIO_DIDREGISTERFORREMOTENOTIFICATIONSWITHDEVICETOKEN_SNIPPET","addExpoNotificationsHeaderModification","addFirebaseDelegateForwardDeclarationIfNeeded","modifyAppDelegateHeader","headerContent","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","modifyAppDelegateContents","contents","projectName","props","_props$pushNotificati","_props$pushNotificati2","next","pushNotification","disableNotificationRegistration","handleDeeplinkInKilledState","isFcmPushProvider","withAppDelegateModifications","configOuter","withAppDelegate","config","modResults","RegExp","modRequest","logger","info","headerPath","getAppDelegateHeaderFilePath","projectRoot","FileManagement","read","write","exports"],"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 { logger } from '../utils/logger';\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\n/**\n * Pure string transform: ensures the AppDelegate header (Objective-C path) declares\n * `UNUserNotificationCenterDelegate` and imports `UserNotifications`. Idempotent.\n */\nexport function modifyAppDelegateHeader(headerContent: string): string {\n return headerContent.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\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\n/**\n * Pure string transform: produces the modified Objective-C AppDelegate.m / AppDelegate.mm\n * contents wired with the Customer.io push pipeline (imports, declarations, notification\n * configuration, registration callbacks, optional killed-state deep-link, FCM forward decl,\n * Expo notifications header). The caller is responsible for the AppDelegate header file\n * (.h) — see `modifyAppDelegateHeader`.\n */\nexport function modifyAppDelegateContents(\n contents: string,\n projectName: string,\n props: CustomerIOPluginOptionsIOS\n): string {\n let next = addImport(contents, projectName);\n next = addNotificationHandlerDeclaration(next);\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 next = addNotificationConfiguration(next);\n }\n\n next = addInitializeNativeCioSdk(next);\n\n if (props.pushNotification?.handleDeeplinkInKilledState === true) {\n next = addHandleDeeplinkInKilledState(next);\n }\n\n next = addDidFailToRegisterForRemoteNotificationsWithError(next);\n next = addDidRegisterForRemoteNotificationsWithDeviceToken(next);\n\n if (isFcmPushProvider(props)) {\n next = addFirebaseDelegateForwardDeclarationIfNeeded(next);\n }\n\n next = addExpoNotificationsHeaderModification(next);\n\n return next;\n}\n\nexport const withAppDelegateModifications: ConfigPlugin<\n CustomerIOPluginOptionsIOS\n> = (configOuter, props) => {\n return withAppDelegate(configOuter, async (config) => {\n const stringContents = config.modResults.contents;\n const regex = new RegExp(\n `#import <${config.modRequest.projectName}-Swift.h>`\n );\n\n if (stringContents.match(regex)) {\n logger.info('Customerio AppDelegate changes already exist. Skipping...');\n return config;\n }\n\n const headerPath = getAppDelegateHeaderFilePath(\n config.modRequest.projectRoot\n );\n const headerContent = await FileManagement.read(headerPath);\n FileManagement.write(headerPath, modifyAppDelegateHeader(headerContent));\n\n config.modResults.contents = modifyAppDelegateContents(\n stringContents,\n config.modRequest.projectName as string,\n props\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":";;;;;;;;A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,MAAM,CAACC,UAAU,CAACd,QAAQ,GAAGD,yBAAyB,CACpDrD,cAAc,EACdmE,MAAM,CAACG,UAAU,CAACf,WAAW,EAC7BC,KACF,CAAC;IAED,OAAOW,MAAM;EACf,CAAC,CAAC;AACJ,CAAC;AAACY,OAAA,CAAAf,4BAAA,GAAAA,4BAAA;AACF,SAAS5D,gBAAgBA,CAACH,OAAe,EAAE;EACzC,OAAO;AACT;AACA;AACA,WAAWA,OAAO;AAClB,GAAG;AACH","ignoreList":[]}
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.modifyAppDelegateForNativeSDKInitializer = modifyAppDelegateForNativeSDKInitializer;
|
|
7
|
+
exports.modifyAppDelegateForPushHandler = modifyAppDelegateForPushHandler;
|
|
6
8
|
exports.withCIOIosSwift = void 0;
|
|
7
9
|
var _configPlugins = require("@expo/config-plugins");
|
|
8
10
|
var _path = _interopRequireDefault(require("path"));
|
|
@@ -151,12 +153,14 @@ const withCIOIosSwift = (configOuter, sdkConfig, props, location) => {
|
|
|
151
153
|
if (props !== null && props !== void 0 && props.pushNotification) {
|
|
152
154
|
// With push notifications: delegate to CioSdkAppDelegateHandler for both push and auto-init
|
|
153
155
|
return (0, _configPlugins.withAppDelegate)(configOuter, async config => {
|
|
154
|
-
|
|
156
|
+
config.modResults.contents = modifyAppDelegateForPushHandler(config.modResults.contents, props);
|
|
157
|
+
return config;
|
|
155
158
|
});
|
|
156
159
|
} else if (sdkConfig) {
|
|
157
160
|
// Without push notifications: directly inject auto initialization into AppDelegate
|
|
158
161
|
return (0, _configPlugins.withAppDelegate)(configOuter, async config => {
|
|
159
|
-
|
|
162
|
+
config.modResults.contents = modifyAppDelegateForNativeSDKInitializer(config.modResults.contents);
|
|
163
|
+
return config;
|
|
160
164
|
});
|
|
161
165
|
} else {
|
|
162
166
|
return configOuter;
|
|
@@ -164,58 +168,38 @@ const withCIOIosSwift = (configOuter, sdkConfig, props, location) => {
|
|
|
164
168
|
};
|
|
165
169
|
|
|
166
170
|
/**
|
|
167
|
-
*
|
|
171
|
+
* Pure string transform: produces the Swift AppDelegate contents wired to delegate to
|
|
172
|
+
* `CioSdkAppDelegateHandler` for both push notifications and (when configured) auto-init.
|
|
173
|
+
* Idempotent — returns `contents` unchanged when the handler is already present.
|
|
168
174
|
*/
|
|
169
175
|
exports.withCIOIosSwift = withCIOIosSwift;
|
|
170
|
-
|
|
176
|
+
function modifyAppDelegateForPushHandler(contents, props) {
|
|
171
177
|
var _props$pushNotificati6;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// Check if modifications have already been applied
|
|
175
|
-
if (appDelegateContent.includes(CIO_SDK_APP_DELEGATE_HANDLER_CLASS)) {
|
|
178
|
+
if (contents.includes(CIO_SDK_APP_DELEGATE_HANDLER_CLASS)) {
|
|
176
179
|
_logger.logger.info('CustomerIO Swift AppDelegate changes already exist. Skipping...');
|
|
177
|
-
return
|
|
180
|
+
return contents;
|
|
178
181
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// Modify didFinishLaunchingWithOptions to initialize and call the handler
|
|
184
|
-
modifiedContent = modifyDidFinishLaunchingWithOptions(modifiedContent, ` cioSdkHandler.application(application, didFinishLaunchingWithOptions: launchOptions)\n\n `);
|
|
185
|
-
|
|
186
|
-
// Add didRegisterForRemoteNotificationsWithDeviceToken implementation
|
|
187
|
-
modifiedContent = addDidRegisterForRemoteNotificationsWithDeviceToken(modifiedContent);
|
|
188
|
-
|
|
189
|
-
// Add didFailToRegisterForRemoteNotificationsWithError implementation
|
|
190
|
-
modifiedContent = addDidFailToRegisterForRemoteNotificationsWithError(modifiedContent);
|
|
191
|
-
|
|
192
|
-
// Add deep link handling for killed state if enabled
|
|
182
|
+
let next = addHandlerPropertyDeclaration(contents);
|
|
183
|
+
next = modifyDidFinishLaunchingWithOptions(next, ` cioSdkHandler.application(application, didFinishLaunchingWithOptions: launchOptions)\n\n `);
|
|
184
|
+
next = addDidRegisterForRemoteNotificationsWithDeviceToken(next);
|
|
185
|
+
next = addDidFailToRegisterForRemoteNotificationsWithError(next);
|
|
193
186
|
if (((_props$pushNotificati6 = props.pushNotification) === null || _props$pushNotificati6 === void 0 ? void 0 : _props$pushNotificati6.handleDeeplinkInKilledState) === true) {
|
|
194
|
-
|
|
187
|
+
next = addHandleDeeplinkInKilledState(next);
|
|
195
188
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
189
|
+
return next;
|
|
190
|
+
}
|
|
199
191
|
|
|
200
192
|
/**
|
|
201
|
-
*
|
|
193
|
+
* Pure string transform: injects the auto-init snippet into the Swift AppDelegate's
|
|
194
|
+
* didFinishLaunchingWithOptions for the no-push path. Idempotent.
|
|
202
195
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
) => {
|
|
206
|
-
const appDelegateContent = config.modResults.contents;
|
|
207
|
-
|
|
208
|
-
// Check if modifications have already been applied
|
|
209
|
-
if (appDelegateContent.includes(_ios.CIO_NATIVE_SDK_INITIALIZE_CALL)) {
|
|
196
|
+
function modifyAppDelegateForNativeSDKInitializer(contents) {
|
|
197
|
+
if (contents.includes(_ios.CIO_NATIVE_SDK_INITIALIZE_CALL)) {
|
|
210
198
|
_logger.logger.info('CustomerIO Swift AppDelegate changes already exist. Skipping...');
|
|
211
|
-
return
|
|
199
|
+
return contents;
|
|
212
200
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const modifiedContent = modifyDidFinishLaunchingWithOptions(appDelegateContent, _ios.CIO_NATIVE_SDK_INITIALIZE_SNIPPET);
|
|
216
|
-
config.modResults.contents = modifiedContent;
|
|
217
|
-
return config;
|
|
218
|
-
};
|
|
201
|
+
return modifyDidFinishLaunchingWithOptions(contents, _ios.CIO_NATIVE_SDK_INITIALIZE_SNIPPET);
|
|
202
|
+
}
|
|
219
203
|
|
|
220
204
|
/**
|
|
221
205
|
* Check if a method exists in the AppDelegate content
|