customerio-expo-plugin 2.0.2 → 2.1.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 (76) hide show
  1. package/package.json +10 -10
  2. package/plugin/lib/commonjs/android/withAndroidManifestUpdates.js.map +1 -1
  3. package/plugin/lib/commonjs/android/withAppGoogleServices.js.map +1 -1
  4. package/plugin/lib/commonjs/android/withGistMavenRepository.js.map +1 -1
  5. package/plugin/lib/commonjs/android/withGoogleServicesJSON.js.map +1 -1
  6. package/plugin/lib/commonjs/android/withProjectGoogleServices.js.map +1 -1
  7. package/plugin/lib/commonjs/android/withProjectStrings.js.map +1 -1
  8. package/plugin/lib/commonjs/helpers/constants/ios.js +27 -1
  9. package/plugin/lib/commonjs/helpers/constants/ios.js.map +1 -1
  10. package/plugin/lib/commonjs/helpers/native-files/ios/apn/CioSdkAppDelegateHandler.swift +52 -0
  11. package/plugin/lib/commonjs/helpers/native-files/ios/fcm/CioSdkAppDelegateHandler.swift +74 -0
  12. package/plugin/lib/commonjs/helpers/utils/fileManagement.js.map +1 -1
  13. package/plugin/lib/commonjs/ios/utils.js +17 -2
  14. package/plugin/lib/commonjs/ios/utils.js.map +1 -1
  15. package/plugin/lib/commonjs/ios/withAppDelegateModifications.js.map +1 -1
  16. package/plugin/lib/commonjs/ios/withCIOIos.js +8 -1
  17. package/plugin/lib/commonjs/ios/withCIOIos.js.map +1 -1
  18. package/plugin/lib/commonjs/ios/withCIOIosSwift.js +269 -0
  19. package/plugin/lib/commonjs/ios/withCIOIosSwift.js.map +1 -0
  20. package/plugin/lib/commonjs/ios/withGoogleServicesJsonFile.js.map +1 -1
  21. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js +4 -3
  22. package/plugin/lib/commonjs/ios/withNotificationsXcodeProject.js.map +1 -1
  23. package/plugin/lib/commonjs/ios/withXcodeProject.js.map +1 -1
  24. package/plugin/lib/module/android/withAndroidManifestUpdates.js.map +1 -1
  25. package/plugin/lib/module/android/withAppGoogleServices.js.map +1 -1
  26. package/plugin/lib/module/android/withGistMavenRepository.js.map +1 -1
  27. package/plugin/lib/module/android/withGoogleServicesJSON.js.map +1 -1
  28. package/plugin/lib/module/android/withProjectGoogleServices.js.map +1 -1
  29. package/plugin/lib/module/android/withProjectStrings.js.map +1 -1
  30. package/plugin/lib/module/helpers/constants/ios.js +26 -0
  31. package/plugin/lib/module/helpers/constants/ios.js.map +1 -1
  32. package/plugin/lib/module/helpers/native-files/ios/apn/CioSdkAppDelegateHandler.swift +52 -0
  33. package/plugin/lib/module/helpers/native-files/ios/fcm/CioSdkAppDelegateHandler.swift +74 -0
  34. package/plugin/lib/module/helpers/utils/fileManagement.js.map +1 -1
  35. package/plugin/lib/module/ios/utils.js +15 -1
  36. package/plugin/lib/module/ios/utils.js.map +1 -1
  37. package/plugin/lib/module/ios/withAppDelegateModifications.js.map +1 -1
  38. package/plugin/lib/module/ios/withCIOIos.js +8 -1
  39. package/plugin/lib/module/ios/withCIOIos.js.map +1 -1
  40. package/plugin/lib/module/ios/withCIOIosSwift.js +262 -0
  41. package/plugin/lib/module/ios/withCIOIosSwift.js.map +1 -0
  42. package/plugin/lib/module/ios/withGoogleServicesJsonFile.js.map +1 -1
  43. package/plugin/lib/module/ios/withNotificationsXcodeProject.js +5 -4
  44. package/plugin/lib/module/ios/withNotificationsXcodeProject.js.map +1 -1
  45. package/plugin/lib/module/ios/withXcodeProject.js.map +1 -1
  46. package/plugin/lib/typescript/android/withAndroidManifestUpdates.d.ts +1 -1
  47. package/plugin/lib/typescript/android/withAppGoogleServices.d.ts +1 -1
  48. package/plugin/lib/typescript/android/withGistMavenRepository.d.ts +1 -1
  49. package/plugin/lib/typescript/android/withGoogleServicesJSON.d.ts +1 -1
  50. package/plugin/lib/typescript/android/withProjectGoogleServices.d.ts +1 -1
  51. package/plugin/lib/typescript/android/withProjectStrings.d.ts +1 -1
  52. package/plugin/lib/typescript/helpers/constants/ios.d.ts +3 -0
  53. package/plugin/lib/typescript/helpers/utils/fileManagement.d.ts +1 -2
  54. package/plugin/lib/typescript/ios/utils.d.ts +2 -0
  55. package/plugin/lib/typescript/ios/withAppDelegateModifications.d.ts +1 -1
  56. package/plugin/lib/typescript/ios/withCIOIosSwift.d.ts +3 -0
  57. package/plugin/lib/typescript/ios/withGoogleServicesJsonFile.d.ts +1 -1
  58. package/plugin/lib/typescript/ios/withNotificationsXcodeProject.d.ts +1 -1
  59. package/plugin/lib/typescript/ios/withXcodeProject.d.ts +1 -1
  60. package/plugin/src/android/withAndroidManifestUpdates.ts +2 -1
  61. package/plugin/src/android/withAppGoogleServices.ts +2 -1
  62. package/plugin/src/android/withGistMavenRepository.ts +2 -1
  63. package/plugin/src/android/withGoogleServicesJSON.ts +2 -1
  64. package/plugin/src/android/withProjectGoogleServices.ts +2 -1
  65. package/plugin/src/android/withProjectStrings.ts +2 -1
  66. package/plugin/src/helpers/constants/ios.ts +29 -0
  67. package/plugin/src/helpers/native-files/ios/apn/CioSdkAppDelegateHandler.swift +52 -0
  68. package/plugin/src/helpers/native-files/ios/fcm/CioSdkAppDelegateHandler.swift +74 -0
  69. package/plugin/src/helpers/utils/fileManagement.ts +1 -1
  70. package/plugin/src/ios/utils.ts +20 -3
  71. package/plugin/src/ios/withAppDelegateModifications.ts +2 -1
  72. package/plugin/src/ios/withCIOIos.ts +15 -2
  73. package/plugin/src/ios/withCIOIosSwift.ts +384 -0
  74. package/plugin/src/ios/withGoogleServicesJsonFile.ts +1 -1
  75. package/plugin/src/ios/withNotificationsXcodeProject.ts +9 -9
  76. package/plugin/src/ios/withXcodeProject.ts +2 -1
