react-native-expo-moengage 1.0.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 (47) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE.txt +8 -0
  3. package/README.md +38 -0
  4. package/android/build.gradle +53 -0
  5. package/android/src/main/AndroidManifest.xml +6 -0
  6. package/android/src/main/java/expo/modules/moengage/MoEExpoFireBaseMessagingService.kt +56 -0
  7. package/android/src/main/java/expo/modules/moengage/MoEngageApplicationLifecycleListener.kt +31 -0
  8. package/android/src/main/java/expo/modules/moengage/MoEngagePackage.kt +12 -0
  9. package/android/src/main/java/expo/modules/moengage/internal/Constants.kt +4 -0
  10. package/android/user-agent.gradle +15 -0
  11. package/app.plugin.js +1 -0
  12. package/apple/ExpoAdapterMoEngage/MoEngageAppDelegate.swift +76 -0
  13. package/apple/ExpoAdapterMoEngage/MoEngageExpoPluginInfo.swift +5 -0
  14. package/apple/ExpoAdapterMoEngage.podspec +40 -0
  15. package/apple/PushTemplates/MainInterface.storyboard +29 -0
  16. package/apple/PushTemplates/MoEngageExpoPushTemplates-Info.plist +45 -0
  17. package/apple/PushTemplates/MoEngageExpoPushTemplates.entitlements +14 -0
  18. package/apple/PushTemplates/NotificationViewController.swift +14 -0
  19. package/apple/RichPush/MoEngageExpoRichPush-Info.plist +31 -0
  20. package/apple/RichPush/MoEngageExpoRichPush.entitlements +14 -0
  21. package/apple/RichPush/NotificationService.swift +20 -0
  22. package/build/android/constants.js +47 -0
  23. package/build/android/types.js +2 -0
  24. package/build/android/utils.js +80 -0
  25. package/build/android/withMoEngageAndroid.js +100 -0
  26. package/build/apple/constants.js +47 -0
  27. package/build/apple/index.js +72 -0
  28. package/build/apple/withDangerousMod.js +275 -0
  29. package/build/apple/withEntitlements.js +117 -0
  30. package/build/apple/withInfoPlist.js +91 -0
  31. package/build/apple/withXcodeProject.js +364 -0
  32. package/build/index.js +37 -0
  33. package/build/types.js +2 -0
  34. package/expo-module.config.json +18 -0
  35. package/package.json +69 -0
  36. package/src/android/constants.ts +52 -0
  37. package/src/android/types.ts +1 -0
  38. package/src/android/utils.ts +74 -0
  39. package/src/android/withMoEngageAndroid.ts +127 -0
  40. package/src/apple/constants.ts +48 -0
  41. package/src/apple/index.ts +38 -0
  42. package/src/apple/withDangerousMod.ts +265 -0
  43. package/src/apple/withEntitlements.ts +81 -0
  44. package/src/apple/withInfoPlist.ts +63 -0
  45. package/src/apple/withXcodeProject.ts +418 -0
  46. package/src/index.ts +52 -0
  47. package/src/types.ts +100 -0
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.withMoEngageEntitlements = void 0;
37
+ const config_plugins_1 = require("@expo/config-plugins");
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const plist = require('plist');
41
+ /**
42
+ * MoEngage Expo plugin for iOS - Entitlements modifications
43
+ *
44
+ * This plugin configures the app's entitlements file to enable MoEngage features by:
45
+ * 1. Reading the AppGroupName from the MoEngage configuration file
46
+ * 2. Adding app groups to entitlements for push notifications and extensions
47
+ * 3. Setting up keychain sharing if configured
48
+ * 4. Adding any other required entitlements for MoEngage features
49
+ *
50
+ * @param config - The Expo config object
51
+ * @param props - The MoEngage plugin properties
52
+ * @returns The updated config with modified entitlements
53
+ */
54
+ const withMoEngageEntitlements = (config, props) => {
55
+ return (0, config_plugins_1.withEntitlementsPlist)(config, (config) => {
56
+ // Import configuration from plist file if specified
57
+ try {
58
+ const configFilePath = path.join(config.modRequest.projectRoot, props.apple.configFilePath);
59
+ if (fs.existsSync(configFilePath)) {
60
+ const configPlist = plist.parse(fs.readFileSync(configFilePath, 'utf8'));
61
+ // Add the app group to the main application target's entitlements if rich push or push templates are enabled
62
+ const appGroupsKey = 'com.apple.security.application-groups';
63
+ const appGroupValue = configPlist['AppGroupName'];
64
+ if (props.apple.pushTemplatesEnabled || props.apple.richPushNotificationEnabled || props.apple.pushNotificationImpressionTrackingEnabled) {
65
+ if (appGroupValue && appGroupValue.length > 0) {
66
+ const existingAppGroups = config.modResults[appGroupsKey];
67
+ if (Array.isArray(existingAppGroups)) {
68
+ if (!existingAppGroups.includes(appGroupValue)) {
69
+ config.modResults[appGroupsKey] = existingAppGroups.concat([appGroupValue]);
70
+ }
71
+ }
72
+ else {
73
+ config.modResults[appGroupsKey] = [appGroupValue];
74
+ }
75
+ }
76
+ else {
77
+ const message = `Missing AppGroupName key in MoEngage configuration`;
78
+ console.error(message);
79
+ throw new Error(message);
80
+ }
81
+ }
82
+ // Add the keychain access groups to the main application target's entitlements if specified
83
+ const keychainGroupsKey = 'keychain-access-groups';
84
+ const keychainGroupValue = configPlist['KeychainGroupName'];
85
+ const isStorageEncryptionEnabled = configPlist['IsStorageEncryptionEnabled'];
86
+ if (isStorageEncryptionEnabled && (!keychainGroupValue || keychainGroupValue.length == 0)) {
87
+ const message = `KeychainGroupName in "${configFilePath}" is required when IsStorageEncryptionEnabled is true`;
88
+ console.error(message);
89
+ throw new Error(message);
90
+ }
91
+ if (keychainGroupValue && keychainGroupValue.length > 0) {
92
+ const existingKeychainGroups = config.modResults[keychainGroupsKey];
93
+ if (Array.isArray(existingKeychainGroups)) {
94
+ if (!existingKeychainGroups.includes(keychainGroupValue)) {
95
+ config.modResults[keychainGroupsKey] = existingKeychainGroups.concat([keychainGroupValue]);
96
+ }
97
+ }
98
+ else {
99
+ config.modResults[keychainGroupsKey] = [keychainGroupValue];
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ const message = `MoEngage configuration does not exist`;
105
+ console.error(message);
106
+ throw new Error(message);
107
+ }
108
+ }
109
+ catch (e) {
110
+ const message = `Could not import MoEngage configuration: ${e}`;
111
+ console.error(message);
112
+ throw new Error(message);
113
+ }
114
+ return config;
115
+ });
116
+ };
117
+ exports.withMoEngageEntitlements = withMoEngageEntitlements;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.withMoEngageInfoPlist = void 0;
37
+ const config_plugins_1 = require("@expo/config-plugins");
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const plist = require('plist');
41
+ /**
42
+ * MoEngage Expo plugin for iOS - Info.plist modifications
43
+ *
44
+ * This plugin configures the Info.plist file with MoEngage settings, including:
45
+ * 1. Importing configuration from the MoEngage plist file
46
+ * 2. Setting up notification service extensions
47
+ * 3. Configuring required app settings for MoEngage SDK
48
+ *
49
+ * @param config - The Expo config object
50
+ * @param props - The MoEngage plugin properties
51
+ * @returns The updated config with Info.plist modifications
52
+ */
53
+ const withMoEngageInfoPlist = (config, props) => {
54
+ return (0, config_plugins_1.withInfoPlist)(config, (config) => {
55
+ const { apple } = props;
56
+ // Initialize MoEngage configuration in Info.plist
57
+ config.modResults['MoEngage'] = config.modResults['MoEngage'] || {};
58
+ // Import configuration from plist file if specified
59
+ try {
60
+ const configFilePath = path.join(config.modRequest.projectRoot, apple.configFilePath);
61
+ if (fs.existsSync(configFilePath)) {
62
+ const configPlist = plist.parse(fs.readFileSync(configFilePath, 'utf8'));
63
+ // Merge the configuration from the plist file with existing MoEngage settings
64
+ config.modResults['MoEngage'] = Object.assign(Object.assign({}, config.modResults['MoEngage']), configPlist);
65
+ }
66
+ else {
67
+ const message = `MoEngage configuration does not exist`;
68
+ console.error(message);
69
+ throw new Error(message);
70
+ }
71
+ }
72
+ catch (e) {
73
+ const message = `Could not import MoEngage configuration: ${e}`;
74
+ console.error(message);
75
+ throw new Error(message);
76
+ }
77
+ /**
78
+ * Set up Live Activities support in the Info.plist if enabled
79
+ *
80
+ * This adds the NSSupportsLiveActivities key to Info.plist, which is required
81
+ * for the app to support Live Activities on iOS. We only enable this if:
82
+ * 1. The app is not a tvOS app (Live Activities aren't supported on tvOS)
83
+ * 2. A Live Activity target path has been specified in the plugin configuration
84
+ */
85
+ if (!process.env['EXPO_TV'] && apple.liveActivityTargetPath && apple.liveActivityTargetPath.length) {
86
+ config.modResults['NSSupportsLiveActivities'] = true;
87
+ }
88
+ return config;
89
+ });
90
+ };
91
+ exports.withMoEngageInfoPlist = withMoEngageInfoPlist;
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.withMoEngageXcodeProject = void 0;
37
+ exports.withLiveActivity = withLiveActivity;
38
+ const config_plugins_1 = require("@expo/config-plugins");
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const constants_1 = require("./constants");
42
+ const plist = require('plist');
43
+ /**
44
+ * MoEngage Expo plugin for iOS - Xcode project modifications
45
+ *
46
+ * This plugin configures the Xcode project to include MoEngage extensions for rich notifications,
47
+ * push templates, and LiveActivity. It reads configuration from the MoEngage plist file and sets up
48
+ * the necessary targets, PBX groups, and build phases.
49
+ *
50
+ * @param config - The Expo config object
51
+ * @param props - The MoEngage plugin properties
52
+ * @returns The updated config object with Xcode project modifications
53
+ */
54
+ const withMoEngageXcodeProject = (config, props) => {
55
+ return (0, config_plugins_1.withXcodeProject)(config, (config) => {
56
+ var _a, _b;
57
+ if (process.env['EXPO_TV']) {
58
+ // Skip modifications for tvOS
59
+ console.log(`Skipping extension targets setup for tvOS`);
60
+ return config;
61
+ }
62
+ const { apple } = props;
63
+ const shouldAddRichPushExtension = apple.richPushNotificationEnabled || apple.pushNotificationImpressionTrackingEnabled || apple.pushTemplatesEnabled;
64
+ // Get app group from plist file if specified
65
+ let appGroupValue = '';
66
+ try {
67
+ const configFilePath = path.join(config.modRequest.projectRoot, props.apple.configFilePath);
68
+ if (fs.existsSync(configFilePath)) {
69
+ const configPlist = plist.parse(fs.readFileSync(configFilePath, 'utf8'));
70
+ appGroupValue = configPlist['AppGroupName'];
71
+ if (!appGroupValue) {
72
+ const message = `Missing AppGroupName key in MoEngage configuration`;
73
+ console.error(message);
74
+ throw new Error(message);
75
+ }
76
+ }
77
+ else {
78
+ const message = `MoEngage configuration does not exist`;
79
+ console.error(message);
80
+ throw new Error(message);
81
+ }
82
+ }
83
+ catch (e) {
84
+ const message = `Could not import MoEngage configuration: ${e}`;
85
+ console.error(message);
86
+ throw new Error(message);
87
+ }
88
+ // Initialize with an empty object if these top-level objects are non-existent.
89
+ // This guarantees that the extension targets will have a destination.
90
+ const objects = config.modResults.hash.project.objects;
91
+ objects['PBXTargetDependency'] = objects['PBXTargetDependency'] || {};
92
+ objects['PBXContainerItemProxy'] = objects['PBXContainerItemProxy'] || {};
93
+ const groups = objects['PBXGroup'];
94
+ const xcconfigs = objects['XCBuildConfiguration'];
95
+ // Retrieve Swift version and code signing settings from main target to apply to dependency targets.
96
+ let swiftVersion;
97
+ let codeSignStyle;
98
+ let codeSignIdentity;
99
+ let otherCodeSigningFlags;
100
+ let developmentTeam;
101
+ let provisioningProfile;
102
+ for (const configUUID of Object.keys(xcconfigs)) {
103
+ const buildSettings = xcconfigs[configUUID].buildSettings;
104
+ if (!swiftVersion && buildSettings && buildSettings.SWIFT_VERSION) {
105
+ swiftVersion = buildSettings.SWIFT_VERSION;
106
+ codeSignStyle = buildSettings.CODE_SIGN_STYLE;
107
+ codeSignIdentity = buildSettings.CODE_SIGN_IDENTITY;
108
+ otherCodeSigningFlags = buildSettings.OTHER_CODE_SIGN_FLAGS;
109
+ developmentTeam = buildSettings.DEVELOPMENT_TEAM;
110
+ provisioningProfile = buildSettings.PROVISIONING_PROFILE_SPECIFIER;
111
+ break;
112
+ }
113
+ }
114
+ // Rich Push Notification Service Extension
115
+ if (shouldAddRichPushExtension && !config.modResults.pbxGroupByName(constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET)) {
116
+ // Add the Notification Service Extension target.
117
+ const richPushTarget = config.modResults.addTarget(constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET, 'app_extension', constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET, `${(_a = config.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier}.${constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET}`);
118
+ // Add the relevant files to the PBX group.
119
+ const moengageNotificationServiceGroup = config.modResults.addPbxGroup(constants_1.MOENGAGE_IOS_RICH_PUSH_FILES, constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET, constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET);
120
+ for (const groupUUID of Object.keys(groups)) {
121
+ if (typeof groups[groupUUID] === 'object'
122
+ && groups[groupUUID].name === undefined
123
+ && groups[groupUUID].path === undefined) {
124
+ config.modResults.addToPbxGroup(moengageNotificationServiceGroup.uuid, groupUUID);
125
+ }
126
+ }
127
+ ;
128
+ for (const configUUID of Object.keys(xcconfigs)) {
129
+ const buildSettings = xcconfigs[configUUID].buildSettings;
130
+ if (buildSettings && buildSettings.PRODUCT_NAME === `"${constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET}"`) {
131
+ buildSettings.MOENGAGE_APP_GROUP = appGroupValue;
132
+ buildSettings.SWIFT_VERSION = swiftVersion;
133
+ buildSettings.CODE_SIGN_ENTITLEMENTS = `${constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET}/${constants_1.MOENGAGE_IOS_RICH_PUSH_TARGET}.entitlements`;
134
+ if (codeSignStyle) {
135
+ buildSettings.CODE_SIGN_STYLE = codeSignStyle;
136
+ }
137
+ if (codeSignIdentity) {
138
+ buildSettings.CODE_SIGN_IDENTITY = codeSignIdentity;
139
+ }
140
+ if (otherCodeSigningFlags) {
141
+ buildSettings.OTHER_CODE_SIGN_FLAGS = otherCodeSigningFlags;
142
+ }
143
+ if (developmentTeam) {
144
+ buildSettings.DEVELOPMENT_TEAM = developmentTeam;
145
+ }
146
+ if (provisioningProfile) {
147
+ buildSettings.PROVISIONING_PROFILE_SPECIFIER = provisioningProfile;
148
+ }
149
+ }
150
+ }
151
+ // Set up target build phase scripts.
152
+ config.modResults.addBuildPhase([
153
+ 'NotificationService.swift',
154
+ ], 'PBXSourcesBuildPhase', 'Sources', richPushTarget.uuid);
155
+ config.modResults.addBuildPhase(['UserNotifications.framework'], 'PBXFrameworksBuildPhase', 'Frameworks', richPushTarget.uuid);
156
+ }
157
+ // Push Templates Notification Content Extension
158
+ if (apple.pushTemplatesEnabled && !config.modResults.pbxGroupByName(constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET)) {
159
+ // Add the Notification Content Extension target.
160
+ const pushTemplateTarget = config.modResults.addTarget(constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET, 'app_extension', constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET, `${(_b = config.ios) === null || _b === void 0 ? void 0 : _b.bundleIdentifier}.${constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET}`);
161
+ // Add the relevant files to the PBX group.
162
+ const moengageNotificationContentGroup = config.modResults.addPbxGroup(constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_FILES, constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET, constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET);
163
+ for (const groupUUID of Object.keys(groups)) {
164
+ if (typeof groups[groupUUID] === 'object'
165
+ && groups[groupUUID].name === undefined
166
+ && groups[groupUUID].path === undefined) {
167
+ config.modResults.addToPbxGroup(moengageNotificationContentGroup.uuid, groupUUID);
168
+ }
169
+ }
170
+ ;
171
+ for (const configUUID of Object.keys(xcconfigs)) {
172
+ const buildSettings = xcconfigs[configUUID].buildSettings;
173
+ if (buildSettings && buildSettings.PRODUCT_NAME === `"${constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET}"`) {
174
+ buildSettings.MOENGAGE_APP_GROUP = appGroupValue;
175
+ buildSettings.SWIFT_VERSION = swiftVersion;
176
+ buildSettings.CODE_SIGN_ENTITLEMENTS = `${constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET}/${constants_1.MOENGAGE_IOS_PUSH_TEMPLATE_TARGET}.entitlements`;
177
+ if (codeSignStyle) {
178
+ buildSettings.CODE_SIGN_STYLE = codeSignStyle;
179
+ }
180
+ if (codeSignIdentity) {
181
+ buildSettings.CODE_SIGN_IDENTITY = codeSignIdentity;
182
+ }
183
+ if (otherCodeSigningFlags) {
184
+ buildSettings.OTHER_CODE_SIGN_FLAGS = otherCodeSigningFlags;
185
+ }
186
+ if (developmentTeam) {
187
+ buildSettings.DEVELOPMENT_TEAM = developmentTeam;
188
+ }
189
+ if (provisioningProfile) {
190
+ buildSettings.PROVISIONING_PROFILE_SPECIFIER = provisioningProfile;
191
+ }
192
+ }
193
+ }
194
+ // Set up target build phase scripts.
195
+ config.modResults.addBuildPhase([
196
+ 'NotificationViewController.swift',
197
+ ], 'PBXSourcesBuildPhase', 'Sources', pushTemplateTarget.uuid);
198
+ config.modResults.addBuildPhase([
199
+ 'MainInterface.storyboard',
200
+ ], 'PBXResourcesBuildPhase', 'Resources', pushTemplateTarget.uuid);
201
+ config.modResults.addBuildPhase([
202
+ 'UserNotifications.framework',
203
+ 'UserNotificationsUI.framework'
204
+ ], 'PBXFrameworksBuildPhase', 'Frameworks', pushTemplateTarget.uuid);
205
+ }
206
+ // Handle Live Activity configuration if targetPath is provided
207
+ if (apple.liveActivityTargetPath && apple.liveActivityTargetPath.length && !config.modResults.pbxGroupByName(constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET)) {
208
+ config = withLiveActivity(config, apple.liveActivityTargetPath, {
209
+ swiftVersion,
210
+ codeSignStyle,
211
+ codeSignIdentity,
212
+ otherCodeSigningFlags,
213
+ developmentTeam,
214
+ provisioningProfile
215
+ });
216
+ }
217
+ return config;
218
+ });
219
+ };
220
+ exports.withMoEngageXcodeProject = withMoEngageXcodeProject;
221
+ /**
222
+ * Adds Live Activity extension target to the Xcode project
223
+ *
224
+ * This function configures a LiveActivity extension by:
225
+ * 1. Creating the target and PBX groups
226
+ * 2. Scanning the provided directory for source files, resources, and configuration files
227
+ * 3. Adding all files to appropriate build phases
228
+ * 4. Setting up build settings including code signing and entitlements
229
+ *
230
+ * @param config - Expo config with Xcode project
231
+ * @param liveActivityTargetPath - Path to the LiveActivity source files
232
+ * @param codeSignSettings - Code signing settings to apply to the target
233
+ * @returns The updated config object
234
+ */
235
+ function withLiveActivity(config, liveActivityTargetPath, codeSignSettings) {
236
+ var _a;
237
+ const liveActivityPath = path.join(config.modRequest.projectRoot, liveActivityTargetPath);
238
+ const objects = config.modResults.hash.project.objects;
239
+ const xcconfigs = objects['XCBuildConfiguration'];
240
+ const groups = objects['PBXGroup'];
241
+ // Add the Live Activity target
242
+ const liveActivityTarget = config.modResults.addTarget(constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET, 'app_extension', constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET, `${(_a = config.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier}.${constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET}`);
243
+ // Add the relevant files to the PBX group.
244
+ const moengageLiveActivityPathContentGroup = config.modResults.addPbxGroup([], constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET, liveActivityPath);
245
+ for (const groupUUID of Object.keys(groups)) {
246
+ if (typeof groups[groupUUID] === 'object'
247
+ && groups[groupUUID].name === undefined
248
+ && groups[groupUUID].path === undefined) {
249
+ config.modResults.addToPbxGroup(moengageLiveActivityPathContentGroup.uuid, groupUUID);
250
+ }
251
+ }
252
+ ;
253
+ // Find all .xcassets files, source files, header files,
254
+ // info plist file and entitlements file in liveActivityTargetPath
255
+ let entitlementsFile = '';
256
+ let infoPlistFile = '';
257
+ let resourcesFiles = [];
258
+ let sourceFiles = [];
259
+ let headerFiles = [];
260
+ try {
261
+ const findFilesRecursively = (directory, group) => {
262
+ let items = fs.readdirSync(directory, { withFileTypes: true });
263
+ for (const item of items) {
264
+ const itemPath = path.join(directory, item.name);
265
+ const ext = path.extname(item.name).toLowerCase();
266
+ if (item.isDirectory()) {
267
+ if (['.xcassets'].includes(ext)) {
268
+ resourcesFiles.push(itemPath);
269
+ console.log(`Found ${itemPath} as resource for LiveActivity`);
270
+ }
271
+ else {
272
+ // Recursively read directories
273
+ const group = config.modResults.addPbxGroup([], item.name, itemPath);
274
+ config.modResults.addToPbxGroup(group.uuid, moengageLiveActivityPathContentGroup.uuid);
275
+ findFilesRecursively(itemPath, group);
276
+ continue;
277
+ }
278
+ }
279
+ else if (['.swift', '.m', '.c', '.cpp'].includes(ext)) {
280
+ sourceFiles.push(itemPath);
281
+ console.log(`Found ${itemPath} as source file for LiveActivity`);
282
+ }
283
+ else if (['.h'].includes(ext)) {
284
+ headerFiles.push(itemPath);
285
+ console.log(`Found ${itemPath} as header file for LiveActivity`);
286
+ }
287
+ else if (['.entitlements'].includes(ext)) {
288
+ entitlementsFile = itemPath;
289
+ console.log(`Found ${itemPath} as entitlements file for LiveActivity`);
290
+ }
291
+ else if (item.name === 'Info.plist' ||
292
+ item.name === `${constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET}-Info.plist` ||
293
+ item.name === `${path.basename(path.dirname(liveActivityTargetPath !== null && liveActivityTargetPath !== void 0 ? liveActivityTargetPath : ''))}-Info.plist`) {
294
+ infoPlistFile = itemPath;
295
+ console.log(`Found ${itemPath} as Info.plist file for LiveActivity`);
296
+ }
297
+ else {
298
+ resourcesFiles.push(itemPath);
299
+ console.log(`Found ${itemPath} as resource for LiveActivity`);
300
+ }
301
+ // Add file to project
302
+ config.modResults.addFile(itemPath, group.uuid);
303
+ }
304
+ };
305
+ // Find all files
306
+ findFilesRecursively(liveActivityPath, moengageLiveActivityPathContentGroup);
307
+ }
308
+ catch (e) {
309
+ const message = `Error finding files in Live Activity path: ${e}`;
310
+ console.error(message);
311
+ throw new Error(message);
312
+ }
313
+ // Set up build settings for the Live Activity target
314
+ for (const configUUID of Object.keys(xcconfigs)) {
315
+ const buildSettings = xcconfigs[configUUID].buildSettings;
316
+ if (buildSettings && buildSettings.PRODUCT_NAME === `"${constants_1.MOENGAGE_IOS_LIVE_ACTIVITY_TARGET}"`) {
317
+ buildSettings.SWIFT_VERSION = codeSignSettings.swiftVersion;
318
+ buildSettings.IPHONEOS_DEPLOYMENT_TARGET = '18.0'; // Set minimum iOS version for Live Activity
319
+ // Add entitlements file if found
320
+ if (entitlementsFile && entitlementsFile.length) {
321
+ buildSettings.CODE_SIGN_ENTITLEMENTS = `${entitlementsFile}`;
322
+ }
323
+ // Add Info.plist file if found
324
+ if (infoPlistFile && infoPlistFile.length) {
325
+ buildSettings.INFOPLIST_FILE = `${infoPlistFile}`;
326
+ }
327
+ // Copy code signing settings from main target
328
+ if (codeSignSettings.codeSignStyle) {
329
+ buildSettings.CODE_SIGN_STYLE = codeSignSettings.codeSignStyle;
330
+ }
331
+ if (codeSignSettings.codeSignIdentity) {
332
+ buildSettings.CODE_SIGN_IDENTITY = codeSignSettings.codeSignIdentity;
333
+ }
334
+ if (codeSignSettings.otherCodeSigningFlags) {
335
+ buildSettings.OTHER_CODE_SIGN_FLAGS = codeSignSettings.otherCodeSigningFlags;
336
+ }
337
+ if (codeSignSettings.developmentTeam) {
338
+ buildSettings.DEVELOPMENT_TEAM = codeSignSettings.developmentTeam;
339
+ }
340
+ if (codeSignSettings.provisioningProfile) {
341
+ buildSettings.PROVISIONING_PROFILE_SPECIFIER = codeSignSettings.provisioningProfile;
342
+ }
343
+ }
344
+ }
345
+ // Add resources (xcassets) to the target
346
+ if (resourcesFiles.length) {
347
+ config.modResults.addBuildPhase(resourcesFiles, 'PBXResourcesBuildPhase', 'Resources', liveActivityTarget.uuid);
348
+ }
349
+ // Add source files to the target
350
+ if (sourceFiles.length) {
351
+ config.modResults.addBuildPhase(sourceFiles, 'PBXSourcesBuildPhase', 'Sources', liveActivityTarget.uuid);
352
+ }
353
+ // Add header files to the target
354
+ if (headerFiles.length) {
355
+ config.modResults.addBuildPhase(headerFiles, 'PBXHeadersBuildPhase', 'Headers', liveActivityTarget.uuid);
356
+ }
357
+ // Add required frameworks for Live Activity
358
+ config.modResults.addBuildPhase([
359
+ 'SwiftUI.framework',
360
+ 'WidgetKit.framework',
361
+ 'ActivityKit.framework'
362
+ ], 'PBXFrameworksBuildPhase', 'Frameworks', liveActivityTarget.uuid);
363
+ return config;
364
+ }
package/build/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const config_plugins_1 = require("@expo/config-plugins");
7
+ const withMoEngageAndroid_1 = __importDefault(require("./android/withMoEngageAndroid"));
8
+ const apple_1 = require("./apple");
9
+ const defaultProps = {
10
+ android: {
11
+ disableMoEngageDefaultBackupFile: false,
12
+ isExpoNotificationIntegration: false,
13
+ shouldIncludeMoEngageFirebaseMessagingService: false,
14
+ includeFirebaseMessagingDependencies: false,
15
+ configFilePath: 'assets/moengage/android_initilisation_config.xml',
16
+ },
17
+ apple: {
18
+ configFilePath: 'assets/moengage/MoEngage-Config.plist',
19
+ pushNotificationImpressionTrackingEnabled: true,
20
+ richPushNotificationEnabled: false,
21
+ pushTemplatesEnabled: false,
22
+ deviceTriggerEnabled: false,
23
+ liveActivityTargetPath: '',
24
+ },
25
+ };
26
+ /**
27
+ * Configure MoEngage SDK in your Expo app
28
+ */
29
+ const withMoEngage = (config, props) => {
30
+ // Apply default values or handle undefined props
31
+ const pluginProps = props ? Object.assign(Object.assign(Object.assign({}, defaultProps), props), { android: Object.assign(Object.assign({}, defaultProps.android), props.android), apple: Object.assign(Object.assign({}, defaultProps.apple), props.apple) }) : defaultProps;
32
+ config = (0, withMoEngageAndroid_1.default)(config, pluginProps);
33
+ config = (0, apple_1.withMoEngageIos)(config, pluginProps);
34
+ return config;
35
+ };
36
+ const pkg = require('../package.json');
37
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withMoEngage, pkg.name, pkg.version);
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "react-native-expo-moengage",
3
+ "platforms": ["ios", "tvos", "android"],
4
+ "apple": {
5
+ "appDelegateSubscribers": ["MoEngageAppDelegate"]
6
+ },
7
+ "modules": [
8
+ {
9
+ "name": "ReactNativeExpoMoEngage",
10
+ "apple": {
11
+ "subdirectory": "apple"
12
+ },
13
+ "android": {
14
+ "subdirectory": "android"
15
+ }
16
+ }
17
+ ]
18
+ }