onesignal-vue 2.0.1 → 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/.eslintrc.cjs ADDED
@@ -0,0 +1,38 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ browser: true,
5
+ es6: true,
6
+ node: true,
7
+ worker: true,
8
+ },
9
+ settings: {
10
+ 'import/resolver': {
11
+ node: {
12
+ paths: ['src'],
13
+ extensions: ['.js', '.ts'],
14
+ },
15
+ },
16
+ },
17
+ globals: {
18
+ Atomics: 'readonly',
19
+ SharedArrayBuffer: 'readonly',
20
+ },
21
+ parser: '@typescript-eslint/parser',
22
+ parserOptions: {
23
+ ecmaVersion: 2018,
24
+ sourceType: 'module',
25
+ },
26
+ plugins: ['@typescript-eslint'],
27
+ extends: ['plugin:@typescript-eslint/recommended'],
28
+ rules: {
29
+ 'prefer-destructuring': 0,
30
+ 'no-param-reassign': 0,
31
+ 'import/extensions': 0,
32
+ 'dot-notation': 0,
33
+ 'no-continue': 0,
34
+ 'no-unused-vars': 'off',
35
+ '@typescript-eslint/no-unused-vars': ['error'],
36
+ 'no-prototype-builtins': 'warn',
37
+ },
38
+ };
@@ -0,0 +1,40 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ jobs:
8
+ release:
9
+ name: Release
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ issues: write
14
+ pull-requests: write
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
20
+ token: ${{ secrets.GH_WEB_SHIM_PUSH_TOKEN }}
21
+ - name: Setup Node.js
22
+ uses: actions/setup-node@v4
23
+ with:
24
+ node-version: 'lts/*'
25
+ registry-url: 'https://registry.npmjs.org'
26
+ - name: Install dependencies
27
+ run: npm ci
28
+ - name: Release
29
+ env:
30
+ GITHUB_TOKEN: ${{ secrets.GH_WEB_SHIM_PUSH_TOKEN }}
31
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_WEB_SHIM_PUSH_TOKEN }}
32
+ NPM_TOKEN: ${{ secrets.NPM_WEB_SHIM_PUSH_TOKEN }}
33
+ run: |
34
+ npx -p semantic-release \
35
+ -p @semantic-release/changelog \
36
+ -p @semantic-release/git \
37
+ -p @semantic-release/github \
38
+ -p @semantic-release/npm \
39
+ -p conventional-changelog-conventionalcommits \
40
+ semantic-release
@@ -0,0 +1,133 @@
1
+ {
2
+ "branches": [
3
+ "main"
4
+ ],
5
+ "tagFormat": "${version}",
6
+ "plugins": [
7
+ [
8
+ "@semantic-release/commit-analyzer",
9
+ {
10
+ "releaseRules": [
11
+ {
12
+ "breaking": true,
13
+ "release": "minor"
14
+ },
15
+ {
16
+ "type": "feat",
17
+ "release": "minor"
18
+ },
19
+ {
20
+ "type": "fix",
21
+ "release": "patch"
22
+ },
23
+ {
24
+ "type": "docs",
25
+ "release": "patch"
26
+ },
27
+ {
28
+ "type": "perf",
29
+ "release": "patch"
30
+ },
31
+ {
32
+ "type": "refactor",
33
+ "release": "patch"
34
+ },
35
+ {
36
+ "type": "style",
37
+ "release": "patch"
38
+ },
39
+ {
40
+ "type": "test",
41
+ "release": "patch"
42
+ },
43
+ {
44
+ "type": "build",
45
+ "release": "patch"
46
+ },
47
+ {
48
+ "type": "ci",
49
+ "release": "patch"
50
+ },
51
+ {
52
+ "type": "chore",
53
+ "scope": "deps",
54
+ "release": "patch"
55
+ }
56
+ ]
57
+ }
58
+ ],
59
+ [
60
+ "@semantic-release/release-notes-generator",
61
+ {
62
+ "preset": "conventionalcommits",
63
+ "writerOpts": {
64
+ "types": [
65
+ {
66
+ "type": "feat",
67
+ "section": "Features"
68
+ },
69
+ {
70
+ "type": "fix",
71
+ "section": "Bug Fixes"
72
+ },
73
+ {
74
+ "type": "docs",
75
+ "section": "Documentation",
76
+ "hidden": false
77
+ },
78
+ {
79
+ "type": "deps",
80
+ "section": "Dependency Updates",
81
+ "hidden": false
82
+ },
83
+ {
84
+ "type": "chore",
85
+ "hidden": true
86
+ },
87
+ {
88
+ "type": "style",
89
+ "hidden": true
90
+ },
91
+ {
92
+ "type": "refactor",
93
+ "hidden": true
94
+ },
95
+ {
96
+ "type": "perf",
97
+ "hidden": true
98
+ },
99
+ {
100
+ "type": "test",
101
+ "hidden": true
102
+ }
103
+ ]
104
+ }
105
+ }
106
+ ],
107
+ [
108
+ "@semantic-release/changelog",
109
+ {
110
+ "changelogFile": "CHANGELOG.md",
111
+ "changelogTitle": "# Changelog"
112
+ }
113
+ ],
114
+ [
115
+ "@semantic-release/npm",
116
+ {
117
+ "pkgRoot": "."
118
+ }
119
+ ],
120
+ [
121
+ "@semantic-release/git",
122
+ {
123
+ "assets": [
124
+ "dist/**",
125
+ "package.json",
126
+ "CHANGELOG.md"
127
+ ],
128
+ "message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes} [skip ci]"
129
+ }
130
+ ],
131
+ "@semantic-release/github"
132
+ ]
133
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## [2.2.0](https://github.com/OneSignal/onesignal-vue/compare/2.1.0...2.2.0) (2025-03-24)
4
+
5
+ ### Features
6
+
7
+ * sync with web-shim-codegen v3.0.2 ([5937a51](https://github.com/OneSignal/onesignal-vue/commit/5937a513bcd7927fc1dc73fcc0407bb3d19f573d))
8
+
9
+ ## [2.1.0](https://github.com/OneSignal/onesignal-vue/compare/2.0.1...2.1.0) (2025-03-18)
10
+
11
+ ### Features
12
+
13
+ * sync with web-shim-codegen v3.0.1 ([689df89](https://github.com/OneSignal/onesignal-vue/commit/689df8984f94f143b3371b0e7af46fe65b71da15)), closes [#143](https://github.com/OneSignal/onesignal-vue/issues/143)
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <h1 align="center">welcome to onesignal-vue 👋</h1>
1
+ <h1 align="center">Welcome to onesignal-vue 👋</h1>
2
2
 
3
3
  <p>
4
4
  <a href="https://www.npmjs.com/package/onesignal-vue" target="_blank">
@@ -17,57 +17,59 @@
17
17
 
18
18
  > This is a JavaScript module that can be used to easily include [OneSignal](https://onesignal.com/) code in a website or app that uses Vue for its front-end codebase.
19
19
 
20
- * 🏠 [Homepage](https://onesignal.com)
21
- * 🖤 [npm](https://www.npmjs.com/package/onesignal-vue)
20
+ - 🏠 [Homepage](https://onesignal.com)
21
+ - 🖤 [npm](https://www.npmjs.com/package/onesignal-vue)
22
22
 
23
23
  OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 800k businesses to send 5 billion Push Notifications per day.
24
24
 
25
25
  You can find more information on OneSignal [here](https://onesignal.com/).
26
26
 
27
27
  > Upgrading from Version 1?
28
- See our [migration guide](./MigrationGuide.md) if coming from v1.
28
+ > See our [migration guide](./MigrationGuide.md) if coming from v1.
29
29
 
30
30
  ## Contents
31
+
31
32
  - [Install](#install)
32
33
  - [Usage](#usage)
33
34
  - [API](#onesignal-api)
34
35
  - [Advanced Usage](#advanced-usage)
35
36
 
36
37
  ---
38
+
37
39
  ## Vue Compatibility
38
- Make sure you install a plugin version compatible with your Vue environment.
39
40
 
40
- | Vue | OneSignal Plugin |
41
- |-----|------------------|
42
- | 2 | onesignal-vue |
43
- | 3 | [onesignal-vue3](https://github.com/OneSignal/onesignal-vue3) |
41
+ Make sure you install a plugin version compatible with your Vue environment.
44
42
 
43
+ | Vue | OneSignal Plugin |
44
+ | --- | ------------------------------------------------------------- |
45
+ | 2 | onesignal-vue |
46
+ | 3 | [onesignal-vue3](https://github.com/OneSignal/onesignal-vue3) |
45
47
 
46
48
  ---
47
- ## Install
48
-
49
- You can use `yarn` or `npm`.
50
49
 
50
+ ## Install
51
51
 
52
- ### Yarn
52
+ ### npm
53
53
 
54
54
  ```bash
55
- yarn add onesignal-vue
55
+ npm install --save onesignal-vue
56
56
  ```
57
57
 
58
- ### npm
58
+ ### Yarn
59
59
 
60
60
  ```bash
61
- npm install --save onesignal-vue
61
+ yarn add onesignal-vue
62
62
  ```
63
63
 
64
64
  ---
65
+
65
66
  ## Usage
66
67
 
67
68
  ## Plugin setup
69
+
68
70
  ```js
69
- import Vue from 'vue'
70
- import OneSignalVue from 'onesignal-vue'
71
+ import Vue from 'vue';
72
+ import OneSignalVue from 'onesignal-vue';
71
73
 
72
74
  Vue.use(OneSignalVue);
73
75
  ```
@@ -76,88 +78,93 @@ Initialize OneSignal with your `appId` via the `options` parameter:
76
78
 
77
79
  ```js
78
80
  new Vue({
79
- render: h => h(App),
81
+ render: (h) => h(App),
80
82
  beforeMount() {
81
83
  this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
82
- }
83
- }).$mount('#app')
84
+ },
85
+ }).$mount('#app');
84
86
  ```
85
87
 
86
88
  The `init` function returns a promise that resolves when OneSignal is loaded.
87
89
 
88
90
  **Examples**
91
+
89
92
  ```js
90
93
  await this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
91
94
  // do other stuff
92
95
  ```
93
96
 
94
97
  ```js
95
- this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }).then(() => {
96
- // do other stuff
97
- });
98
+ this.$OneSignal
99
+ .init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' })
100
+ .then(() => {
101
+ // do other stuff
102
+ });
98
103
  ```
99
104
 
100
105
  ### Code completion
106
+
101
107
  For code completion to work correctly, make sure you import the plugin (e.g: in child components).
102
108
 
103
109
  ```vue
104
110
  <script>
105
- import OneSignalVue from 'onesignal-vue';
106
111
  export default {
107
112
  name: 'HelloWorld',
108
113
  props: {
109
- msg: String
114
+ msg: String,
110
115
  },
111
116
  beforeCreate() {
112
117
  // Example prompting for notification permission
113
118
  this.$OneSignal.User.PushSubscription.optIn();
114
- }
115
- }
119
+ },
120
+ };
116
121
  </script>
117
122
  ```
118
123
 
119
124
  ### Init Options
125
+
120
126
  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.
121
127
 
122
128
  <details>
123
129
  <summary>Expand to see more options</summary>
124
130
 
125
- | Property Name | Type | Description |
126
- | ---------------------------| --------------------- | -------------------------------------------------- |
127
- | `appId` | `string` | The ID of your OneSignal app. |
128
- | `autoRegister` | `boolean` (optional) | Whether or not to automatically register the user. |
129
- | `autoResubscribe` | `boolean` (optional) | Whether or not to automatically resubscribe the user. |
130
- | `path` | `string` (optional) | The path to the OneSignal service worker file. |
131
- | `serviceWorkerPath` | `string` (optional) | The path to the OneSignal service worker script. |
132
- | `serviceWorkerUpdaterPath` | `string` (optional) | The path to the OneSignal service worker updater script. |
133
- | `subdomainName` | `string` (optional) | The subdomain of your OneSignal app. |
134
- | `allowLocalhostAsSecureOrigin` | `boolean` (optional) | Whether or not to allow localhost as a secure origin. |
135
- | `requiresUserPrivacyConsent`| `boolean` (optional) | Whether or not the user's consent is required. |
136
- | `persistNotification` | `boolean` (optional) | Whether or not notifications should persist. |
137
- | `notificationClickHandlerMatch`| `string` (optional) | The URL match pattern for notification clicks. |
138
- | `notificationClickHandlerAction`| `string` (optional)| The action to perform when a notification is clicked. |
139
- | `welcomeNotification` | `object` (optional) | The welcome notification configuration. |
140
- | `notifyButton` | `object` (optional) | The notify button configuration. |
141
- | `promptOptions` | `object` (optional) | Additional options for the subscription prompt. |
142
- | `webhooks` | `object` (optional) | The webhook configuration. |
143
- | `[key: string]` | `any` | Additional properties can be added as needed. |
131
+ | Property Name | Type | Description |
132
+ | -------------------------------- | -------------------- | -------------------------------------------------------- |
133
+ | `appId` | `string` | The ID of your OneSignal app. |
134
+ | `autoRegister` | `boolean` (optional) | Whether or not to automatically register the user. |
135
+ | `autoResubscribe` | `boolean` (optional) | Whether or not to automatically resubscribe the user. |
136
+ | `path` | `string` (optional) | The path to the OneSignal service worker file. |
137
+ | `serviceWorkerPath` | `string` (optional) | The path to the OneSignal service worker script. |
138
+ | `serviceWorkerUpdaterPath` | `string` (optional) | The path to the OneSignal service worker updater script. |
139
+ | `subdomainName` | `string` (optional) | The subdomain of your OneSignal app. |
140
+ | `allowLocalhostAsSecureOrigin` | `boolean` (optional) | Whether or not to allow localhost as a secure origin. |
141
+ | `requiresUserPrivacyConsent` | `boolean` (optional) | Whether or not the user's consent is required. |
142
+ | `persistNotification` | `boolean` (optional) | Whether or not notifications should persist. |
143
+ | `notificationClickHandlerMatch` | `string` (optional) | The URL match pattern for notification clicks. |
144
+ | `notificationClickHandlerAction` | `string` (optional) | The action to perform when a notification is clicked. |
145
+ | `welcomeNotification` | `object` (optional) | The welcome notification configuration. |
146
+ | `notifyButton` | `object` (optional) | The notify button configuration. |
147
+ | `promptOptions` | `object` (optional) | Additional options for the subscription prompt. |
148
+ | `webhooks` | `object` (optional) | The webhook configuration. |
149
+ | `[key: string]` | `any` | Additional properties can be added as needed. |
144
150
 
145
151
  **Service Worker Params**
146
152
  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).
147
153
 
148
154
  In this distribution, you can specify the parameters via the following:
149
155
 
150
- | Field | Details |
151
- |----------------------------|------------------------------------------------------------------------------------------------------------------------|
152
- | `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` |
153
- | `serviceWorkerPath` | The path to the service worker file. |
156
+ | Field | Details |
157
+ | -------------------- | -------------------------------------------------------------------------------------------------------------------- |
158
+ | `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` |
159
+ | `serviceWorkerPath` | The path to the service worker file. |
154
160
 
155
161
  </details>
156
162
 
157
163
  ---
158
164
 
159
165
  ### Service Worker File
160
- 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)).
166
+
167
+ 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)).
161
168
 
162
169
  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).
163
170
 
@@ -165,55 +172,65 @@ The OneSignal SDK file must be publicly accessible. You can put them in your top
165
172
  Visit `https://yoursite.com/OneSignalSDKWorker.js` in the address bar to make sure the files are being served successfully.
166
173
 
167
174
  ---
175
+
168
176
  ### Typescript
177
+
169
178
  This package includes Typescript support.
170
179
 
171
180
  ```ts
172
181
  interface IOneSignalOneSignal {
173
- Slidedown: IOneSignalSlidedown;
174
- Notifications: IOneSignalNotifications;
175
- Session: IOneSignalSession;
176
- User: IOneSignalUser;
177
- Debug: IOneSignalDebug;
178
- login(externalId: string, jwtToken?: string): Promise<void>;
179
- logout(): Promise<void>;
180
- init(options: IInitObject): Promise<void>;
181
- setConsentGiven(consent: boolean): Promise<void>;
182
- setConsentRequired(requiresConsent: boolean): Promise<void>;
182
+ Slidedown: IOneSignalSlidedown;
183
+ Notifications: IOneSignalNotifications;
184
+ Session: IOneSignalSession;
185
+ User: IOneSignalUser;
186
+ Debug: IOneSignalDebug;
187
+ login(externalId: string, jwtToken?: string): Promise<void>;
188
+ logout(): Promise<void>;
189
+ init(options: IInitObject): Promise<void>;
190
+ setConsentGiven(consent: boolean): Promise<void>;
191
+ setConsentRequired(requiresConsent: boolean): Promise<void>;
183
192
  }
184
193
  ```
185
194
 
186
195
  ### OneSignal API
196
+
187
197
  See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/v11.0/docs/web-sdk#initializing-the-sdk) for information on all available SDK functions.
188
198
 
189
199
  ---
200
+
190
201
  ## Advanced Usage
202
+
191
203
  ### Events and Event Listeners
204
+
192
205
  Use listeners to react to OneSignal-related events:
193
206
 
194
207
  ### Notifications Namespace
195
- | Event Name | Callback Argument Type |
196
- |-|-|
197
- |'click' | NotificationClickEvent|
198
- |'foregroundWillDisplay'| NotificationForegroundWillDisplayEvent
199
- | 'dismiss'| NotificationDismissEvent|
200
- |'permissionChange'| boolean|
201
- |'permissionPromptDisplay'| void|
208
+
209
+ | Event Name | Callback Argument Type |
210
+ | ------------------------- | -------------------------------------- |
211
+ | 'click' | NotificationClickEvent |
212
+ | 'foregroundWillDisplay' | NotificationForegroundWillDisplayEvent |
213
+ | 'dismiss' | NotificationDismissEvent |
214
+ | 'permissionChange' | boolean |
215
+ | 'permissionPromptDisplay' | void |
202
216
 
203
217
  ### Slidedown Namespace
204
- | Event Name | Callback Argument Type |
205
- |-|-|
206
- |'slidedownShown' | boolean |
218
+
219
+ | Event Name | Callback Argument Type |
220
+ | ---------------- | ---------------------- |
221
+ | 'slidedownShown' | boolean |
207
222
 
208
223
  ### Push Subscription Namespace
224
+
209
225
  | Event Name | Callback Argument Type |
210
- |-|-|
211
- |'change' | boolean |
226
+ | ---------- | ---------------------- |
227
+ | 'change' | boolean |
212
228
 
213
229
  **Example**
230
+
214
231
  ```js
215
- OneSignal.Notifications.addEventListener('click', (event) => {
216
- console.log("The notification was clicked!", event);
232
+ this.$OneSignal.Notifications.addEventListener('click', (event) => {
233
+ console.log('The notification was clicked!', event);
217
234
  });
218
235
  ```
219
236
 
@@ -231,12 +248,13 @@ Give a ⭐️ if this project helped you!
231
248
 
232
249
  ## OneSignal
233
250
 
234
- * [Website](https://onesignal.com)
235
- * Twitter: [@onesignal](https://twitter.com/onesignal)
236
- * Github: [@OneSignal](https://github.com/OneSignal)
237
- * LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
251
+ - [Website](https://onesignal.com)
252
+ - Twitter: [@onesignal](https://twitter.com/onesignal)
253
+ - Github: [@OneSignal](https://github.com/OneSignal)
254
+ - LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
238
255
 
239
256
  ## Discord
257
+
240
258
  Reach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)!
241
259
 
242
260
  ## 📝 License
@@ -244,5 +262,4 @@ Reach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)!
244
262
  Copyright © 2022 [OneSignal](https://github.com/OneSignal).<br />
245
263
  This project is [Modified MIT](https://github.com/OneSignal/onesignal-vue/blob/main/LICENSE) licensed.
246
264
 
247
-
248
265
  Enjoy!