onesignal-expo-plugin 2.1.0 → 2.2.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.
package/README.md CHANGED
@@ -88,6 +88,7 @@ You can pass props to the plugin config object to configure:
88
88
  | `smallIconAccentColor` | optional | The accent color to use for notification icons on Android. Must be a valid hex value, e.g: `"#FF0000"` |
89
89
  | `iosNSEFilePath` | optional | The local path to a custom Notification Service Extension (NSE), written in Objective-C. The NSE will typically start as a copy of the [default NSE](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/support/serviceExtensionFiles/NotificationService.m), then altered to support any custom logic required. e.g: `"./assets/NotificationService.m"`. |
90
90
  | `appGroupName` | optional | Used to configure a custom iOS [App Group](https://documentation.onesignal.com/docs/ios-sdk-setup#step-3-create-an-app-group) name. If not provided, defaults to `"group.{ios.bundleIdentifier}.onesignal"`. e.g: `"group.com.example.myapp.onesignal2"`. |
91
+ | `nseBundleIdentifier` | optional | Used to configure a custom bundle identifier suffix for the iOS Notification Service Extension. The full bundle identifier will be `"{ios.bundleIdentifier}.{nseBundleIdentifier}"`. If not provided, defaults to `"OneSignalNotificationServiceExtension"`. |
91
92
 
92
93
  ### OneSignal App ID
93
94
 
@@ -45,6 +45,7 @@ const config_plugins_1 = require("@expo/config-plugins");
45
45
  const fs = __importStar(require("fs"));
46
46
  const path = __importStar(require("path"));
47
47
  const iosConstants_1 = require("../support/iosConstants");
48
+ const helpers_1 = require("../support/helpers");
48
49
  const updatePodfile_1 = require("../support/updatePodfile");
49
50
  const NseUpdaterManager_1 = __importDefault(require("../support/NseUpdaterManager"));
50
51
  const OneSignalLog_1 = require("../support/OneSignalLog");
@@ -96,7 +97,7 @@ const withAppGroupPermissions = (config, props) => {
96
97
  newConfig.modResults[APP_GROUP_KEY] = [];
97
98
  }
98
99
  const modResultsArray = newConfig.modResults[APP_GROUP_KEY];
99
- const entitlement = (0, iosConstants_1.getAppGroupIdentifier)(newConfig?.ios?.bundleIdentifier || '', props?.appGroupName);
100
+ const entitlement = (0, helpers_1.getAppGroupIdentifier)(newConfig?.ios?.bundleIdentifier || '', props?.appGroupName);
100
101
  if (modResultsArray.indexOf(entitlement) !== -1) {
101
102
  return newConfig;
102
103
  }
@@ -118,18 +119,15 @@ const withCustomAppGroupsKey = (config, props) => {
118
119
  };
119
120
  const withEasManagedCredentials = (config, props) => {
120
121
  (0, assert_1.default)(config.ios?.bundleIdentifier, "Missing 'ios.bundleIdentifier' in app config.");
121
- config.extra = (0, getEasManagedCredentialsConfigExtra_1.default)(config, props?.appGroupName);
122
+ config.extra = (0, getEasManagedCredentialsConfigExtra_1.default)(config, props?.appGroupName, props?.nseBundleIdentifier);
122
123
  return config;
123
124
  };
124
125
  const withOneSignalPodfile = (config) => {
125
126
  return (0, config_plugins_1.withDangerousMod)(config, [
126
127
  'ios',
127
128
  async (config) => {
128
- // not awaiting in order to not block main thread
129
129
  const iosRoot = path.join(config.modRequest.projectRoot, 'ios');
130
- (0, updatePodfile_1.updatePodfile)(iosRoot).catch((err) => {
131
- OneSignalLog_1.OneSignalLog.error(err);
132
- });
130
+ await (0, updatePodfile_1.updatePodfile)(iosRoot);
133
131
  return config;
134
132
  },
135
133
  ]);
@@ -143,19 +141,19 @@ const withOneSignalNSE = (config, props) => {
143
141
  async (config) => {
144
142
  const iosPath = path.join(config.modRequest.projectRoot, 'ios');
145
143
  /* COPY OVER EXTENSION FILES */
146
- fs.mkdirSync(`${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`, { recursive: true });
147
- for (let i = 0; i < iosConstants_1.NSE_EXT_FILES.length; i++) {
148
- const extFile = iosConstants_1.NSE_EXT_FILES[i];
149
- const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${extFile}`;
150
- await FileManager_1.FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
144
+ fs.mkdirSync(`${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`, {
145
+ recursive: true,
146
+ });
147
+ for (const file of iosConstants_1.NSE_EXT_FILES) {
148
+ const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${file}`;
149
+ await FileManager_1.FileManager.copyFile(`${sourceDir}${file}`, targetFile);
151
150
  }
152
- // Copy NSE source file either from configuration-provided location, falling back to the default one.
153
151
  const sourcePath = props.iosNSEFilePath ?? `${sourceDir}${iosConstants_1.NSE_SOURCE_FILE}`;
154
152
  const targetFile = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}/${iosConstants_1.NSE_SOURCE_FILE}`;
155
153
  await FileManager_1.FileManager.copyFile(`${sourcePath}`, targetFile);
156
154
  /* MODIFY COPIED EXTENSION FILES */
157
155
  const nseUpdater = new NseUpdaterManager_1.default(iosPath);
158
- const appGroupId = (0, iosConstants_1.getAppGroupIdentifier)(config.ios?.bundleIdentifier ?? '', props.appGroupName);
156
+ const appGroupId = (0, helpers_1.getAppGroupIdentifier)(config.ios?.bundleIdentifier ?? '', props.appGroupName);
159
157
  await nseUpdater.updateNSEEntitlements(appGroupId);
160
158
  if (props.appGroupName) {
161
159
  await nseUpdater.updateNSEInfoPlistAppGroupKey(props.appGroupName);
@@ -169,6 +167,7 @@ const withOneSignalNSE = (config, props) => {
169
167
  const withOneSignalXcodeProject = (config, props) => {
170
168
  return (0, config_plugins_1.withXcodeProject)(config, (newConfig) => {
171
169
  const xcodeProject = newConfig.modResults;
170
+ const nseBundleId = `${config.ios?.bundleIdentifier}.${props.nseBundleIdentifier ?? iosConstants_1.NSE_TARGET_NAME}`;
172
171
  if (xcodeProject.pbxTargetByName(iosConstants_1.NSE_TARGET_NAME)) {
173
172
  OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} already exists in project. Skipping...`);
174
173
  return newConfig;
@@ -196,7 +195,7 @@ const withOneSignalXcodeProject = (config, props) => {
196
195
  projObjects['PBXTargetDependency'] || {};
197
196
  // Add the NSE target
198
197
  // This adds PBXTargetDependency and PBXContainerItemProxy for you
199
- const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME, 'app_extension', iosConstants_1.NSE_TARGET_NAME, `${config.ios?.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`);
198
+ const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME, 'app_extension', iosConstants_1.NSE_TARGET_NAME, nseBundleId);
200
199
  // Add build phases to the new target
201
200
  xcodeProject.addBuildPhase(['NotificationService.m'], 'PBXSourcesBuildPhase', 'Sources', nseTarget.uuid);
202
201
  xcodeProject.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', nseTarget.uuid);
@@ -2,11 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const FileManager_1 = require("./FileManager");
4
4
  const iosConstants_1 = require("./iosConstants");
5
- // project `ios/OneSignalNotificationServiceExtension` directory
6
- const entitlementsFileName = `OneSignalNotificationServiceExtension.entitlements`;
7
- const plistFileName = `OneSignalNotificationServiceExtension-Info.plist`;
5
+ const entitlementsFileName = `${iosConstants_1.NSE_TARGET_NAME}.entitlements`;
6
+ const plistFileName = `${iosConstants_1.NSE_TARGET_NAME}-Info.plist`;
8
7
  class NseUpdaterManager {
9
- nsePath = '';
8
+ nsePath;
10
9
  constructor(iosPath) {
11
10
  this.nsePath = `${iosPath}/${iosConstants_1.NSE_TARGET_NAME}`;
12
11
  }
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = getEasManagedCredentialsConfigExtra;
4
4
  const iosConstants_1 = require("../iosConstants");
5
- function getEasManagedCredentialsConfigExtra(config, appGroupName) {
5
+ const helpers_1 = require("../helpers");
6
+ function getEasManagedCredentialsConfigExtra(config, appGroupName, nseBundleIdentifier) {
7
+ const bundleId = `${config?.ios?.bundleIdentifier}.${nseBundleIdentifier ?? iosConstants_1.NSE_TARGET_NAME}`;
6
8
  return {
7
9
  ...config.extra,
8
10
  eas: {
@@ -17,12 +19,11 @@ function getEasManagedCredentialsConfigExtra(config, appGroupName) {
17
19
  ...(config.extra?.eas?.build?.experimental?.ios?.appExtensions ??
18
20
  []),
19
21
  {
20
- // keep in sync with native changes in NSE
21
22
  targetName: iosConstants_1.NSE_TARGET_NAME,
22
- bundleIdentifier: `${config?.ios?.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`,
23
+ bundleIdentifier: bundleId,
23
24
  entitlements: {
24
25
  'com.apple.security.application-groups': [
25
- (0, iosConstants_1.getAppGroupIdentifier)(config?.ios?.bundleIdentifier ?? '', appGroupName),
26
+ (0, helpers_1.getAppGroupIdentifier)(config?.ios?.bundleIdentifier ?? '', appGroupName),
26
27
  ],
27
28
  },
28
29
  },
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatePluginProps = validatePluginProps;
4
+ exports.getAppGroupIdentifier = getAppGroupIdentifier;
4
5
  const types_1 = require("../types/types");
5
6
  function validatePluginProps(props) {
6
7
  // check the type of each property
@@ -30,6 +31,10 @@ function validatePluginProps(props) {
30
31
  if (props.appGroupName && typeof props.appGroupName !== 'string') {
31
32
  throw new Error("OneSignal Expo Plugin: 'appGroupName' must be a string.");
32
33
  }
34
+ if (props.nseBundleIdentifier &&
35
+ typeof props.nseBundleIdentifier !== 'string') {
36
+ throw new Error("OneSignal Expo Plugin: 'nseBundleIdentifier' must be a string.");
37
+ }
33
38
  // check for extra properties
34
39
  const inputProps = Object.keys(props);
35
40
  for (const prop of inputProps) {
@@ -38,3 +43,6 @@ function validatePluginProps(props) {
38
43
  }
39
44
  }
40
45
  }
46
+ function getAppGroupIdentifier(bundleIdentifier, customAppGroupName) {
47
+ return customAppGroupName ?? `group.${bundleIdentifier}.onesignal`;
48
+ }
@@ -1,25 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NSE_EXT_FILES = exports.NSE_SOURCE_FILE = exports.NSE_TARGET_NAME = exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.DEFAULT_BUNDLE_VERSION = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.NSE_PODFILE_REGEX = exports.NSE_PODFILE_SNIPPET = exports.TARGETED_DEVICE_FAMILY = exports.IPHONEOS_DEPLOYMENT_TARGET = void 0;
4
- exports.getAppGroupIdentifier = getAppGroupIdentifier;
3
+ exports.NSE_EXT_FILES = exports.NSE_PODFILE_REGEX = exports.NSE_PODFILE_SNIPPET = exports.NSE_SOURCE_FILE = exports.NSE_TARGET_NAME = exports.DEFAULT_BUNDLE_SHORT_VERSION = exports.DEFAULT_BUNDLE_VERSION = exports.BUNDLE_VERSION_TEMPLATE_REGEX = exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = exports.TARGETED_DEVICE_FAMILY = exports.IPHONEOS_DEPLOYMENT_TARGET = void 0;
5
4
  exports.IPHONEOS_DEPLOYMENT_TARGET = '11.0';
6
5
  exports.TARGETED_DEVICE_FAMILY = `"1,2"`;
7
- exports.NSE_PODFILE_SNIPPET = `
8
- target 'OneSignalNotificationServiceExtension' do
9
- pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
10
- use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
11
- end`;
12
- exports.NSE_PODFILE_REGEX = /target 'OneSignalNotificationServiceExtension'/;
13
6
  exports.GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm;
14
7
  exports.BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm;
15
8
  exports.BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm;
16
9
  exports.DEFAULT_BUNDLE_VERSION = '1';
17
10
  exports.DEFAULT_BUNDLE_SHORT_VERSION = '1.0';
18
11
  exports.NSE_TARGET_NAME = 'OneSignalNotificationServiceExtension';
19
- function getAppGroupIdentifier(bundleIdentifier, customAppGroupName) {
20
- return customAppGroupName ?? `group.${bundleIdentifier}.onesignal`;
21
- }
22
12
  exports.NSE_SOURCE_FILE = 'NotificationService.m';
13
+ exports.NSE_PODFILE_SNIPPET = `
14
+ target '${exports.NSE_TARGET_NAME}' do
15
+ pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
16
+ use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
17
+ end`;
18
+ exports.NSE_PODFILE_REGEX = new RegExp(`target '${exports.NSE_TARGET_NAME}'`);
23
19
  exports.NSE_EXT_FILES = [
24
20
  'NotificationService.h',
25
21
  `${exports.NSE_TARGET_NAME}.entitlements`,
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.updatePodfile = updatePodfile;
7
- const fs_1 = __importDefault(require("fs"));
7
+ const promises_1 = __importDefault(require("fs/promises"));
8
8
  const iosConstants_1 = require("./iosConstants");
9
9
  const OneSignalLog_1 = require("./OneSignalLog");
10
10
  const FileManager_1 = require("./FileManager");
@@ -12,13 +12,9 @@ async function updatePodfile(iosPath) {
12
12
  const podfile = await FileManager_1.FileManager.readFile(`${iosPath}/Podfile`);
13
13
  const matches = podfile.match(iosConstants_1.NSE_PODFILE_REGEX);
14
14
  if (matches) {
15
- OneSignalLog_1.OneSignalLog.log('OneSignalNotificationServiceExtension target already added to Podfile. Skipping...');
16
- }
17
- else {
18
- fs_1.default.appendFile(`${iosPath}/Podfile`, iosConstants_1.NSE_PODFILE_SNIPPET, (err) => {
19
- if (err) {
20
- OneSignalLog_1.OneSignalLog.error('Error writing to Podfile');
21
- }
22
- });
15
+ OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} target already added to Podfile. Skipping...`);
16
+ return;
23
17
  }
18
+ await promises_1.default.appendFile(`${iosPath}/Podfile`, iosConstants_1.NSE_PODFILE_SNIPPET);
19
+ OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} target added to Podfile.`);
24
20
  }
@@ -10,6 +10,7 @@ exports.ONESIGNAL_PLUGIN_PROPS = [
10
10
  'iosNSEFilePath',
11
11
  'smallIconAccentColor',
12
12
  'appGroupName',
13
+ 'nseBundleIdentifier',
13
14
  ];
14
15
  var Mode;
15
16
  (function (Mode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onesignal-expo-plugin",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Some Changez",
5
5
  "main": "./app.plugin.js",
6
6
  "files": [
@@ -47,6 +47,9 @@
47
47
  "prettier": "^3.8.1",
48
48
  "typescript": "^5.9.3"
49
49
  },
50
+ "peerDependencies": {
51
+ "react-native-onesignal": ">=5.0.0"
52
+ },
50
53
  "dependencies": {
51
54
  "@expo/image-utils": "^0.8.8"
52
55
  }