onesignal-expo-plugin 1.0.0 → 1.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.
@@ -0,0 +1,50 @@
1
+ name: 🙋‍♂️ Ask a question
2
+ description: Tell us what's on your mind
3
+ title: "[question]: "
4
+ labels: ["triage"]
5
+ # assignees:
6
+ # - assign your sdk team e.g., onesignal/unity
7
+ body:
8
+ - type: markdown
9
+ attributes:
10
+ value: |
11
+ Having issues integrating this SDK?
12
+ - type: textarea
13
+ id: question
14
+ attributes:
15
+ label: How can we help?
16
+ description: Specific question regarding integrating this SDK.
17
+ placeholder: How do I...?
18
+ validations:
19
+ required: true
20
+ - type: textarea
21
+ id: expo-sdk-version
22
+ attributes:
23
+ label: OneSignal Expo SDK version
24
+ description: The version of the OneSignal Expo SDK you have a question for.
25
+ placeholder: 1.0.0
26
+ validations:
27
+ required: true
28
+ - type: dropdown
29
+ id: platform
30
+ attributes:
31
+ label: Platform
32
+ description: Which platform are you having an issue with?
33
+ multiple: true
34
+ options:
35
+ - iOS
36
+ - Android
37
+ - type: textarea
38
+ id: logs
39
+ attributes:
40
+ label: Relevant log output
41
+ description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
42
+ render: Shell
43
+ - type: checkboxes
44
+ id: terms
45
+ attributes:
46
+ label: Code of Conduct
47
+ description: By submitting this issue, you agree to follow our [Code of Conduct](#insert-project-code-of-conduct-here)
48
+ options:
49
+ - label: I agree to follow this project's Code of Conduct
50
+ required: true
@@ -0,0 +1,71 @@
1
+ name: 🪳 Bug Report
2
+ description: File a bug report
3
+ title: "[Bug]: "
4
+ labels: ["bug", "triage"]
5
+ # assignees:
6
+ # - assign your sdk team e.g., onesignal/unity
7
+ body:
8
+ - type: markdown
9
+ attributes:
10
+ value: |
11
+ Thanks for taking the time to fill out this bug report!
12
+ - type: textarea
13
+ id: what-happened
14
+ attributes:
15
+ label: What happened?
16
+ description: Provide a thorough description of whats going on.
17
+ placeholder: The latest version of the SDK causes my screen to go blank when I tap on the screen three times.
18
+ validations:
19
+ required: true
20
+ - type: textarea
21
+ id: reproduction-steps
22
+ attributes:
23
+ label: Steps to reproduce?
24
+ description: Provide as much detail as posible to reproduce the issue.
25
+ placeholder: |
26
+ 1. Install vX.Y.Z of dependency
27
+ 2. Launch the app on iOS device
28
+ 3. Tap the screen three times
29
+ 4. Note that the app crashes
30
+ render: Markdown
31
+ validations:
32
+ required: true
33
+ - type: textarea
34
+ id: what-are-expectations
35
+ attributes:
36
+ label: What did you expect to happen?
37
+ description: Also tell us, what did you expect to happen?
38
+ placeholder: I expected the app to continue running no matter how many times I tap the screen.
39
+ validations:
40
+ required: true
41
+ - type: textarea
42
+ id: expo-sdk-version
43
+ attributes:
44
+ label: OneSignal Expo SDK version
45
+ description: The version of the OneSignal Expo SDK used in your app.
46
+ placeholder: 1.0.0
47
+ validations:
48
+ required: true
49
+ - type: dropdown
50
+ id: platform
51
+ attributes:
52
+ label: Platform
53
+ description: Which platform are you having an issue with?
54
+ multiple: true
55
+ options:
56
+ - iOS
57
+ - Android
58
+ - type: textarea
59
+ id: logs
60
+ attributes:
61
+ label: Relevant log output
62
+ description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
63
+ render: Shell
64
+ - type: checkboxes
65
+ id: terms
66
+ attributes:
67
+ label: Code of Conduct
68
+ description: By submitting this issue, you agree to follow our [Code of Conduct](#insert-project-code-of-conduct-here)
69
+ options:
70
+ - label: I agree to follow this project's Code of Conduct
71
+ required: true
@@ -0,0 +1,27 @@
1
+ name: 📣 General feedback
2
+ description: Tell us what's on your mind
3
+ title: "[feedback]: "
4
+ labels: ["triage"]
5
+ # assignees:
6
+ # - assign your sdk team e.g., onesignal/unity
7
+ body:
8
+ - type: markdown
9
+ attributes:
10
+ value: |
11
+ Thanks for sharing your valuable feedback!
12
+ - type: textarea
13
+ id: feedback
14
+ attributes:
15
+ label: What's on your mind?
16
+ description: Feedback regarding this SDK.
17
+ placeholder: Share your feedback...
18
+ validations:
19
+ required: true
20
+ - type: checkboxes
21
+ id: terms
22
+ attributes:
23
+ label: Code of Conduct
24
+ description: By submitting this issue, you agree to follow our [Code of Conduct](#insert-project-code-of-conduct-here)
25
+ options:
26
+ - label: I agree to follow this project's Code of Conduct
27
+ required: true
package/CHANGELOG.md CHANGED
@@ -1,6 +1,35 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## April 2022
5
+ ### `1.0.1` - 04/11/22
6
+
7
+ #### Changes
8
+ - Add more info regarding the `expo prebuild` command to README.
9
+ #### Fixes
10
+ - Upstream EAS workaround for "Missing Push Capability on iOS" issue. Adds `aps-environment` entitlement to NSE template. Although it is **not** required in normal builds, there is an upstream limitation from EAS that is resolved by including the push entitlement in both target entitlement files. As of 4/8/22, EAS builds will randomly pick an entitlement file if there are multiple in a project without differentiating among targets. This is resulting in flaky builds where half the time they work and half the time they don't. This can be seen as a temporary fix. Note it carries no side-effects / repercussions (i.e: the entitlement is superfluous but not critical to remove in the future).
11
+
12
+ ## March 2022
13
+ ### `1.0.0` - 03/28/22
14
+
15
+ #### Fixes
16
+ - Upgrade dependencies (via dependabot)
17
+ #### Changes
18
+ - Add credentials guide and update README
19
+ - Advance to General Availability
20
+
21
+ ## February 2022
22
+ ### `1.0.0-beta11` - 02/18/2022
23
+ #### Added
24
+ - Linting
25
+ - Instead of creating a "WriterManager", we repurpose the ReaderManager class by renaming it to FileManager and adding a synchronized write helper function (synchronous in the sense that it block further execution until complete).
26
+ - iOS constants file
27
+
28
+ #### Fixes
29
+ - Import cleanups
30
+ - Linting errors
31
+ - Write safety issu. NSE updater helper functions were previously writing to the entitlements & plist files asynchronously. We should await on each to ensure we don't have multiple writes to the same file at once (which is unsafe).
32
+
4
33
  ## January 2022
5
34
 
6
35
  ### `1.0.0-beta10` - 01/24/2022
@@ -5,20 +5,55 @@ To distribute your iOS application, you must set up all the credentials required
5
5
  * Provisioning profiles
6
6
  * Push notification certificate
7
7
 
8
- If you are using EAS, you may be letting Expo handle all your credentials. This is fine for your distribution and provisioning credentials. However, the push notification certificate *must* be handled separately since you are using OneSignal.
8
+ If you are using EAS, you may be letting Expo handle all your credentials. This is fine for your distribution and provisioning credentials. However, the push notification certificate *must* be set up separately since you are using OneSignal.
9
9
 
10
- As of 3/22/2022, OneSignal does not support p8 files and EAS does not support p12 files which results in a particlar issue when cloud building through EAS while using the Expo managed credentials service. Since the EAS CLI only prompts for p8 files at the time of writing, the only way to complete the cloud build is to input "n" (no) when prompted for setting up push notifications through the CLI. However, this leads to the identifier not having the push capability required to set up push successfully. Until EAS adds more granular control over credentials or OneSignal adds p8 support or Expo adds p12 support, developers will have no option except to use local credentials only.
10
+ ### Push Notification Certificate
11
+ To set up OneSignal on iOS, you will need a [push notification certificate](https://documentation.onesignal.com/docs/generate-an-ios-push-certificate). The push certificate is used to send notifications to devices and has nothing to do with the build process. After you have uploaded the certificate to OneSignal, it should just work.
11
12
 
12
- If you have developed on iOS before, you may be used to XCode helping with syncing things like capabilities across app targets. In Expo/EAS, we are likely not using XCode at all. Thus, we need to make sure that we set up everything manually via the Apple Developers portal.
13
+ ### Capabilities
14
+ As of eas-cli `v0.52.0`, the previous capabilities issues should now be resolved. See the [release notes](https://github.com/expo/eas-cli/releases/tag/v0.52.0) for details.
13
15
 
14
- ### TLDR
15
- To set up push notifications with OneSignal + Expo, you *must* manage all credentials yourself and use local credentials when cloud building through EAS.
16
+ You can still view the old instructions by clicking below.
17
+
18
+ <details>
19
+ <summary>Click to expand</summary>
16
20
 
17
21
  ---
22
+ To receive notifications, you must add the `aps-environment` capability (Push Notifications) to your app at build time. The OneSignal plugin tries to facilitate this as much as possible but there could be complications if you added other capabilities/entitlements or another config plugin did. This is because EAS doesn't currently respect entitlement files on a per-target basis. If there are more than one entitlements files, it simply picks one and applies it to both targets.
23
+
24
+ Due to this, there are two setup paths:
25
+ 1. A **simple setup** is one in which the only [capability](https://docs.expo.dev/build-reference/ios-capabilities/) on your main target is "Push Notifications."
26
+ 2. A more **complex setup** is one in which you have other capabilities.
27
+
28
+ This also affects how you should set up your credentials. Use the following table to know whether to proceed with local or managed credentials:
29
+ | Push Notification capability only | |
30
+ |-----------------------------------|-----------------------------------------------------------------------|
31
+ | Local credentials | Works but unnecessary to go through extra effort to use local signing |
32
+ | Managed credentials | Works (simple setup) |
33
+
34
+ | Multiple capabilities | |
35
+ |-----------------------|----------------------------------|
36
+ | Local credentials | Works but requires complex setup |
37
+ | Managed credentials | Works unreliably |
38
+
39
+ If you are unsure, run `expo prebuild` and look at the native entitlements file of your main target (in `ios` directory). Other config plugins may be adding capabilities here. Or check the full [capabilities](https://docs.expo.dev/build-reference/ios-capabilities/#supported-capabilities) list supported by Expo.
40
+
41
+
42
+ #### Simple setup explanation
43
+ Since there is only one capability (Push Notifications) required by your app, everything should just work. OneSignal will automatically add the capability to your app along with the necessary App Groups and EAS should sync them with your Apple Developer account. You can choose to use managed signing on EAS without a problem. This works because OneSignal will add the capability to both targets' entitlements files.
44
+
45
+ #### Complex setup explanation
46
+ Having additional capabilities on your app will result in a more complex setup, including having to use local credentials. The following is an explanation of why. It is not imperative to understand but we have included it for context.
47
+
48
+ The OneSignal plugin will create an additional target: `OneSignalNotificationServiceExtension`. This target is the iOS service extension that adds support for Confirmed Deliveries, badges, media attachments, action buttons, and influenced opens (Firebase Analytics). Learn more [here](https://documentation.onesignal.com/docs/service-extensions). The plugin will automatically add app groups to both targets' entitlements files which are required if you want to make use of these features. They allow your app to execute code when a notification is received, even if your app is not active.
18
49
 
19
- # Setup
50
+ Each target has an entitlement file. If there are multiple entitlements files per project, EAS will randomly pick one and apply it to both targets. To mitigate this, we have added the push capability entilement to both files (even though it's really only necessary in the main target). This can still pose a problem if it picks the NSE's entitlements file since it *could* break any other capabilities in your project, given that file will not have capabilities added to your main target by yourself or other plugins.
20
51
 
21
- ## 1. Credentials setup
52
+ The following section details how to mitigate these issues and not break your other capabilities.
53
+
54
+ ## Complex Setup
55
+
56
+ ### 1. Credentials setup
22
57
  To build successfully, you will need to create and use local credentials (one for production and development). Add `"credentialsSource": "local"` to your `eas.json` file.
23
58
 
24
59
  **Example:**
@@ -39,23 +74,20 @@ To build successfully, you will need to create and use local credentials (one fo
39
74
  "distribution": "internal",
40
75
  "credentialsSource": "local"
41
76
  }
42
- },
43
- "cli": {
44
- "version": ">= 0.40.0"
45
77
  }
46
78
  }
47
79
  ```
48
80
 
49
- ## 2. Identifiers
81
+ ### 2. Identifiers
50
82
  In your [Apple developer console](https://developer.apple.com) create two identifiers with the following format:
51
- - `com.example.app` <-- you likely already have this one
52
- - `com.example.app.OneSignalNotificationServiceExtension`
83
+ - `<com.example.app>` <-- you likely already have this one
84
+ - `<com.example.app>.OneSignalNotificationServiceExtension`
53
85
 
54
- ### When modifying your existing main app identifier:
86
+ #### When modifying your existing main app identifier:
55
87
  - add the App Groups capability like so: `group.<identifier>.onesignal`
56
88
  - keep / add the "Push Notifications" capability
57
89
 
58
- ### When creating a new identifier for `OneSignalNotificationServiceExtension`:
90
+ #### When creating a new identifier for `OneSignalNotificationServiceExtension`:
59
91
  - select AppId from the list of identifier types
60
92
  - select App when choosing between App and App Clip
61
93
  - add the App Groups capability like so: `group.<identifier>.onesignal`
@@ -64,10 +96,10 @@ In your [Apple developer console](https://developer.apple.com) create two identi
64
96
  #### Note on App Groups at Build Time:
65
97
  Make sure to build with both identifiers containing the AppGroup simultaneously. To troubleshoot, remove them both and then rebuild with both identifiers' AppGroup capabilities enabled.
66
98
 
67
- ## 3. Provisioning
99
+ ### 3. Provisioning
68
100
  Create AdHoc (local development) and AppStore (production) provisioning profiles with both identifiers (four provisioning profiles total). Both provisioning profiles should use the same distribution certificate that is used by your app. Download the profiles.
69
101
 
70
- ## 4. Add the profiles to your `credentials.json` file:
102
+ ### 4. Add the profiles to your `credentials.json` file:
71
103
  Use the same distribution certificate for the `OneSignalNotificationServiceExtension` as is used for your app (no need to create a new cert).
72
104
 
73
105
  We recommend creating a `certs` directory in your project with subdirectories for each build type (e.g: `certs/adhoc` & `certs/appstore`). Doing so, you can more easily switch which provisioning profiles get used at build time.
@@ -103,16 +135,20 @@ We recommend creating a `certs` directory in your project with subdirectories fo
103
135
 
104
136
  **Note:** your push certificate (p12) file should not appear anywhere in the `credentials.json` file.
105
137
 
106
- ---
138
+ ## Build (complex setup continued)
139
+
140
+ **IMPORTANT**: run the `eas build` command with `EXPO_NO_CAPABILITY_SYNC` if you want to prevent EAS from syncing capabilities (e.g: overwriting the steps you took in the complex setup).
107
141
 
108
- # Build
109
142
  ### Release
110
143
  If you are ready for a production build, you should use the AppStore provisioning profiles you created. Make sure your `credentials.json` file is using the correct profiles.
111
144
 
112
145
  ### Development
113
146
  The development build will use the AdHoc provisioning profiles you created. Make sure your `credentials.json` file is using the correct profiles.
114
147
 
115
- #### Expo development client
148
+ ---
149
+ </details>
150
+
151
+ ### Expo development client
116
152
  If you haven't already, add the expo development client to your project:
117
153
 
118
154
  ```sh
@@ -121,8 +157,6 @@ expo install expo-dev-client
121
157
 
122
158
  Make sure `"developmentClient": true,` is set in your `eas.json` development build profile.
123
159
 
124
- ## All Builds
125
-
126
160
  ### Run the EAS build command
127
161
  ```sh
128
162
  eas build --profile <build profile> --platform ios
@@ -132,7 +166,5 @@ where `<build profile>` refers to the build profile in your `eas.json` file (e.g
132
166
  ### Build success
133
167
  At this point, your build should succeed. You can check its progress by opening the build link in the terminal.
134
168
 
135
- ---
136
-
137
- # How to run on your device
169
+ ## How to run on your device
138
170
  See our [EAS guide](EAS.md) for instructions.
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  <h1 align="center">Welcome to onesignal-expo-plugin 👋</h1>
2
2
  <p>
3
- <img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
3
+ <a href="https://www.npmjs.com/package/onesignal-expo-plugin" target="_blank">
4
+ <img alt="Version" src="https://img.shields.io/npm/v/onesignal-expo-plugin.svg">
5
+ </a>
4
6
  <a href="https://github.com/OneSignal/onesignal-expo-plugin#readme" target="_blank">
5
7
  <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
6
8
  </a>
@@ -41,7 +43,7 @@ yarn add react-native-onesignal
41
43
 
42
44
  ## Configuration in app.json / app.config.js
43
45
  ### Plugin
44
- Add the plugin to the [plugin array](https://docs.expo.dev/versions/latest/config/app/):
46
+ Add the plugin to the **front** of the [plugin array](https://docs.expo.dev/versions/latest/config/app/). It should be added automatically if you ran `expo install`. Just make sure it is the first plugin in the array and to configure any desired plugin props:
45
47
 
46
48
  **app.json**
47
49
  ```json
@@ -125,11 +127,15 @@ See our [EAS documentation](EAS.md) for help with EAS.
125
127
  ### iOS Credentials: OneSignal + EAS
126
128
  To distribute your iOS application via EAS, you will need to ensure your credentials are set up correctly. See our [credentials setup guide for instructions](IOS_CREDENTIALS_EAS.md).
127
129
 
128
- ## Prebuild
129
- Since we are using custom native code (via the OneSignal plugin), we need to generate the native runtime code for the project. By prebuilding, we automatically link and configure the native modules that have implemented CocoaPods, autolinking, and other config plugins. You can think of prebuild like a native code bundler.
130
+ ## Prebuild (optional)
131
+ Prebuilding in Expo will result in the generation of the native runtime code for the project (and `ios` and `android` directories being built). By prebuilding, we automatically link and configure the native modules that have implemented CocoaPods, autolinking, and other config plugins. You can think of prebuild like a native code bundler.
130
132
 
131
133
  When you run `expo prebuild` we enter into a custom managed workflow which provides most of the benefits of bare workflows and managed workflows at the same time.
132
134
 
135
+ #### Why should I prebuild?
136
+ It may make sense to prebuild locally to inspect config plugin changes and help in debugging issues.
137
+
138
+ #### Run
133
139
  ```sh
134
140
  expo prebuild
135
141
  ```
@@ -139,6 +145,8 @@ expo prebuild
139
145
  expo prebuild --clean
140
146
  ```
141
147
 
148
+ **EAS Note:** if you choose to stay in a fully managed workflow by not prebuilding, EAS will still run `expo prebuild` at build time. You can also prebuild locally but remain in a fully managed workflow by adding the `android` and `ios` directories to your .gitignore.
149
+
142
150
  ## Run
143
151
  The following commands will prebuild *and* run your application. Note that for iOS, push notifications will **not** work in the Simulator.
144
152
  ```sh
@@ -168,5 +176,5 @@ Give a ⭐️ if this project helped you!
168
176
 
169
177
  ## 📝 License
170
178
 
171
- Copyright © 2021 [OneSignal](https://github.com/OneSignal).<br />
179
+ Copyright © 2022 [OneSignal](https://github.com/OneSignal).<br />
172
180
  This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/LICENSE) licensed.
@@ -5,25 +5,9 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.withOneSignalAndroid = void 0;
8
- const config_plugins_1 = require("@expo/config-plugins");
9
- const androidConstants_1 = require("../support/androidConstants");
10
8
  const OneSignalLog_1 = require("../support/OneSignalLog");
11
- const withGradleBuildConfig = (config) => {
12
- return (0, config_plugins_1.withAppBuildGradle)(config, (newConfig) => {
13
- let { contents } = newConfig.modResults;
14
- // make sure we haven't previously added dependencies
15
- if (!contents.includes(androidConstants_1.ONESIGNAL_GRADLE)) {
16
- contents = `${androidConstants_1.ONESIGNAL_GRADLE}\n${contents}`;
17
- }
18
- else {
19
- OneSignalLog_1.OneSignalLog.log("OneSignal dependencies already added to build.gradle. Skipping...");
20
- }
21
- newConfig.modResults.contents = contents;
22
- return newConfig;
23
- });
24
- };
25
9
  const withOneSignalAndroid = (config, props) => {
26
- withGradleBuildConfig(config, props);
10
+ OneSignalLog_1.OneSignalLog.log("No specific actions required for OneSignal on Android...");
27
11
  return config;
28
12
  };
29
13
  exports.withOneSignalAndroid = withOneSignalAndroid;
@@ -35,8 +35,10 @@ const updatePodfile_1 = require("../support/updatePodfile");
35
35
  const NseUpdaterManager_1 = __importDefault(require("../support/NseUpdaterManager"));
36
36
  const OneSignalLog_1 = require("../support/OneSignalLog");
37
37
  const FileManager_1 = require("../support/FileManager");
38
+ const assert_1 = __importDefault(require("assert"));
39
+ const getEasManagedCredentialsConfigExtra_1 = __importDefault(require("../support/eas/getEasManagedCredentialsConfigExtra"));
38
40
  /**
39
- * Add 'app-environment' record with current environment to '<project-name>.entitlements' file
41
+ * Add 'aps-environment' record with current environment to '<project-name>.entitlements' file
40
42
  * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
41
43
  */
42
44
  const withAppEnvironment = (config, onesignalProps) => {
@@ -98,17 +100,31 @@ const withOneSignalNSE = (config, onesignalProps) => {
98
100
  devTeam: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.devTeam,
99
101
  bundleVersion: (_b = props.ios) === null || _b === void 0 ? void 0 : _b.buildNumber,
100
102
  bundleShortVersion: props === null || props === void 0 ? void 0 : props.version,
103
+ mode: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.mode,
101
104
  iPhoneDeploymentTarget: onesignalProps === null || onesignalProps === void 0 ? void 0 : onesignalProps.iPhoneDeploymentTarget
102
105
  };
103
- xcodeProjectAddNse(props.modRequest.projectName || "", options, "node_modules/onesignal-expo-plugin/build/support/serviceExtensionFiles/");
106
+ // support for monorepos where node_modules can be up to 5 parents
107
+ // above the project directory.
108
+ let dir = "node_modules";
109
+ for (let x = 0; x < 5 && !FileManager_1.FileManager.dirExists(dir); x++) {
110
+ dir = "../" + dir;
111
+ }
112
+ xcodeProjectAddNse(props.modRequest.projectName || "", options, dir + "/onesignal-expo-plugin/build/support/serviceExtensionFiles/");
104
113
  return props;
105
114
  });
106
115
  };
116
+ const withEasManagedCredentials = (config) => {
117
+ var _a;
118
+ (0, assert_1.default)((_a = config.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier, "Missing 'ios.bundleIdentifier' in app config.");
119
+ config.extra = (0, getEasManagedCredentialsConfigExtra_1.default)(config);
120
+ return config;
121
+ };
107
122
  const withOneSignalIos = (config, props) => {
108
123
  withAppEnvironment(config, props);
109
124
  withRemoteNotificationsPermissions(config, props);
110
125
  withAppGroupPermissions(config, props);
111
126
  withOneSignalNSE(config, props);
127
+ withEasManagedCredentials(config, props);
112
128
  return config;
113
129
  };
114
130
  exports.withOneSignalIos = withOneSignalIos;
@@ -54,5 +54,8 @@ class FileManager {
54
54
  const fileContents = await FileManager.readFile(path1);
55
55
  await FileManager.writeFile(path2, fileContents);
56
56
  }
57
+ static dirExists(path) {
58
+ return fs.existsSync(path);
59
+ }
57
60
  }
58
61
  exports.FileManager = FileManager;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const iosConstants_1 = require("../iosConstants");
4
+ function getEasManagedCredentialsConfigExtra(config) {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6
+ return {
7
+ ...config.extra,
8
+ eas: {
9
+ ...(_a = config.extra) === null || _a === void 0 ? void 0 : _a.eas,
10
+ build: {
11
+ ...(_c = (_b = config.extra) === null || _b === void 0 ? void 0 : _b.eas) === null || _c === void 0 ? void 0 : _c.build,
12
+ experimental: {
13
+ ...(_f = (_e = (_d = config.extra) === null || _d === void 0 ? void 0 : _d.eas) === null || _e === void 0 ? void 0 : _e.build) === null || _f === void 0 ? void 0 : _f.experimental,
14
+ ios: {
15
+ ...(_k = (_j = (_h = (_g = config.extra) === null || _g === void 0 ? void 0 : _g.eas) === null || _h === void 0 ? void 0 : _h.build) === null || _j === void 0 ? void 0 : _j.experimental) === null || _k === void 0 ? void 0 : _k.ios,
16
+ appExtensions: [
17
+ ...((_r = (_q = (_p = (_o = (_m = (_l = config.extra) === null || _l === void 0 ? void 0 : _l.eas) === null || _m === void 0 ? void 0 : _m.build) === null || _o === void 0 ? void 0 : _o.experimental) === null || _p === void 0 ? void 0 : _p.ios) === null || _q === void 0 ? void 0 : _q.appExtensions) !== null && _r !== void 0 ? _r : []),
18
+ {
19
+ // keep in sync with native changes in NSE
20
+ targetName: iosConstants_1.NSE_TARGET_NAME,
21
+ bundleIdentifier: `${(_s = config === null || config === void 0 ? void 0 : config.ios) === null || _s === void 0 ? void 0 : _s.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`,
22
+ entitlements: {
23
+ 'com.apple.security.application-groups': [
24
+ `group.${(_t = config === null || config === void 0 ? void 0 : config.ios) === null || _t === void 0 ? void 0 : _t.bundleIdentifier}.onesignal`
25
+ ]
26
+ },
27
+ }
28
+ ]
29
+ }
30
+ }
31
+ }
32
+ }
33
+ };
34
+ }
35
+ exports.default = getEasManagedCredentialsConfigExtra;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const withOneSignalIos_1 = require("./onesignal/withOneSignalIos");
4
+ const types_1 = require("./types/types");
4
5
  // Quick testing on any Xcode project
5
6
  // 1. Update values for your project
6
7
  // 2. Run `yarn build` from here
@@ -13,6 +14,7 @@ const withOneSignalIos_1 = require("./onesignal/withOneSignalIos");
13
14
  // even if your .xcodeproj is correct.
14
15
  const options = {
15
16
  iosPath: '.',
17
+ mode: types_1.Mode.Dev,
16
18
  bundleIdentifier: "com.onesignal.XcodeTestProj",
17
19
  devTeam: "99SW8E36CT",
18
20
  iPhoneDeploymentTarget: '12.0'
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Mode = void 0;
4
+ var Mode;
5
+ (function (Mode) {
6
+ Mode["Dev"] = "development";
7
+ Mode["Prod"] = "production";
8
+ })(Mode = exports.Mode || (exports.Mode = {}));
@@ -4,18 +4,10 @@
4
4
  */
5
5
 
6
6
  import { ConfigPlugin } from '@expo/config-plugins';
7
+ import { OneSignalPluginProps } from '../types/types';
7
8
  import { withOneSignalAndroid } from './withOneSignalAndroid';
8
9
  import { withOneSignalIos } from './withOneSignalIos';
9
10
 
10
- export type OneSignalPluginProps = {
11
- /**
12
- * (iOS only) Environment name and bundle identifier
13
- */
14
- mode: string;
15
- devTeam: string;
16
- iPhoneDeploymentTarget: string;
17
- };
18
-
19
11
  const withOneSignal: ConfigPlugin<OneSignalPluginProps> = (config, props) => {
20
12
  config = withOneSignalIos(config, props);
21
13
  config = withOneSignalAndroid(config, props);
@@ -3,32 +3,15 @@
3
3
  * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
4
4
  */
5
5
 
6
- import { ConfigPlugin, withAppBuildGradle } from '@expo/config-plugins';
7
- import { ONESIGNAL_GRADLE } from '../support/androidConstants';
6
+ import { ConfigPlugin } from '@expo/config-plugins';
8
7
  import { OneSignalLog } from '../support/OneSignalLog';
9
- import { OneSignalPluginProps } from './withOneSignal';
10
-
11
- const withGradleBuildConfig: ConfigPlugin<OneSignalPluginProps> = (config) => {
12
- return withAppBuildGradle(config, (newConfig) => {
13
- let { contents } = newConfig.modResults;
14
-
15
- // make sure we haven't previously added dependencies
16
- if (!contents.includes(ONESIGNAL_GRADLE)) {
17
- contents = `${ONESIGNAL_GRADLE}\n${contents}`;
18
- } else {
19
- OneSignalLog.log("OneSignal dependencies already added to build.gradle. Skipping...");
20
- }
21
-
22
- newConfig.modResults.contents = contents;
23
- return newConfig;
24
- });
25
- };
8
+ import { OneSignalPluginProps } from '../types/types';
26
9
 
27
10
  export const withOneSignalAndroid: ConfigPlugin<OneSignalPluginProps> = (
28
11
  config,
29
12
  props,
30
13
  ) => {
31
- withGradleBuildConfig(config, props);
14
+ OneSignalLog.log("No specific actions required for OneSignal on Android...");
32
15
 
33
16
  return config;
34
17
  };
@@ -9,7 +9,6 @@ import {
9
9
  withInfoPlist,
10
10
  withXcodeProject,
11
11
  } from "@expo/config-plugins";
12
- import { OneSignalPluginProps } from "./withOneSignal";
13
12
  import * as fs from 'fs';
14
13
  import xcode from 'xcode';
15
14
  import {
@@ -23,19 +22,13 @@ import { updatePodfile } from "../support/updatePodfile";
23
22
  import NseUpdaterManager from "../support/NseUpdaterManager";
24
23
  import { OneSignalLog } from "../support/OneSignalLog";
25
24
  import { FileManager } from "../support/FileManager";
26
-
27
- /* I N T E R F A C E S */
28
- interface PluginOptions {
29
- iosPath: string,
30
- devTeam?: string,
31
- bundleVersion?: string,
32
- bundleShortVersion?: string,
33
- bundleIdentifier?: string,
34
- iPhoneDeploymentTarget?: string
35
- }
25
+ import { OneSignalPluginProps, PluginOptions } from "../types/types";
26
+ import assert from 'assert';
27
+ import getEasManagedCredentialsConfigExtra from "../support/eas/getEasManagedCredentialsConfigExtra";
28
+ import { ExpoConfig } from '@expo/config-types';
36
29
 
37
30
  /**
38
- * Add 'app-environment' record with current environment to '<project-name>.entitlements' file
31
+ * Add 'aps-environment' record with current environment to '<project-name>.entitlements' file
39
32
  * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
40
33
  */
41
34
  const withAppEnvironment: ConfigPlugin<OneSignalPluginProps> = (
@@ -108,19 +101,33 @@ const withOneSignalNSE: ConfigPlugin<OneSignalPluginProps> = (config, onesignalP
108
101
  devTeam: onesignalProps?.devTeam,
109
102
  bundleVersion: props.ios?.buildNumber,
110
103
  bundleShortVersion: props?.version,
104
+ mode: onesignalProps?.mode,
111
105
  iPhoneDeploymentTarget: onesignalProps?.iPhoneDeploymentTarget
112
106
  };
113
107
 
108
+ // support for monorepos where node_modules can be up to 5 parents
109
+ // above the project directory.
110
+ let dir = "node_modules"
111
+ for(let x=0; x < 5 && !FileManager.dirExists(dir); x++) {
112
+ dir = "../" + dir
113
+ }
114
+
114
115
  xcodeProjectAddNse(
115
116
  props.modRequest.projectName || "",
116
117
  options,
117
- "node_modules/onesignal-expo-plugin/build/support/serviceExtensionFiles/"
118
+ dir + "/onesignal-expo-plugin/build/support/serviceExtensionFiles/"
118
119
  );
119
120
 
120
121
  return props;
121
122
  });
122
123
  }
123
124
 
125
+ const withEasManagedCredentials: ConfigPlugin<OneSignalPluginProps> = (config) => {
126
+ assert(config.ios?.bundleIdentifier, "Missing 'ios.bundleIdentifier' in app config.")
127
+ config.extra = getEasManagedCredentialsConfigExtra(config as ExpoConfig);
128
+ return config;
129
+ }
130
+
124
131
  export const withOneSignalIos: ConfigPlugin<OneSignalPluginProps> = (
125
132
  config,
126
133
  props
@@ -129,6 +136,7 @@ export const withOneSignalIos: ConfigPlugin<OneSignalPluginProps> = (
129
136
  withRemoteNotificationsPermissions(config, props);
130
137
  withAppGroupPermissions(config, props);
131
138
  withOneSignalNSE(config, props);
139
+ withEasManagedCredentials(config, props);
132
140
  return config;
133
141
  };
134
142
 
@@ -162,7 +170,7 @@ export function xcodeProjectAddNse(
162
170
  /* COPY OVER EXTENSION FILES */
163
171
  fs.mkdirSync(`${iosPath}/${NSE_TARGET_NAME}`, { recursive: true });
164
172
 
165
- for(let i = 0; i < extFiles.length; i++) {
173
+ for (let i = 0; i < extFiles.length; i++) {
166
174
  const extFile = extFiles[i];
167
175
  const targetFile = `${iosPath}/${NSE_TARGET_NAME}/${extFile}`;
168
176
  await FileManager.copyFile(`${sourceDir}${extFile}`, targetFile);
@@ -180,7 +188,7 @@ export function xcodeProjectAddNse(
180
188
  // Add the new PBXGroup to the top level group. This makes the
181
189
  // files / folder appear in the file explorer in Xcode.
182
190
  const groups = xcodeProject.hash.project.objects["PBXGroup"];
183
- Object.keys(groups).forEach(function (key) {
191
+ Object.keys(groups).forEach(function(key) {
184
192
  if (groups[key].name === undefined) {
185
193
  xcodeProject.addToPbxGroup(extGroup.uuid, key);
186
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onesignal-expo-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.",
5
5
  "main": "./app.plugin.js",
6
6
  "scripts": {
@@ -24,7 +24,8 @@
24
24
  "contributors": [
25
25
  "Karen Grigoryan",
26
26
  "Rodrigo Gomez-Palacio",
27
- "Charlie Cruzan"
27
+ "Charlie Cruzan",
28
+ "Wojciech Kozyra"
28
29
  ],
29
30
  "license": "MIT",
30
31
  "bugs": {
@@ -35,4 +35,8 @@ export class FileManager {
35
35
  const fileContents = await FileManager.readFile(path1);
36
36
  await FileManager.writeFile(path2, fileContents);
37
37
  }
38
+
39
+ static dirExists(path: string): boolean {
40
+ return fs.existsSync(path)
41
+ }
38
42
  }
@@ -19,6 +19,7 @@ export default class NseUpdaterManager {
19
19
  async updateNSEEntitlements(groupIdentifier: string): Promise<void> {
20
20
  const entitlementsFilePath = `${this.nsePath}/${entitlementsFileName}`;
21
21
  let entitlementsFile = await FileManager.readFile(entitlementsFilePath);
22
+
22
23
  entitlementsFile = entitlementsFile.replace(GROUP_IDENTIFIER_TEMPLATE_REGEX, groupIdentifier);
23
24
  await FileManager.writeFile(entitlementsFilePath, entitlementsFile);
24
25
  }
@@ -0,0 +1,33 @@
1
+ import { NSE_TARGET_NAME } from "../iosConstants";
2
+ import { ExpoConfig } from '@expo/config-types';
3
+
4
+ export default function getEasManagedCredentialsConfigExtra(config: ExpoConfig): {[k: string]: any} {
5
+ return {
6
+ ...config.extra,
7
+ eas: {
8
+ ...config.extra?.eas,
9
+ build: {
10
+ ...config.extra?.eas?.build,
11
+ experimental: {
12
+ ...config.extra?.eas?.build?.experimental,
13
+ ios: {
14
+ ...config.extra?.eas?.build?.experimental?.ios,
15
+ appExtensions: [
16
+ ...(config.extra?.eas?.build?.experimental?.ios?.appExtensions ?? []),
17
+ {
18
+ // keep in sync with native changes in NSE
19
+ targetName: NSE_TARGET_NAME,
20
+ bundleIdentifier: `${config?.ios?.bundleIdentifier}.${NSE_TARGET_NAME}`,
21
+ entitlements: {
22
+ 'com.apple.security.application-groups': [
23
+ `group.${config?.ios?.bundleIdentifier}.onesignal`
24
+ ]
25
+ },
26
+ }
27
+ ]
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
package/testRuniOS.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { xcodeProjectAddNse } from "./onesignal/withOneSignalIos";
2
+ import { Mode } from "./types/types";
2
3
 
3
4
  // Quick testing on any Xcode project
4
5
 
@@ -14,6 +15,7 @@ import { xcodeProjectAddNse } from "./onesignal/withOneSignalIos";
14
15
 
15
16
  const options = {
16
17
  iosPath: '.',
18
+ mode: Mode.Dev,
17
19
  bundleIdentifier: "com.onesignal.XcodeTestProj",
18
20
  devTeam: "99SW8E36CT",
19
21
  iPhoneDeploymentTarget: '12.0'
package/types/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * OneSignalPluginProps refer to the properties set by the user in their app config file (e.g: app.json)
3
+ */
4
+ export type OneSignalPluginProps = {
5
+ /**
6
+ * (iOS only) Environment name and bundle identifier
7
+ */
8
+ mode: Mode;
9
+ devTeam: string;
10
+ iPhoneDeploymentTarget: string;
11
+ };
12
+
13
+ /**
14
+ * Not to be confused with OneSignalPluginProps, PluginOptions are the *internal* properties used by the config plugin
15
+ * These include a combination of user-defined properties (from OneSignalPluginProps) and other data to pass between functions
16
+ */
17
+ export type PluginOptions = {
18
+ iosPath: string,
19
+ mode: Mode,
20
+ devTeam?: string,
21
+ bundleVersion?: string,
22
+ bundleShortVersion?: string,
23
+ bundleIdentifier?: string,
24
+ iPhoneDeploymentTarget?: string
25
+ }
26
+
27
+ export enum Mode {
28
+ Dev = "development",
29
+ Prod = "production"
30
+ }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ONESIGNAL_GRADLE = void 0;
4
- exports.ONESIGNAL_GRADLE = `buildscript {
5
- repositories {
6
- gradlePluginPortal()
7
- }
8
- dependencies {
9
- classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
10
- }
11
- }
12
-
13
- apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'`;
@@ -1,11 +0,0 @@
1
- export const ONESIGNAL_GRADLE =
2
- `buildscript {
3
- repositories {
4
- gradlePluginPortal()
5
- }
6
- dependencies {
7
- classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
8
- }
9
- }
10
-
11
- apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'`;