customerio-expo-plugin 2.0.0-beta.1 → 2.0.0-beta.2

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 (67) hide show
  1. package/package.json +3 -3
  2. package/plugin/{src/helpers/native-files/ios → lib/commonjs/helpers/native-files/ios/apn}/PushService.swift +1 -0
  3. package/plugin/lib/commonjs/helpers/native-files/ios/fcm/NotificationService.swift +25 -0
  4. package/plugin/lib/commonjs/helpers/native-files/ios/fcm/PushService.swift +59 -0
  5. package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js +4 -4
  6. package/plugin/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  7. package/plugin/lib/commonjs/ios/utils.js +17 -0
  8. package/plugin/lib/commonjs/ios/utils.js.map +1 -0
  9. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js +8 -0
  10. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
  11. package/plugin/lib/commonjs/ios/withCIOIos.js +2 -0
  12. package/plugin/lib/commonjs/ios/withCIOIos.js.map +1 -1
  13. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js +68 -0
  14. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js.map +1 -0
  15. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js +29 -11
  16. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
  17. package/plugin/lib/commonjs/ios/withXcodeProject.js +2 -1
  18. package/plugin/lib/commonjs/ios/withXcodeProject.js.map +1 -1
  19. package/plugin/lib/commonjs/types/cio-types.js.map +1 -1
  20. package/plugin/lib/{commonjs/helpers/native-files/ios → module/helpers/native-files/ios/apn}/PushService.swift +1 -0
  21. package/plugin/lib/module/helpers/native-files/ios/fcm/NotificationService.swift +25 -0
  22. package/plugin/lib/module/helpers/native-files/ios/fcm/PushService.swift +59 -0
  23. package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js +4 -4
  24. package/plugin/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  25. package/plugin/lib/module/ios/utils.js +10 -0
  26. package/plugin/lib/module/ios/utils.js.map +1 -0
  27. package/plugin/lib/module/ios/withAppDelegateModifications.js +8 -0
  28. package/plugin/lib/module/ios/withAppDelegateModifications.js.map +1 -1
  29. package/plugin/lib/module/ios/withCIOIos.js +2 -0
  30. package/plugin/lib/module/ios/withCIOIos.js.map +1 -1
  31. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js +61 -0
  32. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js.map +1 -0
  33. package/plugin/lib/module/ios/withNotificationsXcodeProject.js +29 -11
  34. package/plugin/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
  35. package/plugin/lib/module/ios/withXcodeProject.js +2 -1
  36. package/plugin/lib/module/ios/withXcodeProject.js.map +1 -1
  37. package/plugin/lib/module/types/cio-types.js.map +1 -1
  38. package/plugin/lib/typescript/helpers/utils/injectCIOPodfileCode.d.ts +2 -2
  39. package/plugin/lib/typescript/ios/utils.d.ts +7 -0
  40. package/plugin/lib/typescript/ios/withGoogleServicesJsonFile.d.ts +3 -0
  41. package/plugin/lib/typescript/types/cio-types.d.ts +3 -0
  42. package/plugin/{lib/module/helpers/native-files/ios → src/helpers/native-files/ios/apn}/PushService.swift +1 -0
  43. package/plugin/src/helpers/native-files/ios/fcm/NotificationService.swift +25 -0
  44. package/plugin/src/helpers/native-files/ios/fcm/PushService.swift +59 -0
  45. package/plugin/src/helpers/utils/injectCIOPodfileCode.ts +5 -4
  46. package/plugin/src/ios/utils.ts +10 -0
  47. package/plugin/src/ios/withAppDelegateModifications.ts +15 -0
  48. package/plugin/src/ios/withCIOIos.ts +2 -0
  49. package/plugin/src/ios/withGoogleServicesJsonFile.ts +97 -0
  50. package/plugin/src/ios/withNotificationsXcodeProject.ts +40 -12
  51. package/plugin/src/ios/withXcodeProject.ts +2 -1
  52. package/plugin/src/types/cio-types.ts +3 -0
  53. /package/plugin/lib/commonjs/helpers/native-files/ios/{NotificationService.swift → apn/NotificationService.swift} +0 -0
  54. /package/plugin/lib/commonjs/helpers/native-files/ios/{Env.swift → common/Env.swift} +0 -0
  55. /package/plugin/lib/commonjs/helpers/native-files/ios/{NotificationService-Info.plist → common/NotificationService-Info.plist} +0 -0
  56. /package/plugin/lib/commonjs/helpers/native-files/ios/{NotificationService.h → common/NotificationService.h} +0 -0
  57. /package/plugin/lib/commonjs/helpers/native-files/ios/{NotificationService.m → common/NotificationService.m} +0 -0
  58. /package/plugin/lib/module/helpers/native-files/ios/{NotificationService.swift → apn/NotificationService.swift} +0 -0
  59. /package/plugin/lib/module/helpers/native-files/ios/{Env.swift → common/Env.swift} +0 -0
  60. /package/plugin/lib/module/helpers/native-files/ios/{NotificationService-Info.plist → common/NotificationService-Info.plist} +0 -0
  61. /package/plugin/lib/module/helpers/native-files/ios/{NotificationService.h → common/NotificationService.h} +0 -0
  62. /package/plugin/lib/module/helpers/native-files/ios/{NotificationService.m → common/NotificationService.m} +0 -0
  63. /package/plugin/src/helpers/native-files/ios/{NotificationService.swift → apn/NotificationService.swift} +0 -0
  64. /package/plugin/src/helpers/native-files/ios/{Env.swift → common/Env.swift} +0 -0
  65. /package/plugin/src/helpers/native-files/ios/{NotificationService-Info.plist → common/NotificationService-Info.plist} +0 -0
  66. /package/plugin/src/helpers/native-files/ios/{NotificationService.h → common/NotificationService.h} +0 -0
  67. /package/plugin/src/helpers/native-files/ios/{NotificationService.m → common/NotificationService.m} +0 -0
