react-onesignal 3.1.1 → 3.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/.eslintrc.cjs ADDED
@@ -0,0 +1,40 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es6: true,
5
+ node: true,
6
+ },
7
+ settings: {
8
+ 'import/resolver': {
9
+ node: {
10
+ paths: ['src'],
11
+ extensions: ['.js', '.ts', '.jsx', '.tsx'],
12
+ },
13
+ },
14
+ },
15
+ extends: ['plugin:react/recommended'],
16
+ parser: '@typescript-eslint/parser',
17
+ parserOptions: {
18
+ ecmaFeatures: {
19
+ jsx: true,
20
+ },
21
+ ecmaVersion: 2018,
22
+ sourceType: 'module',
23
+ },
24
+ plugins: ['react', '@typescript-eslint'],
25
+ rules: {
26
+ 'react/jsx-filename-extension': [1, { extensions: ['.tsx', '.jsx'] }],
27
+ 'react/jsx-props-no-spreading': 0,
28
+ 'prefer-destructuring': 0,
29
+ 'no-param-reassign': 0,
30
+ 'import/extensions': 0,
31
+ 'dot-notation': 0,
32
+ 'no-continue': 0,
33
+ 'no-unused-vars': 'off',
34
+ '@typescript-eslint/no-unused-vars': ['error'],
35
+ 'no-unused-expressions': [
36
+ 'error',
37
+ { allowShortCircuit: true, allowTernary: true },
38
+ ],
39
+ },
40
+ };
@@ -24,7 +24,7 @@ jobs:
24
24
  node-version: 'lts/*'
25
25
  registry-url: 'https://registry.npmjs.org'
26
26
  - name: Install dependencies
27
- run: yarn install --frozen-lockfile
27
+ run: npm ci
28
28
  - name: Release
29
29
  env:
