onesignal-expo-plugin 2.0.3 → 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 (42) hide show
  1. package/README.md +45 -36
  2. package/build/onesignal/withOneSignalAndroid.js +9 -15
  3. package/build/onesignal/withOneSignalIos.js +81 -47
  4. package/build/support/FileManager.js +22 -8
  5. package/build/support/NseUpdaterManager.js +8 -1
  6. package/build/support/eas/getEasManagedCredentialsConfigExtra.js +17 -17
  7. package/build/support/helpers.js +11 -7
  8. package/build/support/iosConstants.js +9 -5
  9. package/build/support/updatePodfile.js +3 -4
  10. package/build/types/types.js +9 -8
  11. package/package.json +19 -13
  12. package/.eslintignore +0 -6
  13. package/.eslintrc.js +0 -18
  14. package/.github/ISSUE_TEMPLATE/ask-question.yml +0 -50
  15. package/.github/ISSUE_TEMPLATE/bug-report.yml +0 -71
  16. package/.github/ISSUE_TEMPLATE/general-feedback.yml +0 -27
  17. package/.github/os_probot_metadata.js +0 -58
  18. package/.github/pull_request_template.md +0 -46
  19. package/.github/release-drafter.yml +0 -27
  20. package/.github/set_response_times.js +0 -47
  21. package/.github/workflows/Zapier.yml +0 -34
  22. package/.github/workflows/release-drafter.yml +0 -42
  23. package/.github/workflows/set_response_time.yml +0 -32
  24. package/CHANGELOG.md +0 -83
  25. package/EAS.md +0 -21
  26. package/IOS_CREDENTIALS_EAS.md +0 -170
  27. package/onesignal/withOneSignal.ts +0 -28
  28. package/onesignal/withOneSignalAndroid.ts +0 -147
  29. package/onesignal/withOneSignalIos.ts +0 -235
  30. package/support/FileManager.ts +0 -42
  31. package/support/NseUpdaterManager.ts +0 -40
  32. package/support/OneSignalLog.ts +0 -9
  33. package/support/eas/getEasManagedCredentialsConfigExtra.ts +0 -33
  34. package/support/helpers.ts +0 -41
  35. package/support/iosConstants.ts +0 -25
  36. package/support/serviceExtensionFiles/NotificationService.h +0 -8
  37. package/support/serviceExtensionFiles/NotificationService.m +0 -29
  38. package/support/serviceExtensionFiles/OneSignalNotificationServiceExtension-Info.plist +0 -31
  39. package/support/serviceExtensionFiles/OneSignalNotificationServiceExtension.entitlements +0 -10
  40. package/support/updatePodfile.ts +0 -19
  41. package/tsconfig.json +0 -16
  42. package/types/types.ts +0 -58