@@ -14,6 +14,7 @@ import { replaceCodeByRegex } from '../helpers/utils/codeInjection';
14
14
  import { injectCIONotificationPodfileCode } from '../helpers/utils/injectCIOPodfileCode';
15
15
  import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
16
16
  import { FileManagement } from './../helpers/utils/fileManagement';
17
+ import { isFcmPushProvider } from './utils';
17
18
 
18
19
  const PLIST_FILENAME = `${CIO_NOTIFICATION_TARGET_NAME}-Info.plist`;
19
20
  const ENV_FILENAME = 'Env.swift';
@@ -118,7 +119,9 @@ const addRichPushXcodeProj = async (
118
119
  useFrameworks,
119
120
  } = options;
120
121
 
121
- await injectCIONotificationPodfileCode(iosPath, useFrameworks);
122
+ const isFcmProvider = isFcmPushProvider(options);
123
+
124
+ await injectCIONotificationPodfileCode(iosPath, useFrameworks, isFcmProvider);
122
125
 
123
126
  // Check if `CIO_NOTIFICATION_TARGET_NAME` group already exist in the project
124
127
  // If true then skip creating a new group to avoid duplicate folders
@@ -134,20 +137,32 @@ const addRichPushXcodeProj = async (
134
137
  recursive: true,
135
138
  });
136
139
 
