customerio-expo-plugin 1.0.0-beta.3 → 1.0.0-beta.4

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 (57) hide show
  1. package/README.md +12 -0
  2. package/lib/commonjs/android/withAndroidManifestUpdates.js +37 -0
  3. package/lib/commonjs/android/withAndroidManifestUpdates.js.map +1 -0
  4. package/lib/commonjs/android/withAppGoogleServices.js.map +1 -1
  5. package/lib/commonjs/android/withCIOAndroid.js +4 -0
  6. package/lib/commonjs/android/withCIOAndroid.js.map +1 -1
  7. package/lib/commonjs/android/withGistMavenRepository.js.map +1 -1
  8. package/lib/commonjs/android/withGoogleServicesJSON.js.map +1 -1
  9. package/lib/commonjs/android/withProjectGoogleServices.js.map +1 -1
  10. package/lib/commonjs/helpers/constants/android.js.map +1 -1
  11. package/lib/commonjs/helpers/constants/ios.js +16 -1
  12. package/lib/commonjs/helpers/constants/ios.js.map +1 -1
  13. package/lib/commonjs/helpers/native-files/ios/PushService.swift +1 -13
  14. package/lib/commonjs/helpers/utils/codeInjection.js.map +1 -1
  15. package/lib/commonjs/helpers/utils/fileManagement.js.map +1 -1
  16. package/lib/commonjs/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/ios/withAppDelegateModifications.js +4 -2
  19. package/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
  20. package/lib/commonjs/ios/withCIOIos.js.map +1 -1
  21. package/lib/commonjs/ios/withNotificationsXcodeProject.js +13 -1
  22. package/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
  23. package/lib/commonjs/ios/withXcodeProject.js.map +1 -1
  24. package/lib/commonjs/postInstallHelper.js.map +1 -1
  25. package/lib/commonjs/types/cio-types.js.map +1 -1
  26. package/lib/module/android/withAndroidManifestUpdates.js +30 -0
  27. package/lib/module/android/withAndroidManifestUpdates.js.map +1 -0
  28. package/lib/module/android/withCIOAndroid.js +4 -0
  29. package/lib/module/android/withCIOAndroid.js.map +1 -1
  30. package/lib/module/android/withGoogleServicesJSON.js.map +1 -1
  31. package/lib/module/helpers/constants/ios.js +14 -0
  32. package/lib/module/helpers/constants/ios.js.map +1 -1
  33. package/lib/module/helpers/native-files/ios/PushService.swift +1 -13
  34. package/lib/module/helpers/utils/codeInjection.js.map +1 -1
  35. package/lib/module/helpers/utils/fileManagement.js.map +1 -1
  36. package/lib/module/helpers/utils/injectCIOPodfileCode.js.map +1 -1
  37. package/lib/module/index.js.map +1 -1
  38. package/lib/module/ios/withAppDelegateModifications.js +4 -2
  39. package/lib/module/ios/withAppDelegateModifications.js.map +1 -1
  40. package/lib/module/ios/withCIOIos.js.map +1 -1
  41. package/lib/module/ios/withNotificationsXcodeProject.js +14 -2
  42. package/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
  43. package/lib/module/ios/withXcodeProject.js.map +1 -1
  44. package/lib/module/postInstallHelper.js.map +1 -1
  45. package/lib/module/types/cio-types.js.map +1 -1
  46. package/lib/typescript/android/withAndroidManifestUpdates.d.ts +3 -0
  47. package/lib/typescript/helpers/constants/ios.d.ts +1 -0
  48. package/lib/typescript/ios/withAppDelegateModifications.d.ts +2 -1
  49. package/lib/typescript/types/cio-types.d.ts +2 -0
  50. package/package.json +1 -1
  51. package/src/android/withAndroidManifestUpdates.ts +49 -0
  52. package/src/android/withCIOAndroid.ts +4 -0
  53. package/src/helpers/constants/ios.ts +15 -0
  54. package/src/helpers/native-files/ios/PushService.swift +1 -13
  55. package/src/ios/withAppDelegateModifications.ts +7 -4
  56. package/src/ios/withNotificationsXcodeProject.ts +23 -1
  57. package/src/types/cio-types.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customerio-expo-plugin",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "Expo config plugin for the Customer IO React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -0,0 +1,49 @@