package/CHANGELOG.md DELETED
@@ -1,83 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this file.
3
-
4
- ## April 2023
5
- ### `1.3.2` - 04/18/23
6
- #### Changes
7
- - Update iOS generation to write xcode project via expo mod rather than directly to file system.
8
- - Bump qs from 6.5.2 to 6.5.3
9
- - Bump decode-uri-component from 0.2.0 to 0.2.2
10
- - Bump @xmldom/xmldom from 0.7.5 to 0.7.10
11
- - Bump multiple dependency versions in OneSignal Example App (ua-parser-js, decode-uri-component, @sideway/formula, @xmldom/xmldom)
12
-
13
- ## March 2023
14
- ### `1.3.1` - 03/03/23
15
- #### Changes
16
- - Update monorepo logic to rely on the more reliable `require.resolve` to find the `onesignal-expo-plugin` package.
17
-
18
- ## November 2022
19
- ### `1.3.0` - 11/30/22
20
- #### Changes
21
- - Add `iosNSEFilePath` configuration options to the plugin, which allows an app to specify a custom iOS Notification Service Extension.
22
-
23
- ## October 2022
24
- ### `1.2.0` - 10/25/22
25
- #### Changes
26
- - Add `smallIcons` and `largeIcons` configuration options to the plugin, which allows an app to specify large and small notification icons to package within the Android build.
27
- - Bump jpeg-js from 0.4.3 to 0.4.4
28
- - Bump simple-plist from 1.3.0 to 1.3.1
29
-
30
- ### `1.1.2` - 10/04/22
31
- #### Fixes
32
- - Specify `use_frameworks` on `OneSignalNotificationServiceExtension` target in iOS Podfile when applicable (i.e. the app target also specifies `use_frameworks`).
33
-
34
- ## September 2022
35
- ### `1.1.1` - 09/06/22
36
- #### Fixes
37
- - Fix issue where EAS release builds were no longer successfully building due to log statement
38
-
39
- ### `1.1.0` - 09/01/22
40
- #### Changes
41
- - No longer inject the OneSignal Gradle plugin on Android builds
42
- #### Fixes
43
- - Fix issue where plugin does not support monorepos
44
-
45
- ## April 2022
46
- ### `1.0.1` - 04/11/22
47
-
48
- #### Changes
49
- - Add more info regarding the `expo prebuild` command to README.
50
- #### Fixes
51
- - 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).
52
-
53
- ## March 2022
54
- ### `1.0.0` - 03/28/22
55
-
56
- #### Fixes
57
- - Upgrade dependencies (via dependabot)
58
- #### Changes
59
- - Add credentials guide and update README
60
- - Advance to General Availability
61
-
62
- ## February 2022
63
- ### `1.0.0-beta11` - 02/18/2022
64
- #### Added
65
- - Linting
66
- - 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).
67
- - iOS constants file
68
-
69
- #### Fixes
70
- - Import cleanups
71
- - Linting errors
72
- - 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).
73
-
74
- ## January 2022
75
-
76
- ### `1.0.0-beta10` - 01/24/2022
77
- #### Added
78
- - ability to configure version numbers used in the NSE target's plist file.
79
- - `OneSignalLog` class for better console logging.
80
- - this changelog file.
81
-
82
- #### Fixed
83
- - re-running `expo prebuild` will no longer result in duplicate entitlements and dependencies added to native files.
package/EAS.md DELETED
@@ -1,21 +0,0 @@
1
- # Expo Application Services
2
- EAS is Expo's cloud-build service.
3
-
4
- ## [EAS Homepage](https://expo.dev/eas)
5
-
6
- ## EAS + OneSignal Setup
7
- To get OneSignal push notifications working in an EAS-built app, see our guide on how to configure your [iOS credentials](IOS_CREDENTIALS_EAS.md).
8
-
9
- ## How to run an iOS EAS-built app
10
- ### Run in a production environment
11
- For production builds, your generated ipa file should to be distributed to the App Store or Testflight.
12
-
13
-
14
- ### Run in custom development client
15
- For development/internal distribution builds, you will need to install a [development client](https://docs.expo.dev/development/getting-started/) on your iOS device.
16
-
17
- 1. Scan the QR code shown in the terminal after EAS build success and install the development client application to your device.
18
- 2. In the terminal, run `expo start --dev-client` to be able to serve the application to the client.
19
- 3. Scan the generated QR code to open the dev client and fetch the app bundle from the running Expo process.
20
- 4. You may be prompted to allow the app to find local area network devices. Approve.
21
- 5. Rescan the QR code & open the app. At this point, you should see the metro bundler working. As soon as the bundle is complete, your working app should open!
@@ -1,170 +0,0 @@
1
- # iOS Credentials Guide: OneSignal + EAS
2
- ## Overview
3
- To distribute your iOS application, you must set up all the credentials required by Apple. The 3 primary iOS credentials are:
4
- * Distribution certificate
5
- * Provisioning profiles
6
- * Push notification certificate
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 set up separately since you are using OneSignal.
9
-
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.
12
-
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.
15
-
16
- You can still view the old instructions by clicking below.
17
-
18
- <details>
19
- <summary>Click to expand</summary>
20
-
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.
49
-
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.
51
-
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
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.
58
-
59
- **Example:**
60
- ```json
61
- {
62
- "build": {
63
- "release": {
64
- "android": {
65
- "gradleCommand": ":app:bundleRelease"
66
- },
67
- "ios": {
68
- "credentialsSource": "local",
69
- "buildConfiguration": "Release"
70
- }
71
- },
72
- "development": {
73
- "developmentClient": true,
74
- "distribution": "internal",
75
- "credentialsSource": "local"
76
- }
77
- }
78
- }
79
- ```
80
-
81
- ### 2. Identifiers
82
- In your [Apple developer console](https://developer.apple.com) create two identifiers with the following format:
83
- - `<com.example.app>` <-- you likely already have this one
84
- - `<com.example.app>.OneSignalNotificationServiceExtension`
85
-
86
- #### When modifying your existing main app identifier:
87
- - add the App Groups capability like so: `group.<identifier>.onesignal`
88
- - keep / add the "Push Notifications" capability
89
-
90
- #### When creating a new identifier for `OneSignalNotificationServiceExtension`:
91
- - select AppId from the list of identifier types
92
- - select App when choosing between App and App Clip
93
- - add the App Groups capability like so: `group.<identifier>.onesignal`
94
- - do not add the "Push Notifications" capability
95
-
96
- #### Note on App Groups at Build Time:
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.
98
-
99
- ### 3. Provisioning
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.
101
-
102
- ### 4. Add the profiles to your `credentials.json` file:
103
- Use the same distribution certificate for the `OneSignalNotificationServiceExtension` as is used for your app (no need to create a new cert).
104
-
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.
106
-
107
- **Directory structure:**
108
- ```
109
- /certs
110
- - /adhoc
111
- - /appstore
112
- ```
113
-
114
- **Example `credentials.json`:**
115
- ```json
116
- {
117
- "ios": {
118
- "<PROJECT>": {
119
- "distributionCertificate": {
120
- "path": "certs/ios_distribution_certificate.p12",
121
- "password": "***"
122
- },
123
- "provisioningProfilePath": "certs/adhoc/***mobileappprofile.mobileprovision"
124
- },
125
- "OneSignalNotificationServiceExtension": {
126
- "distributionCertificate": {
127
- "path": "certs/ios_distribution_certificate.p12",
128
- "password": "***"
129
- },
130
- "provisioningProfilePath": "certs/adhoc/***onesignalprofile.mobileprovision"
131
- }
132
- }
133
- }
134
- ```
135
-
136
- **Note:** your push certificate (p12) file should not appear anywhere in the `credentials.json` file.
137
-
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).
141
-
142
- ### Release
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.
144
-
145
- ### Development
146
- The development build will use the AdHoc provisioning profiles you created. Make sure your `credentials.json` file is using the correct profiles.
147
-
148
- ---
149
- </details>
150
-
151
- ### Expo development client
152
- If you haven't already, add the expo development client to your project:
153
-
154
- ```sh
155
- expo install expo-dev-client
156
- ```
157
-
158
- Make sure `"developmentClient": true,` is set in your `eas.json` development build profile.
159
-
160
- ### Run the EAS build command
161
- ```sh
162
- eas build --profile <build profile> --platform ios
163
- ```
164
- where `<build profile>` refers to the build profile in your `eas.json` file (e.g: "development" vs "release").
165
-
166
- ### Build success
167
- At this point, your build should succeed. You can check its progress by opening the build link in the terminal.
168
-
169
- ## How to run on your device
170
- See our [EAS guide](EAS.md) for instructions.
@@ -1,28 +0,0 @@
1
- /**
2
- * Expo config plugin for One Signal
3
- * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
4
- */
5
-
6
- import { ConfigPlugin } from '@expo/config-plugins';
7
- import { OneSignalPluginProps } from '../types/types';
8
- import { withOneSignalAndroid } from './withOneSignalAndroid';
9
- import { withOneSignalIos } from './withOneSignalIos';
10
- import { validatePluginProps } from '../support/helpers';
11
-
12
- const withOneSignal: ConfigPlugin<OneSignalPluginProps> = (config, props) => {
13
- // if props are undefined, throw error
14
- if (!props) {
15
- throw new Error(
16
- 'You are trying to use the OneSignal plugin without any props. Property "mode" is required. Please see https://github.com/OneSignal/onesignal-expo-plugin for more info.'
17
- );
18
- }
19
-
20
- validatePluginProps(props);
21
-
22
- config = withOneSignalIos(config, props);
23
- config = withOneSignalAndroid(config, props);
24
-
25
- return config;
26
- };
27
-
28
- export default withOneSignal;
@@ -1,147 +0,0 @@
1
- /**
2
- * Expo config plugin for OneSignal (Android)
3
- * @see https://documentation.onesignal.com/docs/react-native-sdk-setup#step-4-install-for-ios-using-cocoapods-for-ios-apps
4
- */
5
-
6
- import { ConfigPlugin, withDangerousMod, withStringsXml } from '@expo/config-plugins';
7
- import { generateImageAsync } from '@expo/image-utils';
8
- import { OneSignalLog } from '../support/OneSignalLog';
9
- import { OneSignalPluginProps } from '../types/types';
10
- import { resolve, parse } from 'path';
11
- import { existsSync, mkdirSync, writeFileSync } from 'fs';
12
-
13
- const RESOURCE_ROOT_PATH = 'android/app/src/main/res/';
14
-
15
- // The name of each small icon folder resource, and the icon size for that folder.
16
- const SMALL_ICON_DIRS_TO_SIZE: { [name: string]: number } = {
17
- 'drawable-mdpi': 24,
18
- 'drawable-hdpi': 36,
19
- 'drawable-xhdpi': 48,
20
- 'drawable-xxhdpi': 72,
21
- 'drawable-xxxhdpi': 96
22
- };
23
-
24
- // The name of each large icon folder resource, and the icon size for that folder.
25
- const LARGE_ICON_DIRS_TO_SIZE: { [name: string]: number } = {
26
- 'drawable-xxxhdpi': 256
27
- };
28
-
29
- const withSmallIcons: ConfigPlugin<OneSignalPluginProps> = (
30
- config,
31
- onesignalProps
32
- ) => {
33
-
34
- if(!onesignalProps.smallIcons && !config.notification?.icon) {
35
- return config
36
- }
37
-
38
- // we are modifying the android build (adding files) without a base mod
39
- return withDangerousMod(config, [
40
- 'android',
41
- async (config) => {
42
- if(config.notification?.icon) {
43
- await saveIconAsync(config.notification.icon, config.modRequest.projectRoot, SMALL_ICON_DIRS_TO_SIZE)
44
- }
45
-
46
- if(onesignalProps.smallIcons) {
47
- await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.smallIcons, SMALL_ICON_DIRS_TO_SIZE);
48
- }
49
- return config;
50
- },
51
- ]);
52
- };
53
-
54
- const withLargeIcons: ConfigPlugin<OneSignalPluginProps> = (
55
- config,
56
- onesignalProps
57
- ) => {
58
-
59
- if(!onesignalProps.largeIcons) {
60
- return config
61
- }
62
-
63
- // we are modifying the android build (adding files) without a base mod
64
- return withDangerousMod(config, [
65
- 'android',
66
- async (config) => {
67
- if(onesignalProps.largeIcons) {
68
- await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.largeIcons, LARGE_ICON_DIRS_TO_SIZE);
69
- }
70
- return config;
71
- },
72
- ]);
73
- };
74
-
75
- const withSmallIconAccentColor: ConfigPlugin<OneSignalPluginProps> = (config, onesignalProps) => {
76
- if(!onesignalProps.smallIconAccentColor) {
77
- return config
78
- }
79
-
80
- return withStringsXml(config, (config) => {
81
- const colorInARGB = `FF${onesignalProps.smallIconAccentColor?.replace('#', '')}`;
82
- const strings = config.modResults.resources.string ?? [];
83
-
84
- // Check if the accent color entry already exists
85
- const hasAccentColor = strings.some(
86
- (stringEntry) =>
87
- stringEntry.$?.name === 'onesignal_notification_accent_color' &&
88
- stringEntry._ === colorInARGB
89
- );
90
-
91
- if (!hasAccentColor) {
92
- const accentColorEntry = {
93
- $: { name: 'onesignal_notification_accent_color' },
94
- _: colorInARGB,
95
- };
96
-
97
- config.modResults.resources.string = [...strings, accentColorEntry];
98
- }
99
-
100
- return config;
101
- });
102
- }
103
-
104
- async function saveIconsArrayAsync(projectRoot: string, icons: string[], dirsToSize: { [name: string]: number }) {
105
- for(const icon of icons) {
106
- await saveIconAsync(icon, projectRoot, dirsToSize);
107
- }
108
- }
109
-
110
- async function saveIconAsync(icon: string, projectRoot: string, dirsToSize: { [name: string]: number }) {
111
- const name = parse(icon).name;
112
-
113
- OneSignalLog.log("Saving icon " + icon + " as drawable resource " + name);
114
-
115
- for(const iconResourceDir in dirsToSize) {
116
- const path = resolve(projectRoot, RESOURCE_ROOT_PATH, iconResourceDir);
117
-
118
- if(!existsSync(path)) {
119
- mkdirSync(path, { recursive: true });
120
- }
121
-
122
- const resizedIcon = (
123
- await generateImageAsync(
124
- { projectRoot, cacheType: 'onesignal-icon' },
125
- {
126
- src: icon,
127
- width: dirsToSize[iconResourceDir],
128
- height: dirsToSize[iconResourceDir],
129
- resizeMode: 'cover',
130
- backgroundColor: 'transparent',
131
- }
132
- )
133
- ).source;
134
-
135
- writeFileSync(resolve(path, name + '.png'), resizedIcon);
136
- }
137
- }
138
-
139
- export const withOneSignalAndroid: ConfigPlugin<OneSignalPluginProps> = (
140
- config,
141
- props,
142
- ) => {
143
- config = withSmallIcons(config, props);
144
- config = withLargeIcons(config, props);
145
- config = withSmallIconAccentColor(config, props);
146
- return config;
147
- };