137
- const files = [
140
+ const platformSpecificFiles = [
141
+ 'NotificationService.swift',
142
+ ];
143
+
144
+ const commonFiles = [
138
145
  PLIST_FILENAME,
139
146
  'NotificationService.h',
140
- 'NotificationService.swift',
141
147
  'NotificationService.m',
142
148
  ENV_FILENAME,
143
149
  ];
144
150
 
145
151
  const getTargetFile = (filename: string) => `${nsePath}/${filename}`;
152
+ // Copy platform-specific files
153
+ platformSpecificFiles.forEach((filename) => {
154
+ const targetFile = getTargetFile(filename);
155
+ FileManagement.copyFile(
156
+ `${LOCAL_PATH_TO_CIO_NSE_FILES}/${isFcmProvider ? "fcm" : "apn"}/${filename}`,
157
+ targetFile
158
+ );
159
+ });
146
160
 
147
- files.forEach((filename) => {
161
+ // Copy common files
162
+ commonFiles.forEach((filename) => {
148
163
  const targetFile = getTargetFile(filename);
149
164
  FileManagement.copyFile(
150
- `${LOCAL_PATH_TO_CIO_NSE_FILES}/${filename}`,
165
+ `${LOCAL_PATH_TO_CIO_NSE_FILES}/common/${filename}`,
151
166
  targetFile
152
167
  );
153
168
  });
@@ -163,7 +178,7 @@ const addRichPushXcodeProj = async (
163
178
 
164
179
  // Create new PBXGroup for the extension
165
180
  const extGroup = xcodeProject.addPbxGroup(
166
- files,
181
+ [...platformSpecificFiles, ...commonFiles], // Combine platform-specific and common files,
167
182
  CIO_NOTIFICATION_TARGET_NAME,
168
183
  CIO_NOTIFICATION_TARGET_NAME
169
184
  );
@@ -319,25 +334,29 @@ async function addPushNotificationFile(
319
334
  options: CustomerIOPluginOptionsIOS,
320
335
  xcodeProject: any
321
336
  ) {
337
+ // Maybe copy a different file with FCM config based on config
322
338
  const { iosPath, appName } = options;
323
- const file = 'PushService.swift';
339
+ const isFcmProvider = isFcmPushProvider(options);
340
+ // PushService.swift is platform-specific and always lives in the platform folder
341
+ const sourceFile = `${isFcmProvider ? "fcm" : "apn"}/PushService.swift`;
342
+ const targetFileName = 'PushService.swift';
324
343
  const appPath = `${iosPath}/${appName}`;
325
344
  const getTargetFile = (filename: string) => `${appPath}/${filename}`;
326
- const targetFile = getTargetFile(file);
345
+ const targetFile = getTargetFile(targetFileName);
327
346
 
328
347
  // Check whether {file} exists in the project. If false, then add the file
329
348
  // If {file} exists then skip and return
330
- if (!FileManagement.exists(getTargetFile(file))) {
349
+ if (!FileManagement.exists(getTargetFile(targetFileName))) {
331
350
  FileManagement.mkdir(appPath, {
332
351
  recursive: true,
333
352
  });
334
353
 
335
354
  FileManagement.copyFile(
336
- `${LOCAL_PATH_TO_CIO_NSE_FILES}/${file}`,
355
+ `${LOCAL_PATH_TO_CIO_NSE_FILES}/${sourceFile}`,
337
356
  targetFile
338
357
  );
339
358
  } else {
340
- console.log(`${getTargetFile(file)} already exists. Skipping...`);
359
+ console.log(`${getTargetFile(targetFileName)} already exists. Skipping...`);
341
360
  return;
342
361
  }
343
362
 
@@ -347,7 +366,7 @@ async function addPushNotificationFile(
347
366
  const classesKey = xcodeProject.findPBXGroupKey({ name: `${appName}` });
348
367
  xcodeProject.addToPbxGroup(group, classesKey);
349
368
 
350
- xcodeProject.addSourceFile(`${appName}/${file}`, null, group);
369
+ xcodeProject.addSourceFile(`${appName}/${targetFileName}`, null, group);
351
370
  }
352
371
 
353
372
  const updatePushFile = (
@@ -389,6 +408,15 @@ const updatePushFile = (
389
408
  autoTrackPushEvents.toString()
390
409
  );
391
410
 
411
+ const autoFetchDeviceToken =
412
+ options.autoFetchDeviceToken === undefined ||
413
+ options.autoFetchDeviceToken === true;
414
+ envFileContent = replaceCodeByRegex(
415
+ envFileContent,
416
+ /\{\{AUTO_FETCH_DEVICE_TOKEN\}\}/,
417
+ autoFetchDeviceToken.toString()
418
+ );
419
+
392
420
  const showPushAppInForeground =
393
421
  options.showPushAppInForeground === undefined ||
394
422
  options.showPushAppInForeground === true;
@@ -2,6 +2,7 @@ import { ConfigPlugin, withXcodeProject } from '@expo/config-plugins';
2
2
 
3
3
  import { injectCIOPodfileCode } from '../helpers/utils/injectCIOPodfileCode';
4
4
  import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
5
+ import { isFcmPushProvider } from './utils';
5
6
 
6
7
  export const withCioXcodeProject: ConfigPlugin<CustomerIOPluginOptionsIOS> = (
7
8
  config,
@@ -18,7 +19,7 @@ export const withCioXcodeProject: ConfigPlugin<CustomerIOPluginOptionsIOS> = (
18
19
  };
19
20
  const { iosPath } = options;
20
21
 
21
- await injectCIOPodfileCode(iosPath);
22
+ await injectCIOPodfileCode(iosPath, isFcmPushProvider(cioProps));
22
23
 
23
24
  return props;
24
25
  });
@@ -22,9 +22,12 @@ export type CustomerIOPluginOptionsIOS = {
22
22
  handleNotificationClick?: boolean;
23
23
  showPushAppInForeground?: boolean;
24
24
  autoTrackPushEvents?: boolean;
25
+ autoFetchDeviceToken?: boolean;
25
26
  handleDeeplinkInKilledState?: boolean;
26
27
  useFrameworks?: 'static' | 'dynamic';
27
28
  pushNotification?: {
29
+ provider?: 'apn' | 'fcm';
30
+ googleServicesFile?: string;
28
31
  useRichPush: boolean;
29
32
  env: {
30
33
  cdpApiKey: string;