@onesignal/onesignal-vue3 1.0.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.js 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: [
12
+ ".js",
13
+ ".ts",
14
+ ".tsx",
15
+ ],
16
+ },
17
+ },
18
+ },
19
+ globals: {
20
+ Atomics: 'readonly',
21
+ SharedArrayBuffer: 'readonly',
22
+ },
23
+ parser: '@typescript-eslint/parser',
24
+ parserOptions: {
25
+ ecmaVersion: 2018,
26
+ sourceType: 'module',
27
+ },
28
+ plugins: [
29
+ '@typescript-eslint',
30
+ ],
31
+ rules: {
32
+ "prefer-destructuring": 0,
33
+ "no-param-reassign": 0,
34
+ "import/extensions": 0,
35
+ "dot-notation": 0,
36
+ "no-continue": 0,
37
+ "no-unused-vars": "off",
38
+ "@typescript-eslint/no-unused-vars": ["error"]
39
+ },
40
+ };
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Modified MIT License
2
+
3
+ Copyright 2022 OneSignal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ 1. The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ 2. All copies of substantial portions of the Software may only be used in connection
16
+ with services provided by OneSignal.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+ <h1 align="center">welcome to onesignal-vue3 👋</h1>
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@onesignal/onesignal-vue3.svg)](https://www.npmjs.com/package/@onesignal/onesignal-vue3) [![npm downloads](https://img.shields.io/npm/dm/@onesignal/onesignal-vue3.svg)](https://www.npmjs.com/package/@onesignal/onesignal-vue3)
4
+
5
+ Vue OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!
6
+
7
+ 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.
8
+
9
+ 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.
10
+
11
+ You can find more information on OneSignal [here](https://onesignal.com/).
12
+
13
+ * 🏠 [Homepage](https://onesignal.com)
14
+ * 🖤 [npm](https://www.npmjs.com/package/@onesignal/onesignal-vue3)
15
+
16
+ ## Contents
17
+ - [Install](#install)
18
+ - [Usage](#usage)
19
+ - [API](#onesignal-api)
20
+ - [Advanced Usage](#advanced-usage)
21
+
22
+ ---
23
+ ## Vue Compatibility
24
+ Make sure you install a plugin version compatible with your Vue environment.
25
+
26
+ | Vue | OneSignal Plugin |
27
+ |-----|------------------|
28
+ | 2 | [onesignal-vue](https://github.com/OneSignal/onesignal-vue) |
29
+ | 3 | onesignal-vue3 |
30
+
31
+ ## Install
32
+
33
+ You can use `yarn` or `npm`.
34
+
35
+
36
+ ### Yarn
37
+
38
+ ```bash
39
+ yarn add @onesignal/onesignal-vue3
40
+ ```
41
+
42
+ ### npm
43
+
44
+ ```bash
45
+ npm install --save @onesignal/onesignal-vue3
46
+ ```
47
+
48
+ ---
49
+ ## Usage
50
+
51
+ ## Plugin setup
52
+
53
+ In Vue 3, you can pass in the OneSignal initialization options directly as an argument to the `use` function. You can still initialize separately if you prefer editor benefits like code-completion.
54
+
55
+ ```js
56
+ // main
57
+ import { createApp } from 'vue'
58
+ import OneSignalVuePlugin from '@onesignal/onesignal-vue3'
59
+
60
+ createApp(App).use(OneSignalVuePlugin, {
61
+ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
62
+ }).mount('#app');
63
+
64
+ ```
65
+ or
66
+
67
+ ```js
68
+ //main
69
+ import { createApp } from 'vue'
70
+ import OneSignalVuePlugin from '@onesignal/onesignal-vue3'
71
+
72
+ createApp(App).use(OneSignalVuePlugin).mount('#app');
73
+
74
+ // component
75
+ this.$OneSignal.init({
76
+ appId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
77
+ });
78
+
79
+ ```
80
+
81
+ The OneSignal plugin automatically exposes a `$OneSignal` global property accessible inside the application.
82
+
83
+ ### Composition API
84
+
85
+ You can also leverage Vue's [Composition API](https://vuejs.org/guide/extras/composition-api-faq.html) via the `useOneSignal` function that can be called from within [`setup`](https://vuejs.org/api/composition-api-setup.html#basic-usage).
86
+
87
+ ## Reference
88
+ ### Initialization
89
+ The `init` function returns a promise that resolves when OneSignal is loaded.
90
+
91
+ **Examples**
92
+ ```js
93
+ await this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
94
+ // do other stuff
95
+ ```
96
+
97
+ ```js
98
+ this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }).then(() => {
99
+ // do other stuff
100
+ });
101
+ ```
102
+
103
+ ### Options
104
+ You can pass other [options](https://documentation.onesignal.com/docs/web-push-sdk#init) to the `init` function. Use these options to configure personalized prompt options, auto-resubscribe, and more.
105
+
106
+ **Service Worker Params**
107
+ 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).
108
+
109
+ In this distribution, you can specify the parameters via the following:
110
+
111
+ | Field | Details |
112
+ |----------------------------|------------------------------------------------------------------------------------------------------------------------|
113
+ | `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` |
114
+ | `serviceWorkerPath` | The path to the service worker file. |
115
+
116
+ ### Service Worker File
117
+ 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)).
118
+
119
+ 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).
120
+
121
+ **Tip:**
122
+ Visit `https://yoursite.com/OneSignalSDKWorker.js` in the address bar to make sure the files are being served successfully.
123
+
124
+ ### Code completion
125
+ If IntelliSense is not working as expected in your `.vue` file, try adding an import from the OneSignal plugin.
126
+
127
+
128
+ ![intellisense](https://user-images.githubusercontent.com/11739227/164801900-96592534-f991-49e0-ba36-e02bb04f31b8.png)
129
+
130
+
131
+ ### Typescript
132
+ This package includes Typescript support.
133
+
134
+ ```ts
135
+ interface IOneSignal {
136
+ init(options: IInitObject): Promise<void>;
137
+ on(event: string, listener: () => void): void;
138
+ off(event: string, listener: () => void): void;
139
+ once(event: string, listener: () => void): void;
140
+ isPushNotificationsEnabled(callback?: Action<boolean>): Promise<boolean>;
141
+ showHttpPrompt(options?: AutoPromptOptions): Promise<void>;
142
+ registerForPushNotifications(options?: RegisterOptions): Promise<void>;
143
+ setDefaultNotificationUrl(url: string): Promise<void>;
144
+ setDefaultTitle(title: string): Promise<void>;
145
+ getTags(callback?: Action<any>): Promise<void>;
146
+ sendTag(key: string, value: any, callback?: Action<Object>): Promise<Object | null>;
147
+ sendTags(tags: TagsObject<any>, callback?: Action<Object>): Promise<Object | null>;
148
+ deleteTag(tag: string): Promise<Array<string>>;
149
+ deleteTags(tags: Array<string>, callback?: Action<Array<string>>): Promise<Array<string>>;
150
+ addListenerForNotificationOpened(callback?: Action<Notification>): Promise<void>;
151
+ setSubscription(newSubscription: boolean): Promise<void>;
152
+ showHttpPermissionRequest(options?: AutoPromptOptions): Promise<any>;
153
+ showNativePrompt(): Promise<void>;
154
+ showSlidedownPrompt(options?: AutoPromptOptions): Promise<void>;
155
+ showCategorySlidedown(options?: AutoPromptOptions): Promise<void>;
156
+ showSmsSlidedown(options?: AutoPromptOptions): Promise<void>;
157
+ showEmailSlidedown(options?: AutoPromptOptions): Promise<void>;
158
+ showSmsAndEmailSlidedown(options?: AutoPromptOptions): Promise<void>;
159
+ getNotificationPermission(onComplete?: Function): Promise<NotificationPermission>;
160
+ getUserId(callback?: Action<string | undefined | null>): Promise<string | undefined | null>;
161
+ getSubscription(callback?: Action<boolean>): Promise<boolean>;
162
+ setEmail(email: string, options?: SetEmailOptions): Promise<string | null>;
163
+ setSMSNumber(smsNumber: string, options?: SetSMSOptions): Promise<string | null>;
164
+ logoutEmail(): Promise<void>;
165
+ logoutSMS(): Promise<void>;
166
+ setExternalUserId(externalUserId: string | undefined | null, authHash?: string): Promise<void>;
167
+ removeExternalUserId(): Promise<void>;
168
+ getExternalUserId(): Promise<string | undefined | null>;
169
+ provideUserConsent(consent: boolean): Promise<void>;
170
+ getEmailId(callback?: Action<string | undefined>): Promise<string | null | undefined>;
171
+ getSMSId(callback?: Action<string | undefined>): Promise<string | null | undefined>;
172
+ sendOutcome(outcomeName: string, outcomeWeight?: number | undefined): Promise<void>;
173
+ }
174
+ ```
175
+
176
+ ### OneSignal API
177
+ See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/docs/web-push-sdk) for information on all available SDK functions.
178
+
179
+ ---
180
+ ## Advanced Usage
181
+ ### Events and Event Listeners
182
+ Use listeners to react to OneSignal-related events:
183
+
184
+ * `subscriptionChange`
185
+ * `permissionPromptDisplay`
186
+ * `notificationPermissionChange`
187
+ * `popoverShown`
188
+ * `customPromptClick`
189
+ * `notificationDisplay`
190
+ * `notificationDismiss`
191
+
192
+ **Example**
193
+ ```js
194
+ this.$OneSignal.on('subscriptionChange', function(isSubscribed) {
195
+ console.log("The user's subscription state is now:", isSubscribed);
196
+ });
197
+ ```
198
+
199
+ See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/docs/web-push-sdk) for all available event listeners.
200
+
201
+ ---
202
+
203
+ ## 🤝 Contributing
204
+
205
+ Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/OneSignal/onesignal-vue3/issues).
206
+
207
+ ## Show your support
208
+
209
+ Give a ⭐️ if this project helped you!
210
+
211
+ ## OneSignal
212
+
213
+ * [Website](https://onesignal.com)
214
+ * Twitter: [@onesignal](https://twitter.com/onesignal)
215
+ * Github: [@OneSignal](https://github.com/OneSignal)
216
+ * LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
217
+
218
+ ## Discord
219
+ Reach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)!
220
+
221
+ ## 📝 License
222
+
223
+ Copyright © 2022 [OneSignal](https://github.com/OneSignal).<br />
224
+ This project is [Modified MIT](https://github.com/OneSignal/onesignal-vue3/blob/main/LICENSE) licensed.
225
+
226
+
227
+ Enjoy!
@@ -0,0 +1,119 @@
1
+ import { App } from 'vue';
2
+ declare module '@vue/runtime-core' {
3
+ interface ComponentCustomProperties {
4
+ $OneSignal: IOneSignal;
5
+ }
6
+ }
7
+ declare global {
8
+ interface Window {
9
+ OneSignal: any;
10
+ }
11
+ }
12
+ declare type Action<T> = (item: T) => void;
13
+ interface AutoPromptOptions {
14
+ force?: boolean;
15
+ forceSlidedownOverNative?: boolean;
16
+ slidedownPromptOptions?: IOneSignalAutoPromptOptions;
17
+ }
18
+ interface RegisterOptions {
19
+ modalPrompt?: boolean;
20
+ httpPermissionRequest?: boolean;
21
+ slidedown?: boolean;
22
+ autoAccept?: boolean;
23
+ }
24
+ interface SetSMSOptions {
25
+ identifierAuthHash?: string;
26
+ }
27
+ interface SetEmailOptions {
28
+ identifierAuthHash?: string;
29
+ emailAuthHash?: string;
30
+ }
31
+ interface TagsObject<T> {
32
+ [key: string]: T;
33
+ }
34
+ interface IOneSignalAutoPromptOptions {
35
+ force?: boolean;
36
+ forceSlidedownOverNative?: boolean;
37
+ isInUpdateMode?: boolean;
38
+ categoryOptions?: IOneSignalCategories;
39
+ }
40
+ interface IOneSignalCategories {
41
+ positiveUpdateButton: string;
42
+ negativeUpdateButton: string;
43
+ savingButtonText: string;
44
+ errorButtonText: string;
45
+ updateMessage: string;
46
+ tags: IOneSignalTagCategory[];
47
+ }
48
+ interface IOneSignalTagCategory {
49
+ tag: string;
50
+ label: string;
51
+ checked?: boolean;
52
+ }
53
+ interface IInitObject {
54
+ appId: string;
55
+ subdomainName?: string;
56
+ requiresUserPrivacyConsent?: boolean;
57
+ promptOptions?: object;
58
+ welcomeNotification?: object;
59
+ notifyButton?: object;
60
+ persistNotification?: boolean;
61
+ webhooks?: object;
62
+ autoResubscribe?: boolean;
63
+ autoRegister?: boolean;
64
+ notificationClickHandlerMatch?: string;
65
+ notificationClickHandlerAction?: string;
66
+ serviceWorkerParam?: {
67
+ scope: string;
68
+ };
69
+ serviceWorkerPath?: string;
70
+ serviceWorkerUpdaterPath?: string;
71
+ path?: string;
72
+ allowLocalhostAsSecureOrigin?: boolean;
73
+ [key: string]: any;
74
+ }
75
+ interface IOneSignal {
76
+ init(options: IInitObject): Promise<void>;
77
+ on(event: string, listener: () => void): void;
78
+ off(event: string, listener: () => void): void;
79
+ once(event: string, listener: () => void): void;
80
+ isPushNotificationsEnabled(callback?: Action<boolean>): Promise<boolean>;
81
+ showHttpPrompt(options?: AutoPromptOptions): Promise<void>;
82
+ registerForPushNotifications(options?: RegisterOptions): Promise<void>;
83
+ setDefaultNotificationUrl(url: string): Promise<void>;
84
+ setDefaultTitle(title: string): Promise<void>;
85
+ getTags(callback?: Action<any>): Promise<void>;
86
+ sendTag(key: string, value: any, callback?: Action<Object>): Promise<Object | null>;
87
+ sendTags(tags: TagsObject<any>, callback?: Action<Object>): Promise<Object | null>;
88
+ deleteTag(tag: string): Promise<Array<string>>;
89
+ deleteTags(tags: Array<string>, callback?: Action<Array<string>>): Promise<Array<string>>;
90
+ addListenerForNotificationOpened(callback?: Action<Notification>): Promise<void>;
91
+ setSubscription(newSubscription: boolean): Promise<void>;
92
+ showHttpPermissionRequest(options?: AutoPromptOptions): Promise<any>;
93
+ showNativePrompt(): Promise<void>;
94
+ showSlidedownPrompt(options?: AutoPromptOptions): Promise<void>;
95
+ showCategorySlidedown(options?: AutoPromptOptions): Promise<void>;
96
+ showSmsSlidedown(options?: AutoPromptOptions): Promise<void>;
97
+ showEmailSlidedown(options?: AutoPromptOptions): Promise<void>;
98
+ showSmsAndEmailSlidedown(options?: AutoPromptOptions): Promise<void>;
99
+ getNotificationPermission(onComplete?: Action<NotificationPermission>): Promise<NotificationPermission>;
100
+ getUserId(callback?: Action<string | undefined | null>): Promise<string | undefined | null>;
101
+ getSubscription(callback?: Action<boolean>): Promise<boolean>;
102
+ setEmail(email: string, options?: SetEmailOptions): Promise<string | null>;
103
+ setSMSNumber(smsNumber: string, options?: SetSMSOptions): Promise<string | null>;
104
+ logoutEmail(): Promise<void>;
105
+ logoutSMS(): Promise<void>;
106
+ setExternalUserId(externalUserId: string | undefined | null, authHash?: string): Promise<void>;
107
+ removeExternalUserId(): Promise<void>;
108
+ getExternalUserId(): Promise<string | undefined | null>;
109
+ provideUserConsent(consent: boolean): Promise<void>;
110
+ getEmailId(callback?: Action<string | undefined>): Promise<string | null | undefined>;
111
+ getSMSId(callback?: Action<string | undefined>): Promise<string | null | undefined>;
112
+ sendOutcome(outcomeName: string, outcomeWeight?: number | undefined): Promise<void>;
113
+ [index: string]: Function;
114
+ }
115
+ export declare const useOneSignal: () => unknown;
116
+ declare const OneSignalVuePlugin: {
117
+ install(app: App, options: IInitObject): void;
118
+ };
119
+ export default OneSignalVuePlugin;