30
30
  GITHUB_TOKEN: ${{ secrets.GH_WEB_SHIM_PUSH_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.2.0](https://github.com/OneSignal/react-onesignal/compare/3.1.1...3.2.0) (2025-03-24)
4
+
5
+ ### Features
6
+
7
+ * sync with web-shim-codegen v3.0.2 ([1a23688](https://github.com/OneSignal/react-onesignal/commit/1a23688ba8cb42533ad561ef460eaacf2c9be6d9))
8
+
3
9
  ## [3.1.1](https://github.com/OneSignal/react-onesignal/compare/3.1.0...3.1.1) (2025-03-14)
4
10
 
5
11
  ## [3.1.0](https://github.com/OneSignal/react-onesignal/compare/3.0.1...3.1.0) (2025-03-14)
package/README.md CHANGED
@@ -16,40 +16,42 @@
16
16
 
17
17
  > This is a JavaScript module that can be used to easily include [OneSignal](https://onesignal.com/) code in a website or app in practically any JS front-end codebase (not limited to React).
18
18
 
19
- * 🏠 [Homepage](https://github.com/OneSignal/react-onesignal#readme)
20
- * 🖤 [npm](https://www.npmjs.com/package/react-onesignal)
19
+ - 🏠 [Homepage](https://github.com/OneSignal/react-onesignal#readme)
20
+ - 🖤 [npm](https://www.npmjs.com/package/react-onesignal)
21
21
 
22
22
  OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 2 million+ businesses to send 9 billion Push Notifications per day.
23
23
 
24
24
  You can find more information on OneSignal [here](https://onesignal.com/).
25
25
 
26
26
  ### Migration Guides
27
- Versions 3.0 were recently released and include breaking changes. See the [Migration Guide](https://github.com/OneSignal/react-onesignal/blob/main/MigrationGuide.md) to update your implementation.
27
+
28
+ Version 3.0 was recently released and includes breaking changes. See the [Migration Guide](https://github.com/OneSignal/react-onesignal/blob/main/MigrationGuide.md) to update your implementation.
28
29
 
29
30
  ## Contents
31
+
30
32
  - [Install](#install)
31
33
  - [Usage](#usage)
32
34
  - [API](#onesignal-api)
33
35
  - [Advanced Usage](#advanced-usage)
34
36
 
35
37
  ---
36
- ## Install
37
38
 
38
- You can use `yarn` or `npm`.
39
+ ## Install
39
40
 
40
- ### Yarn
41
+ ### npm
41
42
 
42
43
  ```bash
43
- yarn add react-onesignal
44
+ npm install --save react-onesignal
44
45
  ```
45
46
 
46
- ### npm
47
+ ### yarn
47
48
 
48
49
  ```bash
49
- npm install --save react-onesignal
50
+ yarn add react-onesignal
50
51
  ```
51
52
 
52
53
  ---
54
+
53
55
  ## Usage
54
56
 
55
57
  Initialize OneSignal with your `appId` via the `options` parameter:
@@ -63,10 +65,12 @@ OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
63
65
  The `init` function returns a promise that resolves when OneSignal is loaded.
64
66
 
65
67
  **Examples**
68
+
66
69
  ```js
67
70
  await OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
68
71
  // do other stuff
69
72
  ```
73
+
70
74
  ---
71
75
 
72
76
  ```js
@@ -75,51 +79,53 @@ OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }).then(() => {
75
79
  setInitialized(true);
76
80
  OneSignal.Slidedown.promptPush();
77
81
  // do other stuff
78
- })
82
+ });
79
83
  ```
80
84
 
81
85
  ### Init Options
86
+
82
87
  You can pass other [options](https://documentation.onesignal.com/v11.0/docs/web-sdk#initializing-the-sdk) to the `init` function. Use these options to configure personalized prompt options, auto-resubscribe, and more.
83
88
 
84
89
  <details>
85
90
  <summary>Expand to see more options</summary>
86
91
 
87
- | Property Name | Type | Description |
88
- | ---------------------------| --------------------- | -------------------------------------------------- |
89
- | `appId` | `string` | The ID of your OneSignal app. |
90
- | `autoRegister` | `boolean` (optional) | Whether or not to automatically register the user. |
91
- | `autoResubscribe` | `boolean` (optional) | Whether or not to automatically resubscribe the user. |
92
- | `path` | `string` (optional) | The path to the OneSignal service worker file. |
93
- | `serviceWorkerPath` | `string` (optional) | The path to the OneSignal service worker script. |
94
- | `serviceWorkerUpdaterPath` | `string` (optional) | The path to the OneSignal service worker updater script. |
95
- | `subdomainName` | `string` (optional) | The subdomain of your OneSignal app. |
96
- | `allowLocalhostAsSecureOrigin` | `boolean` (optional) | Whether or not to allow localhost as a secure origin. |
97
- | `requiresUserPrivacyConsent`| `boolean` (optional) | Whether or not the user's consent is required. |
98
- | `persistNotification` | `boolean` (optional) | Whether or not notifications should persist. |
99
- | `notificationClickHandlerMatch`| `string` (optional) | The URL match pattern for notification clicks. |
100
- | `notificationClickHandlerAction`| `string` (optional)| The action to perform when a notification is clicked. |
101
- | `welcomeNotification` | `object` (optional) | The welcome notification configuration. |
102
- | `notifyButton` | `object` (optional) | The notify button configuration. |
103
- | `promptOptions` | `object` (optional) | Additional options for the subscription prompt. |
104
- | `webhooks` | `object` (optional) | The webhook configuration. |
105
- | `[key: string]` | `any` | Additional properties can be added as needed. |
92
+ | Property Name | Type | Description |
93
+ | -------------------------------- | -------------------- | -------------------------------------------------------- |
94
+ | `appId` | `string` | The ID of your OneSignal app. |
95
+ | `autoRegister` | `boolean` (optional) | Whether or not to automatically register the user. |
96
+ | `autoResubscribe` | `boolean` (optional) | Whether or not to automatically resubscribe the user. |
97
+ | `path` | `string` (optional) | The path to the OneSignal service worker file. |
98
+ | `serviceWorkerPath` | `string` (optional) | The path to the OneSignal service worker script. |
99
+ | `serviceWorkerUpdaterPath` | `string` (optional) | The path to the OneSignal service worker updater script. |
100
+ | `subdomainName` | `string` (optional) | The subdomain of your OneSignal app. |
101
+ | `allowLocalhostAsSecureOrigin` | `boolean` (optional) | Whether or not to allow localhost as a secure origin. |
102
+ | `requiresUserPrivacyConsent` | `boolean` (optional) | Whether or not the user's consent is required. |
103
+ | `persistNotification` | `boolean` (optional) | Whether or not notifications should persist. |
104
+ | `notificationClickHandlerMatch` | `string` (optional) | The URL match pattern for notification clicks. |
105
+ | `notificationClickHandlerAction` | `string` (optional) | The action to perform when a notification is clicked. |
106
+ | `welcomeNotification` | `object` (optional) | The welcome notification configuration. |
107
+ | `notifyButton` | `object` (optional) | The notify button configuration. |
108
+ | `promptOptions` | `object` (optional) | Additional options for the subscription prompt. |
109
+ | `webhooks` | `object` (optional) | The webhook configuration. |
110
+ | `[key: string]` | `any` | Additional properties can be added as needed. |
106
111
 
107
112
  **Service Worker Params**
108
113
  You can customize the location and filenames of service worker assets. You are also able to specify the specific scope that your service worker should control. You can read more [here](https://documentation.onesignal.com/docs/onesignal-service-worker-faq#sdk-parameter-reference-for-service-workers).
109
114
 
110
115
  In this distribution, you can specify the parameters via the following:
111
116
 
112
- | Field | Details |
113
- |----------------------------|------------------------------------------------------------------------------------------------------------------------|
114
- | `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` |
115
- | `serviceWorkerPath` | The path to the service worker file. |
117
+ | Field | Details |
118
+ | -------------------- | -------------------------------------------------------------------------------------------------------------------- |
119
+ | `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` |
120
+ | `serviceWorkerPath` | The path to the service worker file. |
116
121
 
117
122
  </details>
118
123
 
119
124
  ---
120
125
 
121
126
  ### Service Worker File
122
- If you haven't done so already, you will need to add the [OneSignal Service Worker file](https://github.com/OneSignal/OneSignal-Website-SDK/files/7585231/OneSignal-Web-SDK-HTTPS-Integration-Files.zip) to your site ([learn more](https://documentation.onesignal.com/docs/web-push-quickstart#step-6-upload-files)).
127
+
128
+ If you haven't done so already, you will need to add the [OneSignal Service Worker file](https://github.com/OneSignal/OneSignal-Website-SDK/files/11480764/OneSignalSDK-v16-ServiceWorker.zip) to your site ([learn more](https://documentation.onesignal.com/docs/web-push-quickstart#step-6-upload-files)).
123
129
 
124
130
  The OneSignal SDK file must be publicly accessible. You can put them in your top-level root or a subdirectory. However, if you are placing the file not on top-level root make sure to specify the path via the service worker params in the init options (see section above).
125
131
 
@@ -127,65 +133,78 @@ The OneSignal SDK file must be publicly accessible. You can put them in your top
127
133
  Visit `https://yoursite.com/OneSignalSDKWorker.js` in the address bar to make sure the files are being served successfully.
128
134
 
129
135
  ---
136
+
130
137
  ### Typescript
138
+
131
139
  This package includes Typescript support.
132
140
 
133
141
  ```ts
134
142
  interface IOneSignalOneSignal {
135
- Slidedown: IOneSignalSlidedown;
136
- Notifications: IOneSignalNotifications;
137
- Session: IOneSignalSession;
138
- User: IOneSignalUser;
139
- Debug: IOneSignalDebug;
140
- login(externalId: string, jwtToken?: string): Promise<void>;
141
- logout(): Promise<void>;
142
- init(options: IInitObject): Promise<void>;
143
- setConsentGiven(consent: boolean): Promise<void>;
144
- setConsentRequired(requiresConsent: boolean): Promise<void>;
143
+ Slidedown: IOneSignalSlidedown;
144
+ Notifications: IOneSignalNotifications;
145
+ Session: IOneSignalSession;
146
+ User: IOneSignalUser;
147
+ Debug: IOneSignalDebug;
148
+ login(externalId: string, jwtToken?: string): Promise<void>;
149
+ logout(): Promise<void>;
150
+ init(options: IInitObject): Promise<void>;
151
+ setConsentGiven(consent: boolean): Promise<void>;
152
+ setConsentRequired(requiresConsent: boolean): Promise<void>;
145
153
  }
146
154
  ```
147
155
 
148
156
  ### OneSignal API
157
+
149
158
  See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for information on all available SDK functions.
150
159
 
151
160
  ---
161
+
152
162
  ## Advanced Usage
163
+
153
164
  ### Events and Event Listeners
165
+
154
166
  Use listeners to react to OneSignal-related events:
155
167
 
156
168
  ### Notifications Namespace
157
- | Event Name | Callback Argument Type |
158
- |-|-|
159
- |'click' | NotificationClickEvent|
160
- |'foregroundWillDisplay'| NotificationForegroundWillDisplayEvent
161
- | 'dismiss'| NotificationDismissEvent|
162
- |'permissionChange'| boolean|
163
- |'permissionPromptDisplay'| void|
169
+
170
+ | Event Name | Callback Argument Type |
171
+ | ------------------------- | -------------------------------------- |
172
+ | 'click' | NotificationClickEvent |
173
+ | 'foregroundWillDisplay' | NotificationForegroundWillDisplayEvent |
174
+ | 'dismiss' | NotificationDismissEvent |
175
+ | 'permissionChange' | boolean |
176
+ | 'permissionPromptDisplay' | void |
164
177
 
165
178
  ### Slidedown Namespace
166
- | Event Name | Callback Argument Type |
167
- |-|-|
168
- |'slidedownShown' | boolean |
179
+
180
+ | Event Name | Callback Argument Type |
181
+ | ---------------- | ---------------------- |
182
+ | 'slidedownShown' | boolean |
169
183
 
170
184
  ### Push Subscription Namespace
185
+
171
186
  | Event Name | Callback Argument Type |
172
- |-|-|
173
- |'change' | boolean |
187
+ | ---------- | ---------------------- |
188
+ | 'change' | boolean |
174
189
 
175
190
  **Example**
191
+
176
192
  ```js
177
193
  OneSignal.Notifications.addEventListener('click', (event) => {
178
- console.log("The notification was clicked!", event);
194
+ console.log('The notification was clicked!', event);
179
195
  });
180
196
  ```
181
197
 
182
198
  See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for all available event listeners.
183
199
 
184
200
  ## Troubleshooting
201
+
185
202
  ### `window.OneSignal already defined as 'object'!`
203
+
186
204
  You will get this error if you initialize twice. Make sure you are only initializing one time. When wrapped with `React.StrictMode`, your app might be rendering twice.
187
205
 
188
206
  ## Example App
207
+
189
208
  This repo includes an `example` React application implementing OneSignal. It was created using `create-react-app`. The app uses this repository's root level directory as the `react-onesignal` package and will bundle any changes on every run.
190
209
 
191
210
  ---
@@ -200,12 +219,13 @@ Give a ⭐️ if this project helped you!
200
219
 
201
220
  ## OneSignal
202
221
 
203
- * [Website](https://onesignal.com)
204
- * Twitter: [@onesignal](https://twitter.com/onesignal)
205
- * Github: [@OneSignal](https://github.com/OneSignal)
206
- * LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
222
+ - [Website](https://onesignal.com)
223
+ - Twitter: [@onesignal](https://twitter.com/onesignal)
224
+ - Github: [@OneSignal](https://github.com/OneSignal)
225
+ - LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
207
226
 
208
227
  ## Discord
228
+
209
229
  Reach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)!
210
230
 
211
231
  ## 📝 License
@@ -214,9 +234,10 @@ Copyright © 2023 [OneSignal](https://github.com/OneSignal).<br />
214
234
  This project is [Modified MIT](https://github.com/OneSignal/react-onesignal/blob/master/LICENSE) licensed.
215
235
 
216
236
  ## Thanks
237
+
217
238
  Special thanks to [pedro-lb](https://github.com/pedro-lb) and others for work on the project this package is [based on](https://github.com/pedro-lb/react-onesignal).
218
239
  <a href="https://github.com/onesignal/react-onesignal/graphs/contributors">
219
- <img src="https://user-images.githubusercontent.com/11739227/119415383-1d354700-bcb7-11eb-946d-01c40cd07010.png" />
240
+ <img src="https://user-images.githubusercontent.com/11739227/119415383-1d354700-bcb7-11eb-946d-01c40cd07010.png" />
220
241
  </a>
221
242
 
222
243
  Enjoy!