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.
Files changed (79) hide show
  1. package/package.json +2 -1
  2. package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js +64 -59
  3. package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js.map +1 -1
  4. package/plugin/lib/commonjs/android/withAppGoogleServices.js +10 -7
  5. package/plugin/lib/commonjs/android/withAppGoogleServices.js.map +1 -1
  6. package/plugin/lib/commonjs/android/withGoogleServicesJSON.js +18 -21
  7. package/plugin/lib/commonjs/android/withGoogleServicesJSON.js.map +1 -1
  8. package/plugin/lib/commonjs/android/withLocationGradleProperties.js +16 -12
  9. package/plugin/lib/commonjs/android/withLocationGradleProperties.js.map +1 -1
  10. package/plugin/lib/commonjs/android/withMainApplicationModifications.js +19 -12
  11. package/plugin/lib/commonjs/android/withMainApplicationModifications.js.map +1 -1
  12. package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js +2 -1
  13. package/plugin/lib/commonjs/android/withNotificationChannelMetadata.js.map +1 -1
  14. package/plugin/lib/commonjs/android/withProjectBuildGradle.js +29 -25
  15. package/plugin/lib/commonjs/android/withProjectBuildGradle.js.map +1 -1
  16. package/plugin/lib/commonjs/android/withProjectGoogleServices.js +9 -5
  17. package/plugin/lib/commonjs/android/withProjectGoogleServices.js.map +1 -1
  18. package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js +63 -31
  19. package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  20. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js +47 -33
  21. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
  22. package/plugin/lib/commonjs/ios/withCIOIosSwift.js +26 -42
  23. package/plugin/lib/commonjs/ios/withCIOIosSwift.js.map +1 -1
  24. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js +46 -30
  25. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js.map +1 -1
  26. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js +192 -122
  27. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
  28. package/plugin/lib/module/android/withAndroidManifestUpdates.js +61 -58
  29. package/plugin/lib/module/android/withAndroidManifestUpdates.js.map +1 -1
  30. package/plugin/lib/module/android/withAppGoogleServices.js +9 -7
  31. package/plugin/lib/module/android/withAppGoogleServices.js.map +1 -1
  32. package/plugin/lib/module/android/withGoogleServicesJSON.js +17 -21
  33. package/plugin/lib/module/android/withGoogleServicesJSON.js.map +1 -1
  34. package/plugin/lib/module/android/withLocationGradleProperties.js +15 -12
  35. package/plugin/lib/module/android/withLocationGradleProperties.js.map +1 -1
  36. package/plugin/lib/module/android/withMainApplicationModifications.js +18 -12
  37. package/plugin/lib/module/android/withMainApplicationModifications.js.map +1 -1
  38. package/plugin/lib/module/android/withNotificationChannelMetadata.js +1 -1
  39. package/plugin/lib/module/android/withNotificationChannelMetadata.js.map +1 -1
  40. package/plugin/lib/module/android/withProjectBuildGradle.js +28 -25
  41. package/plugin/lib/module/android/withProjectBuildGradle.js.map +1 -1
  42. package/plugin/lib/module/android/withProjectGoogleServices.js +8 -5
  43. package/plugin/lib/module/android/withProjectGoogleServices.js.map +1 -1
  44. package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js +61 -31
  45. package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  46. package/plugin/lib/module/ios/withAppDelegateModifications.js +45 -33
  47. package/plugin/lib/module/ios/withAppDelegateModifications.js.map +1 -1
  48. package/plugin/lib/module/ios/withCIOIosSwift.js +24 -42
  49. package/plugin/lib/module/ios/withCIOIosSwift.js.map +1 -1
  50. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js +45 -30
  51. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js.map +1 -1
  52. package/plugin/lib/module/ios/withNotificationsXcodeProject.js +187 -122
  53. package/plugin/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
  54. package/plugin/lib/typescript/android/withAndroidManifestUpdates.d.ts +2 -0
  55. package/plugin/lib/typescript/android/withAppGoogleServices.d.ts +1 -0
  56. package/plugin/lib/typescript/android/withGoogleServicesJSON.d.ts +1 -0
  57. package/plugin/lib/typescript/android/withLocationGradleProperties.d.ts +2 -0
  58. package/plugin/lib/typescript/android/withMainApplicationModifications.d.ts +6 -0
  59. package/plugin/lib/typescript/android/withNotificationChannelMetadata.d.ts +5 -0
  60. package/plugin/lib/typescript/android/withProjectBuildGradle.d.ts +9 -0
  61. package/plugin/lib/typescript/android/withProjectGoogleServices.d.ts +1 -0
  62. package/plugin/lib/typescript/helpers/utils/injectCIOPodfileCode.d.ts +14 -0
  63. package/plugin/lib/typescript/ios/withAppDelegateModifications.d.ts +13 -0
  64. package/plugin/lib/typescript/ios/withCIOIosSwift.d.ts +11 -0
  65. package/plugin/lib/typescript/ios/withGoogleServicesJsonFile.d.ts +14 -1
  66. package/plugin/lib/typescript/ios/withNotificationsXcodeProject.d.ts +53 -2
  67. package/plugin/src/android/withAndroidManifestUpdates.ts +83 -73
  68. package/plugin/src/android/withAppGoogleServices.ts +13 -11
  69. package/plugin/src/android/withGoogleServicesJSON.ts +30 -28
  70. package/plugin/src/android/withLocationGradleProperties.ts +23 -17
  71. package/plugin/src/android/withMainApplicationModifications.ts +25 -15
  72. package/plugin/src/android/withNotificationChannelMetadata.ts +1 -1
  73. package/plugin/src/android/withProjectBuildGradle.ts +37 -27
  74. package/plugin/src/android/withProjectGoogleServices.ts +14 -9
  75. package/plugin/src/helpers/utils/injectCIOPodfileCode.ts +83 -48
  76. package/plugin/src/ios/withAppDelegateModifications.ts +61 -48
  77. package/plugin/src/ios/withCIOIosSwift.ts +33 -50
  78. package/plugin/src/ios/withGoogleServicesJsonFile.ts +66 -48
  79. package/plugin/src/ios/withNotificationsXcodeProject.ts +257 -207