1
+ import { ConfigPlugin, withAndroidManifest } from '@expo/config-plugins';
2
+ import type { ManifestApplication } from '@expo/config-plugins/build/android/Manifest';
3
+
4
+ import type { CustomerIOPluginOptionsAndroid } from '../types/cio-types';
5
+
6
+ export const withAndroidManifestUpdates: ConfigPlugin<
7
+ CustomerIOPluginOptionsAndroid
8
+ > = (configOuter) => {
9
+ return withAndroidManifest(configOuter, (props) => {
10
+ const application = props.modResults.manifest
11
+ .application as ManifestApplication[];
12
+ const customerIOMessagingpush =
13
+ 'io.customer.messagingpush.CustomerIOFirebaseMessagingService';
14
+
15
+ if (!application[0]['service']) {
16
+ application[0]['service'] = [];
17
+ }
18
+
19
+ const hasService = application[0]['service'].some(
20
+ (service) => service['$']['android:name'] === customerIOMessagingpush
21
+ );
22
+
23
+ if (!hasService) {
24
+ application[0]['service'].push({
25
+ '$': {
26
+ 'android:name': customerIOMessagingpush,
27
+ 'android:exported': 'false',
28
+ },
29
+ 'intent-filter': [
30
+ {
31
+ action: [
32
+ {
33
+ $: {
34
+ 'android:name': 'com.google.firebase.MESSAGING_EVENT',
35
+ },
36
+ },
37
+ ],
38
+ },
39
+ ],
40
+ });
41
+ console.log(
42
+ 'Successfully set CustomerIO push handler as priority in AndroidManifest.xml'
43
+ );
44
+ }
45
+
46
+ props.modResults.manifest.application = application;
47
+ return props;
48
+ });
49
+ };
@@ -1,6 +1,7 @@
1
1
  import type { ExpoConfig } from '@expo/config-types';
2
2
 
3
3
  import type { CustomerIOPluginOptionsAndroid } from '../types/cio-types';
4
+ import { withAndroidManifestUpdates } from './withAndroidManifestUpdates';
4
5
  import { withAppGoogleServices } from './withAppGoogleServices';
5
6
  import { withGistMavenRepository } from './withGistMavenRepository';
6
7
  import { withGoogleServicesJSON } from './withGoogleServicesJSON';
@@ -14,6 +15,9 @@ export function withCIOAndroid(
14
15
  config = withProjectGoogleServices(config, props);
15
16
  config = withAppGoogleServices(config, props);
16
17
  config = withGoogleServicesJSON(config, props);
18
+ if (props.setHighPriorityPushHandler) {
19
+ config = withAndroidManifestUpdates(config, props);
20
+ }
17
21
 
18
22
  return config;
19
23
  }
@@ -74,3 +74,18 @@ target '${CIO_NOTIFICATION_TARGET_NAME}' do
74
74
  use_frameworks! :linkage => :static
75
75
  ${CIO_PODFILE_SNIPPET}
76
76
  end`;
77
+
78
+ export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
79
+ @objc(registerPushNotification:)
80
+ public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {
81
+
82
+ let center = UNUserNotificationCenter.current()
83
+ center.delegate = notificationDelegate
84
+ center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
85
+ if error == nil{
86
+ DispatchQueue.main.async {
87
+ UIApplication.shared.registerForRemoteNotifications()
88
+ }
89
+ }
90
+ }
91
+ }`;
@@ -9,19 +9,7 @@ public class CIOAppPushNotificationsHandler : NSObject {
9
9
 
10
10
  public override init() {}
11
11
 
12
- @objc(registerPushNotification:)
13
- public func registerPushNotification(withNotificationDelegate notificationDelegate: UNUserNotificationCenterDelegate) {
14
-
15
- let center = UNUserNotificationCenter.current()
16
- center.delegate = notificationDelegate
17
- center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
18
- if error == nil{
19
- DispatchQueue.main.async {
20
- UIApplication.shared.registerForRemoteNotifications()
21
- }
22
- }
23
- }
24
- }
12
+ {{REGISTER_SNIPPET}}
25
13
 
26
14
  @objc(application:deviceToken:)
27
15
  public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
@@ -22,6 +22,7 @@ import {
22
22
  injectCodeByMultiLineRegexAndReplaceLine,
23
23
  } from '../helpers/utils/codeInjection';
24
24
  import { FileManagement } from '../helpers/utils/fileManagement';
25
+ import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
25
26
 