@@ -1,3 +1,3 @@
1
- import { ConfigPlugin } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
2
  import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
3
3
  export declare const withCioNotificationsXcodeProject: ConfigPlugin<CustomerIOPluginOptionsIOS>;
@@ -1,3 +1,3 @@
1
- import { ConfigPlugin } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
2
  import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
3
3
  export declare const withCioXcodeProject: ConfigPlugin<CustomerIOPluginOptionsIOS>;
@@ -1,4 +1,5 @@
1
- import { ConfigPlugin, withAndroidManifest } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
+ import { withAndroidManifest } from '@expo/config-plugins';
2
3
  import type { ManifestApplication } from '@expo/config-plugins/build/android/Manifest';
3
4
 
4
5
  import type { CustomerIOPluginOptionsAndroid } from '../types/cio-types';
@@ -1,4 +1,5 @@
1
- import { ConfigPlugin, withAppBuildGradle } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
+ import { withAppBuildGradle } from '@expo/config-plugins';
2
3
 
3
4
  import {
4
5
  CIO_APP_APPLY_REGEX,
@@ -1,4 +1,5 @@
1
- import { withProjectBuildGradle, ConfigPlugin } from '@expo/config-plugins';
1
+ import { withProjectBuildGradle } from '@expo/config-plugins';
2
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
3
 
3
4
  import {
4
5
  CIO_GIST_MAVEN_REGEX,
@@ -1,4 +1,5 @@
1
- import { withProjectBuildGradle, ConfigPlugin } from '@expo/config-plugins';
1
+ import { withProjectBuildGradle } from '@expo/config-plugins';
2
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
3
 
3
4
  import { FileManagement } from './../helpers/utils/fileManagement';
4
5
  import type { CustomerIOPluginOptionsAndroid } from './../types/cio-types';
@@ -1,4 +1,5 @@
1
- import { ConfigPlugin, withProjectBuildGradle } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
+ import { withProjectBuildGradle } from '@expo/config-plugins';
2
3
 
3
4
  import {
4
5
  CIO_PROJECT_BUILDSCRIPTS_REGEX,
@@ -1,4 +1,5 @@
1
- import { ConfigPlugin, withStringsXml } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
+ import { withStringsXml } from '@expo/config-plugins';
2
3
  import { getPluginVersion } from '../helpers/utils/pluginUtils';
3
4
 
4
5
  /**
@@ -129,6 +129,23 @@ NSMutableDictionary *modifiedLaunchOptions = [NSMutableDictionary dictionaryWith
129
129
  //Deep link workaround for app killed state ends
130
130
  `;
131
131
 
132
+ export const CIO_CONFIGUREDEEPLINK_KILLEDSTATE_SWIFT_SNIPPET = `
133
+ // Deep link workaround for app killed state start
134
+ var modifiedLaunchOptions = launchOptions
135
+ if let launchOptions = launchOptions,
136
+ let pushContent = launchOptions[UIApplication.LaunchOptionsKey.remoteNotification] as? [AnyHashable: Any],
137
+ let cio = pushContent["CIO"] as? [String: Any],
138
+ let push = cio["push"] as? [String: Any],
139
+ let link = push["link"] as? String,
140
+ !launchOptions.keys.contains(UIApplication.LaunchOptionsKey.url) {
141
+
142
+ var mutableLaunchOptions = launchOptions
143
+ mutableLaunchOptions[UIApplication.LaunchOptionsKey.url] = URL(string: link)
144
+ modifiedLaunchOptions = mutableLaunchOptions
145
+ }
146
+ // Deep link workaround for app killed state ends
147
+ `;
148
+
132
149
  export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
133
150
  @objc(registerPushNotification)
134
151
  public func registerPushNotification() {
@@ -142,3 +159,15 @@ export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET = `
142
159
  }
143
160
  }
144
161
  }`;
162
+
163
+ export const CIO_REGISTER_PUSHNOTIFICATION_SNIPPET_v2 = `
164
+ let center = UNUserNotificationCenter.current()
165
+ center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
166
+ if error == nil{
167
+ DispatchQueue.main.async {
168
+ UIApplication.shared.registerForRemoteNotifications()
169
+ }
170
+ }
171
+ }`;
172
+
173
+ export const CIO_REGISTER_PUSH_NOTIFICATION_PLACEHOLDER = /\{\{REGISTER_SNIPPET\}\}/;
@@ -0,0 +1,52 @@
1
+ import Foundation
2
+ import UIKit
3
+ import UserNotifications
4
+ import CioMessagingPushAPN
5
+ #if canImport(EXNotifications)
6
+ import EXNotifications
7
+ import ExpoModulesCore
8
+ #endif
9
+
10
+ public class CioSdkAppDelegateHandler: NSObject {
11
+
12
+ public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
13
+
14
+ {{REGISTER_SNIPPET}}
15
+
16
+ MessagingPushAPN.initialize(
17
+ withConfig: MessagingPushConfigBuilder()
18
+ .autoFetchDeviceToken({{AUTO_FETCH_DEVICE_TOKEN}})
19
+ .showPushAppInForeground({{SHOW_PUSH_APP_IN_FOREGROUND}})
20
+ .autoTrackPushEvents({{AUTO_TRACK_PUSH_EVENTS}})
21
+ .build()
22
+ )
23
+
24
+ // Code to make the CIO SDK compatible with expo-notifications package.
25
+ //
26
+ // The CIO SDK and expo-notifications both need to handle when a push gets clicked. However, iOS only allows one click handler to be set per app.
27
+ // To get around this limitation, we set the CIO SDK as the click handler. The CIO SDK sets itself up so that when another SDK or host iOS app
28
+ // sets itself as the click handler, the CIO SDK will still be able to handle when the push gets clicked, even though it's not the designated
29
+ // click handler in iOS at runtime.
30
+ //
31
+ // This should work for most SDKs. However, expo-notifications is unique in its implementation. It will not setup push click handling if it detects
32
+ // that another SDK or host iOS app has already set itself as the click handler.
33
+ // To get around this, we must manually set it as the click handler after the CIO SDK. That's what this code block does.
34
+ //
35
+ // Note: Initialize the native iOS SDK and setup SDK push click handling before running this code.
36
+ #if canImport(EXNotifications)
37
+ // Getting the singleton reference from Expo
38
+ if let notificationCenterDelegate = ModuleRegistryProvider.getSingletonModule(for: NotificationCenterManager.self) as? UNUserNotificationCenterDelegate {
39
+ let center = UNUserNotificationCenter.current()
40
+ center.delegate = notificationCenterDelegate
41
+ }
42
+ #endif
43
+ }
44
+
45
+ public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
46
+ MessagingPush.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
47
+ }
48
+
49
+ public func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
50
+ MessagingPush.shared.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
51
+ }
52
+ }
@@ -0,0 +1,74 @@
1
+ import Foundation
2
+ import CioMessagingPushFCM
3
+ import FirebaseCore
4
+ import FirebaseMessaging
5
+ import UserNotifications
6
+ import UIKit
7
+ #if canImport(EXNotifications)
8
+ import EXNotifications
9
+ import ExpoModulesCore
10
+ #endif
11
+
12
+ public class CioSdkAppDelegateHandler: NSObject {
13
+
14
+ public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
15
+
16
+ {{REGISTER_SNIPPET}}
17
+
18
+ if (FirebaseApp.app() == nil) {
19
+ FirebaseApp.configure()
20
+ }
21
+ Messaging.messaging().delegate = self
22
+ UIApplication.shared.registerForRemoteNotifications()
23
+
24
+ MessagingPushFCM.initialize(
25
+ withConfig: MessagingPushConfigBuilder()
26
+ .autoFetchDeviceToken({{AUTO_FETCH_DEVICE_TOKEN}})
27
+ .showPushAppInForeground({{SHOW_PUSH_APP_IN_FOREGROUND}})
28
+ .autoTrackPushEvents({{AUTO_TRACK_PUSH_EVENTS}})
29
+ .build()
30
+ )
31
+
32
+ // Code to make the CIO SDK compatible with expo-notifications package.
33
+ //
34
+ // The CIO SDK and expo-notifications both need to handle when a push gets clicked. However, iOS only allows one click handler to be set per app.
35
+ // To get around this limitation, we set the CIO SDK as the click handler. The CIO SDK sets itself up so that when another SDK or host iOS app
36
+ // sets itself as the click handler, the CIO SDK will still be able to handle when the push gets clicked, even though it's not the designated
37
+ // click handler in iOS at runtime.
38
+ //
39
+ // This should work for most SDKs. However, expo-notifications is unique in its implementation. It will not setup push click handling if it detects
40
+ // that another SDK or host iOS app has already set itself as the click handler.
41
+ // To get around this, we must manually set it as the click handler after the CIO SDK. That's what this code block does.
42
+ //
43
+ // Note: Initialize the native iOS SDK and setup SDK push click handling before running this code.
44
+ #if canImport(EXNotifications)
45
+ // Getting the singleton reference from Expo
46
+ if let notificationCenterDelegate = ModuleRegistryProvider.getSingletonModule(for: NotificationCenterManager.self) as? UNUserNotificationCenterDelegate {
47
+ let center = UNUserNotificationCenter.current()
48
+ center.delegate = notificationCenterDelegate
49
+ }
50
+ #endif
51
+ }
52
+
53
+ public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
54
+
55
+ }
56
+
57
+ public func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
58
+
59
+ }
60
+ }
61
+
62
+ extension CioSdkAppDelegateHandler: MessagingDelegate {
63
+ public func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
64
+ MessagingPush.shared.messaging(messaging, didReceiveRegistrationToken: fcmToken)
65
+ }
66
+
67
+ func userNotificationCenter(
68
+ _ center: UNUserNotificationCenter,
69
+ willPresent notification: UNNotification,
70
+ withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
71
+ ) {
72
+ completionHandler([.list, .banner, .badge, .sound])
73
+ }
74
+ }
@@ -7,8 +7,8 @@ import {
7
7
  mkdirSync,
8
8
  writeFileSync,
9
9
  readFileSync,
10
- MakeDirectoryOptions,
11
10
  } from 'fs';
11
+ import type { MakeDirectoryOptions } from 'fs';
12
12
 
13
13
  export class FileManagement {
14
14
  static async read(path: string): Promise<string> {
@@ -1,10 +1,27 @@
1
1
  import type { CustomerIOPluginOptionsIOS } from '../types/cio-types';
2
+ import type { ExpoConfig } from '@expo/config-types';
3
+ import * as semver from 'semver';
2
4
 
3
5
  /**
4
6
  * Returns t
5
7
  * @param iosOptions The plugin iOS configuration options
6
8
  * @returns true if FCM is configured to be used as push provider
7
9
  */
8
- export const isFcmPushProvider = (iosOptions?: CustomerIOPluginOptionsIOS): boolean => {
9
- return iosOptions?.pushNotification?.provider === "fcm";
10
- };
10
+ export const isFcmPushProvider = (
11
+ iosOptions?: CustomerIOPluginOptionsIOS
12
+ ): boolean => {
13
+ return iosOptions?.pushNotification?.provider === 'fcm';
14
+ };
15
+
16
+ export const isExpoVersion53OrHigher = (config: ExpoConfig): boolean => {
17
+ const sdkVersion = config.sdkVersion || '';
18
+
19
+ // If sdkVersion is not a valid semver, coerce it to a valid one if possible
20
+ const validVersion = semver.valid(sdkVersion) || semver.coerce(sdkVersion);
21
+
22
+ // If we couldn't get a valid version, return false
23
+ if (!validVersion) return false;
24
+
25
+ // Check if the version is greater than or equal to 53.0.0
26
+ return semver.gte(validVersion, '53.0.0');
27
+ };
@@ -1,4 +1,5 @@
1
- import { ConfigPlugin, withAppDelegate } from '@expo/config-plugins';
1
+ import type { ConfigPlugin } from '@expo/config-plugins';
2
+ import { withAppDelegate } from '@expo/config-plugins';
2
3
  import { getAppDelegateHeaderFilePath } from '@expo/config-plugins/build/ios/Paths';
3
4
 
4
5
  import {
@@ -1,18 +1,30 @@
1
1
  import type { ExpoConfig } from '@expo/config-types';
2
2
 
3
- import type { CustomerIOPluginOptionsIOS, CustomerIOPluginPushNotificationOptions } from '../types/cio-types';
3
+ import type {
4
+ CustomerIOPluginOptionsIOS,
5
+ CustomerIOPluginPushNotificationOptions,
6
+ } from '../types/cio-types';
4
7
  import { withAppDelegateModifications } from './withAppDelegateModifications';
5
8
  import { withCioNotificationsXcodeProject } from './withNotificationsXcodeProject';
6
9
  import { withCioXcodeProject } from './withXcodeProject';
7
10
  import { withGoogleServicesJsonFile } from './withGoogleServicesJsonFile';
11
+ import { withCIOIosSwift } from './withCIOIosSwift';
12
+ import { isExpoVersion53OrHigher } from './utils';
8
13
 
9
14
  export function withCIOIos(
10
15
  config: ExpoConfig,
11
16
  props: CustomerIOPluginOptionsIOS
12
17
  ) {
13
18
  const cioProps = mergeDeprecatedPropertiesAndLogWarnings(props);
19
+ const isSwiftProject = isExpoVersion53OrHigher(config);
20
+
14
21
  if (cioProps.pushNotification) {
15
- config = withAppDelegateModifications(config, cioProps);
22
+ if (isSwiftProject) {
23
+ config = withCIOIosSwift(config, cioProps);
24
+ } else {
25
+ config = withAppDelegateModifications(config, cioProps);
26
+ }
27
+
16
28
  config = withCioNotificationsXcodeProject(config, cioProps);
17
29
  config = withCioXcodeProject(config, cioProps);
18
30
  config = withGoogleServicesJsonFile(config, cioProps);
@@ -70,3 +82,4 @@ const mergeDeprecatedPropertiesAndLogWarnings = (
70
82
 
71
83
  return props;
72
84
  };
85
+