onesignal-vue 2.1.0 → 2.3.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/.eslintignore +2 -0
- package/.eslintrc.cjs +38 -0
- package/.github/workflows/release.yml +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +98 -81
- package/dist/index.d.ts +187 -30
- package/dist/index.js +14 -12
- package/dist/index.js.map +1 -1
- package/index.ts +238 -49
- package/package.json +5 -5
- package/tsconfig.json +0 -1
- package/.eslintrc.js +0 -44
- package/.github/os_probot_metadata.js +0 -58
- package/.github/set_response_times.js +0 -47
- package/.github/workflows/Zapier.yml +0 -34
- package/.github/workflows/release-drafter.yml +0 -41
- package/.github/workflows/set_response_time.yml +0 -32
package/.eslintignore
ADDED
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
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.3.0](https://github.com/OneSignal/onesignal-vue/compare/2.2.0...2.3.0) (2025-03-28)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* sync with web-shim-codegen v3.0.4 ([c7bb67e](https://github.com/OneSignal/onesignal-vue/commit/c7bb67e6f905488fca8e14207f044970f0ed0279))
|
|
8
|
+
|
|
9
|
+
## [2.2.0](https://github.com/OneSignal/onesignal-vue/compare/2.1.0...2.2.0) (2025-03-24)
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* sync with web-shim-codegen v3.0.2 ([5937a51](https://github.com/OneSignal/onesignal-vue/commit/5937a513bcd7927fc1dc73fcc0407bb3d19f573d))
|
|
14
|
+
|
|
3
15
|
## [2.1.0](https://github.com/OneSignal/onesignal-vue/compare/2.0.1...2.1.0) (2025-03-18)
|
|
4
16
|
|
|
5
17
|
### Features
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<h1 align="center">
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
52
|
+
### npm
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
|
|
55
|
+
npm install --save onesignal-vue
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
###
|
|
58
|
+
### Yarn
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
|
|
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
|
|
96
|
-
|
|
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
|
-
|
|
126
|
-
|
|
|
127
|
-
| `appId`
|
|
128
|
-
| `autoRegister`
|
|
129
|
-
| `autoResubscribe`
|
|
130
|
-
| `path`
|
|
131
|
-
| `serviceWorkerPath`
|
|
132
|
-
| `serviceWorkerUpdaterPath`
|
|
133
|
-
| `subdomainName`
|
|
134
|
-
| `allowLocalhostAsSecureOrigin`
|
|
135
|
-
| `requiresUserPrivacyConsent
|
|
136
|
-
| `persistNotification`
|
|
137
|
-
| `notificationClickHandlerMatch
|
|
138
|
-
| `notificationClickHandlerAction
|
|
139
|
-
| `welcomeNotification`
|
|
140
|
-
| `notifyButton`
|
|
141
|
-
| `promptOptions`
|
|
142
|
-
| `webhooks`
|
|
143
|
-
| `[key: string]`
|
|
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
|
|
151
|
-
|
|
152
|
-
| `serviceWorkerParam`
|
|
153
|
-
| `serviceWorkerPath`
|
|
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
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
|
198
|
-
|'
|
|
199
|
-
| '
|
|
200
|
-
|'
|
|
201
|
-
|'
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
|
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'
|
|
226
|
+
| ---------- | ---------------------- |
|
|
227
|
+
| 'change' | boolean |
|
|
212
228
|
|
|
213
229
|
**Example**
|
|
230
|
+
|
|
214
231
|
```js
|
|
215
|
-
OneSignal.Notifications.addEventListener('click', (event) => {
|
|
216
|
-
console.log(
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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!
|