@@ -232,12 +232,19 @@ export const withCIOIosSwift = (
232
232
  if (props?.pushNotification) {
233
233
  // With push notifications: delegate to CioSdkAppDelegateHandler for both push and auto-init
234
234
  return withAppDelegate(configOuter, async (config) => {
235
- return modifyAppDelegateWithPushAppDelegateHandler(config, props);
235
+ config.modResults.contents = modifyAppDelegateForPushHandler(
236
+ config.modResults.contents,
237
+ props
238
+ );
239
+ return config;
236
240
  });
237
241
  } else if (sdkConfig) {
238
242
  // Without push notifications: directly inject auto initialization into AppDelegate
239
243
  return withAppDelegate(configOuter, async (config) => {
240
- return modifyAppDelegateWithNativeSDKInitializer(config);
244
+ config.modResults.contents = modifyAppDelegateForNativeSDKInitializer(
245
+ config.modResults.contents
246
+ );
247
+ return config;
241
248
  });
242
249
  } else {
243
250
  return configOuter;
@@ -245,77 +252,53 @@ export const withCIOIosSwift = (
245
252
  };
246
253
 
247
254
  /**
248
- * Modify the AppDelegate to integrate with Customer.io SDK
255
+ * Pure string transform: produces the Swift AppDelegate contents wired to delegate to
256
+ * `CioSdkAppDelegateHandler` for both push notifications and (when configured) auto-init.
257
+ * Idempotent — returns `contents` unchanged when the handler is already present.
249
258
  */
250
- const modifyAppDelegateWithPushAppDelegateHandler = (
251
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
- config: any,
259
+ export function modifyAppDelegateForPushHandler(
260
+ contents: string,
253
261
  props: CustomerIOPluginOptionsIOS
254
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
255
- ): any => {
256
- const appDelegateContent = config.modResults.contents;
257
-
258
- // Check if modifications have already been applied
259
- if (appDelegateContent.includes(CIO_SDK_APP_DELEGATE_HANDLER_CLASS)) {
262
+ ): string {
263
+ if (contents.includes(CIO_SDK_APP_DELEGATE_HANDLER_CLASS)) {
260
264
  logger.info(
261
265
  'CustomerIO Swift AppDelegate changes already exist. Skipping...'
262
266
  );
263
- return config;
267
+ return contents;
264
268
  }
265
269
 
266
- // Add the handler property declaration
267
- let modifiedContent = addHandlerPropertyDeclaration(appDelegateContent);
268
-
269
- // Modify didFinishLaunchingWithOptions to initialize and call the handler
270
- modifiedContent = modifyDidFinishLaunchingWithOptions(
271
- modifiedContent,
270
+ let next = addHandlerPropertyDeclaration(contents);
271
+ next = modifyDidFinishLaunchingWithOptions(
272
+ next,
272
273
  ` cioSdkHandler.application(application, didFinishLaunchingWithOptions: launchOptions)\n\n `
273
274
  );
275
+ next = addDidRegisterForRemoteNotificationsWithDeviceToken(next);
276
+ next = addDidFailToRegisterForRemoteNotificationsWithError(next);
274
277
 
275
- // Add didRegisterForRemoteNotificationsWithDeviceToken implementation
276
- modifiedContent =
277
- addDidRegisterForRemoteNotificationsWithDeviceToken(modifiedContent);
278
-
279
- // Add didFailToRegisterForRemoteNotificationsWithError implementation
280
- modifiedContent =
281
- addDidFailToRegisterForRemoteNotificationsWithError(modifiedContent);
282
-
283
- // Add deep link handling for killed state if enabled
284
278
  if (props.pushNotification?.handleDeeplinkInKilledState === true) {
285
- modifiedContent = addHandleDeeplinkInKilledState(modifiedContent);
279
+ next = addHandleDeeplinkInKilledState(next);
286
280
  }
287
281
 
288
- config.modResults.contents = modifiedContent;
289
- return config;
290
- };
282
+ return next;
283
+ }
291
284
 
292
285
  /**
293
- * Modify the AppDelegate to integrate with Customer.io SDK
286
+ * Pure string transform: injects the auto-init snippet into the Swift AppDelegate's
287
+ * didFinishLaunchingWithOptions for the no-push path. Idempotent.
294
288
  */
295
- const modifyAppDelegateWithNativeSDKInitializer = (
296
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
297
- config: any,
298
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
299
- ): any => {
300
- const appDelegateContent = config.modResults.contents;
301
-
302
- // Check if modifications have already been applied
303
- if (appDelegateContent.includes(CIO_NATIVE_SDK_INITIALIZE_CALL)) {
289
+ export function modifyAppDelegateForNativeSDKInitializer(contents: string): string {
290
+ if (contents.includes(CIO_NATIVE_SDK_INITIALIZE_CALL)) {
304
291
  logger.info(
305
292
  'CustomerIO Swift AppDelegate changes already exist. Skipping...'
306
293
  );
307
- return config;
294
+ return contents;
308
295
  }
309
296
 
310
- // Modify didFinishLaunchingWithOptions to initialize and call the handler
311
- const modifiedContent = modifyDidFinishLaunchingWithOptions(
312
- appDelegateContent,
297
+ return modifyDidFinishLaunchingWithOptions(
298
+ contents,
313
299
  CIO_NATIVE_SDK_INITIALIZE_SNIPPET,
314
300
  );
315
-
316
- config.modResults.contents = modifiedContent;
317
- return config;
318
- };
301
+ }
319
302
 
320
303
  /**
321
304
  * Check if a method exists in the AppDelegate content
@@ -6,6 +6,65 @@ import { logger } from '../utils/logger';
6
6
  import { FileManagement } from './../helpers/utils/fileManagement';
7
7
  import { isFcmPushProvider } from './utils';
8
8
 
9
+ export type CopyGoogleServicePlistOptions = {
10
+ iosPath: string;
11
+ appName: string | undefined;
12
+ googleServicesFile: string | undefined;
13
+ expoIosGoogleServicesFileSet: boolean;
14
+ xcodeProject: XcodeProject;
15
+ };
16
+
17
+ /**
18
+ * Copies the FCM GoogleService-Info.plist into the iOS project (when needed) and registers it
19
+ * in the Xcode project's Resources group. Idempotent — no-ops if a plist is already present
20
+ * at either of the two well-known locations Expo / RN Firebase use.
21
+ */
22
+ export function copyGoogleServicePlistFile({
23
+ iosPath,
24
+ appName,
25
+ googleServicesFile,
26
+ expoIosGoogleServicesFileSet,
27
+ xcodeProject,
28
+ }: CopyGoogleServicePlistOptions): void {
29
+ const destination = `${iosPath}/GoogleService-Info.plist`;
30
+
31
+ if (FileManagement.exists(destination)) {
32
+ logger.info(`File already exists: ${destination}. Skipping...`);
33
+ return;
34
+ }
35
+
36
+ if (appName && FileManagement.exists(`${iosPath}/${appName}/GoogleService-Info.plist`)) {
37
+ // This is where RN Firebase potentially copies GoogleService-Info.plist
38
+ // Do not copy if it's already done by Firebase to avoid conflict in Resources
39
+ logger.info(
40
+ `File already exists: ${iosPath}/${appName}/GoogleService-Info.plist. Skipping...`
41
+ );
42
+ return;
43
+ }
44
+
45
+ if (googleServicesFile && FileManagement.exists(googleServicesFile)) {
46
+ if (expoIosGoogleServicesFileSet) {
47
+ logger.warn(
48
+ 'Specifying both Expo ios.googleServicesFile and Customer.io ios.pushNotification.googleServicesFile can cause a conflict' +
49
+ ' duplicating GoogleService-Info.plist in the iOS project resources. Please remove Customer.io ios.pushNotification.googleServicesFile'
50
+ );
51
+ }
52
+
53
+ try {
54
+ FileManagement.copyFile(googleServicesFile, destination);
55
+ addFileToXcodeProject(xcodeProject, 'GoogleService-Info.plist');
56
+ } catch {
57
+ logger.error(
58
+ `There was an error copying your GoogleService-Info.plist file. You can copy it manually into ${destination}`
59
+ );
60
+ }
61
+ } else {
62
+ logger.error(
63
+ `The Google Services file provided in ${googleServicesFile} doesn't seem to exist. You can copy it manually into ${destination}`
64
+ );
65
+ }
66
+ }
67
+
9
68
  export const withGoogleServicesJsonFile: ConfigPlugin<
10
69
  CustomerIOPluginOptionsIOS
11
70
  > = (config, cioProps) => {
@@ -21,54 +80,13 @@ export const withGoogleServicesJsonFile: ConfigPlugin<
21
80
  ' GoogleService-Info.plist as part of Firebase integration'
22
81
  );
23
82
 
24
- // googleServicesFile
25
- const iosPath = props.modRequest.platformProjectRoot;
26
- const googleServicesFile = cioProps.pushNotification?.googleServicesFile;
27
- const appName = props.modRequest.projectName;
28
-
29
- if (FileManagement.exists(`${iosPath}/GoogleService-Info.plist`)) {
30
- logger.info(
31
- `File already exists: ${iosPath}/GoogleService-Info.plist. Skipping...`
32
- );
33
- return props;
34
- }
35
-
36
- if (
37
- FileManagement.exists(`${iosPath}/${appName}/GoogleService-Info.plist`)
38
- ) {
39
- // This is where RN Firebase potentially copies GoogleService-Info.plist
40
- // Do not copy if it's already done by Firebase to avoid conflict in Resources
41
- logger.info(
42
- `File already exists: ${iosPath}/${appName}/GoogleService-Info.plist. Skipping...`
43
- );
44
- return props;
45
- }
46
-
47
- if (googleServicesFile && FileManagement.exists(googleServicesFile)) {
48
- if (config.ios?.googleServicesFile) {
49
- logger.warn(
50
- 'Specifying both Expo ios.googleServicesFile and Customer.io ios.pushNotification.googleServicesFile can cause a conflict' +
51
- ' duplicating GoogleService-Info.plist in the iOS project resources. Please remove Customer.io ios.pushNotification.googleServicesFile'
52
- );
53
- }
54
-
55
- try {
56
- FileManagement.copyFile(
57
- googleServicesFile,
58
- `${iosPath}/GoogleService-Info.plist`
59
- );
60
-
61
- addFileToXcodeProject(props.modResults, 'GoogleService-Info.plist');
62
- } catch {
63
- logger.error(
64
- `There was an error copying your GoogleService-Info.plist file. You can copy it manually into ${iosPath}/GoogleService-Info.plist`
65
- );
66
- }
67
- } else {
68
- logger.error(
69
- `The Google Services file provided in ${googleServicesFile} doesn't seem to exist. You can copy it manually into ${iosPath}/GoogleService-Info.plist`
70
- );
71
- }
83
+ copyGoogleServicePlistFile({
84
+ iosPath: props.modRequest.platformProjectRoot,
85
+ appName: props.modRequest.projectName,
86
+ googleServicesFile: cioProps.pushNotification?.googleServicesFile,
87
+ expoIosGoogleServicesFileSet: Boolean(config.ios?.googleServicesFile),
88
+ xcodeProject: props.modResults,
89
+ });
72
90
 
73
91
  return props;
74
92
  });