26
27
  const pushCodeSnippets = [
27
28
  CIO_DIDRECEIVENOTIFICATIONRESPONSEHANDLER_SNIPPET,
@@ -119,9 +120,9 @@ const addAppdelegateHeaderModification = (stringContents: string) => {
119
120
  return stringContents;
120
121
  };
121
122
 
122
- export const withAppDelegateModifications: ConfigPlugin<any> = (
123
- configOuter
124
- ) => {
123
+ export const withAppDelegateModifications: ConfigPlugin<
124
+ CustomerIOPluginOptionsIOS
125
+ > = (configOuter, props) => {
125
126
  return withAppDelegate(configOuter, async (config) => {
126
127
  let stringContents = config.modResults.contents;
127
128
  const regex = new RegExp(
@@ -142,7 +143,9 @@ export const withAppDelegateModifications: ConfigPlugin<any> = (
142
143
  config.modRequest.projectName as string
143
144
  );
144
145
  stringContents = addNotificationHandlerDeclaration(stringContents);
145
- stringContents = addNotificationConfiguration(stringContents);
146
+ if (!props.disableNotificationRegistration) {
147
+ stringContents = addNotificationConfiguration(stringContents);
148
+ }
146
149
  stringContents = addAdditionalMethodsForPushNotifications(stringContents);
147
150
  stringContents =
148
151
  addDidFailToRegisterForRemoteNotificationsWithError(stringContents);
@@ -3,6 +3,7 @@ import xcode from 'xcode';
3
3
 
4
4
  import {
5
5
  CIO_NOTIFICATION_TARGET_NAME,
6
+ CIO_REGISTER_PUSHNOTIFICATION_SNIPPET,
6
7
  DEFAULT_BUNDLE_VERSION,
7
8
  LOCAL_PATH_TO_CIO_NSE_FILES,
8
9
  } from '../helpers/constants/ios';
@@ -84,6 +85,7 @@ export const withCioNotificationsXcodeProject: ConfigPlugin<
84
85
  }
85
86
 
86
87
  const options = {
88
+ ...props,
87
89
  appleTeamId,
88
90
  bundleIdentifier,
89
91
  bundleShortVersion,
@@ -329,6 +331,7 @@ async function addPushNotificationFile(
329
331
  const file = 'PushService.swift';
330
332
  const appPath = `${iosPath}/${appName}`;
331
333
  const getTargetFile = (filename: string) => `${appPath}/${filename}`;
334
+ const targetFile = getTargetFile(file);
332
335
 
333
336
  // Check whether {file} exists in the project. If false, then add the file
334
337
  // If {file} exists then skip and return
@@ -337,7 +340,6 @@ async function addPushNotificationFile(
337
340
  recursive: true,
338
341
  });
339
342
 
340
- const targetFile = getTargetFile(file);
341
343
  FileManagement.copyFile(
342
344
  `${LOCAL_PATH_TO_CIO_NSE_FILES}/${file}`,
343
345
  targetFile
@@ -347,9 +349,29 @@ async function addPushNotificationFile(
347
349
  return;
348
350
  }
349
351
 
352
+ updatePushFile(options, targetFile);
353
+
350
354
  const group = xcodeProject.pbxCreateGroup('CustomerIONotifications');
351
355
  const classesKey = xcodeProject.findPBXGroupKey({ name: `${appName}` });
352
356
  xcodeProject.addToPbxGroup(group, classesKey);
353
357
 
354
358
  xcodeProject.addSourceFile(`${appName}/${file}`, null, group);
355
359
  }
360
+
361
+ const updatePushFile = (
362
+ options: CustomerIOPluginOptionsIOS,
363
+ envFileName: string
364
+ ) => {
365
+ const REGISTER_RE = /\{\{REGISTER_SNIPPET\}\}/;
366
+
367
+ let envFileContent = FileManagement.readFile(envFileName);
368
+
369
+ let snippet = '';
370
+ if (!options.disableNotificationRegistration) {
371
+ snippet = CIO_REGISTER_PUSHNOTIFICATION_SNIPPET;
372
+ }
373
+
374
+ envFileContent = replaceCodeByRegex(envFileContent, REGISTER_RE, snippet);
375
+
376
+ FileManagement.writeFile(envFileName, envFileContent);
377
+ };
@@ -15,6 +15,7 @@ export type CustomerIOPluginOptionsIOS = {
15
15
  iosDeploymentTarget?: string;
16
16
  appleTeamId?: string;
17
17
  appName?: string;
18
+ disableNotificationRegistration?: boolean;
18
19
  useFrameworks?: 'static' | 'dynamic';
19
20
  pushNotification?: {
20
21
  useRichPush: boolean;
@@ -29,6 +30,7 @@ export type CustomerIOPluginOptionsIOS = {
29
30
  export type CustomerIOPluginOptionsAndroid = {
30
31
  androidPath: string;
31
32
  googleServicesFile?: string;
33
+ setHighPriorityPushHandler?: boolean;
32
34
  };
33
35
 
34
36
  export type CustomerIOPluginOptions = {