├── .eslintignore ├── .eslintrc.cjs ├── .github ├── ISSUE_TEMPLATE │ ├── ask-question.yml │ ├── bug-report.yml │ ├── general-feedback.yml │ └── workflows │ │ ├── Zapier.yml │ │ └── release-drafter.yml ├── release-drafter.yml └── workflows │ ├── project.yml │ └── release.yml ├── .gitignore ├── .npmignore ├── .releaserc.json ├── CHANGELOG.md ├── LICENSE ├── MigrationGuide.md ├── README.md ├── dist ├── index.d.ts ├── index.js └── index.js.map ├── example ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public │ ├── OneSignalSDKWorker.js │ ├── favicon.ico │ └── index.html └── src │ ├── App.vue │ ├── assets │ └── logo.png │ ├── components │ └── HelloWorld.vue │ └── main.js ├── index.ts ├── package-lock.json ├── package.json └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | example/ 3 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 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 | }; 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ask-question.yml: -------------------------------------------------------------------------------- 1 | name: 🙋‍♂️ Ask a question 2 | description: Tell us what's on your mind 3 | title: '[Question]: ' 4 | labels: ['Question'] 5 | 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | Having issues integrating this SDK? 11 | - type: textarea 12 | id: question 13 | attributes: 14 | label: How can we help? 15 | description: Specific question regarding integrating this SDK. 16 | placeholder: How do I...? 17 | validations: 18 | required: true 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: 🪳 Bug report 2 | description: File a bug report 3 | title: '[Bug]: ' 4 | labels: ['Bug'] 5 | 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | Thanks for taking the time to fill out this bug report! 11 | - type: textarea 12 | id: what-happened 13 | attributes: 14 | label: What happened? 15 | description: Provide a thorough description of whats going on. 16 | placeholder: The latest version of the SDK causes a runtime error. 17 | validations: 18 | required: true 19 | - type: dropdown 20 | id: browsers 21 | attributes: 22 | label: What browsers are you seeing the problem on? 23 | multiple: true 24 | options: 25 | - Firefox 26 | - Chrome (Chromium) 27 | - Safari 28 | - Microsoft Edge 29 | - Opera 30 | - Brave 31 | - Other 32 | validations: 33 | required: true 34 | - type: input 35 | id: operating-system 36 | attributes: 37 | label: What operating system are you running? 38 | description: Make sure to include the version. 39 | placeholder: macOS Monterey 12.3.1 40 | validations: 41 | required: true 42 | - type: textarea 43 | id: reproduction-steps 44 | attributes: 45 | label: Steps to reproduce? 46 | description: Provide as much detail as posible to reproduce the issue. 47 | placeholder: | 48 | 1. Install dependencies: vX.Y.Z, etc... 49 | 2. Run the app 50 | 3. Click on the notification prompt 51 | 4. Note that this causes a runtime error and a failed subscription. 52 | render: Markdown 53 | validations: 54 | required: true 55 | - type: textarea 56 | id: what-are-expectations 57 | attributes: 58 | label: What did you expect to happen? 59 | description: Also tell us, what did you expect to happen? 60 | placeholder: I expected the notification prompt to cause a native permission change in the browser. 61 | validations: 62 | required: true 63 | - type: textarea 64 | id: logs 65 | attributes: 66 | label: Relevant log output 67 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 68 | render: Shell 69 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/general-feedback.yml: -------------------------------------------------------------------------------- 1 | name: 📣 General feedback 2 | description: Tell us what's on your mind 3 | title: '[Feedback]: ' 4 | labels: ['Feedback'] 5 | 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | Thanks for sharing your valuable feedback! 11 | - type: textarea 12 | id: feedback 13 | attributes: 14 | label: What's on your mind? 15 | description: Feedback regarding this SDK. 16 | placeholder: Share your feedback... 17 | validations: 18 | required: true 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/workflows/Zapier.yml: -------------------------------------------------------------------------------- 1 | # This is an action to close asana tasks that were generated by Github issues 2 | 3 | name: Zapier web hook 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the "main" branch 8 | issues: 9 | types: [closed] 10 | 11 | permissions: 12 | issues: read 13 | 14 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 15 | jobs: 16 | # This workflow contains a single job called "build" 17 | build: 18 | # The type of runner that the job will run on 19 | runs-on: ubuntu-latest 20 | 21 | # Steps represent a sequence of tasks that will be executed as part of the job 22 | steps: 23 | # Runs a set of commands using the runners shell 24 | - name: Call Zapier web hook to close Asana task 25 | if: ${{ !github.event.issue.pull_request }} 26 | env: 27 | ISSUE_TITLE: ${{ github.event.issue.title }} 28 | run: | 29 | curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \ 30 | --header 'Content-Type: application/json' \ 31 | --header 'Accept: application/json' \ 32 | --data-raw '{ 33 | "task_name" : "$ISSUE_TITLE" 34 | }' 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | # branches to consider in the event; optional, defaults to all 6 | branches: 7 | - main 8 | # pull_request event is required only for autolabeler 9 | pull_request: 10 | # Only following types are handled by the action, but one can default to all as well 11 | types: [opened, reopened, synchronize] 12 | # pull_request_target event is required for autolabeler to support PRs from forks 13 | # pull_request_target: 14 | # types: [opened, reopened, synchronize] 15 | 16 | permissions: 17 | contents: read 18 | 19 | jobs: 20 | update_release_draft: 21 | permissions: 22 | # write permission is required to create a github release 23 | contents: write 24 | # write permission is required for autolabeler 25 | # otherwise, read permission is required at least 26 | pull-requests: write 27 | runs-on: ubuntu-latest 28 | steps: 29 | # (Optional) GitHub Enterprise requires GHE_HOST variable set 30 | #- name: Set GHE_HOST 31 | # run: | 32 | # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV 33 | 34 | # Drafts your next Release notes as Pull Requests are merged into "master" 35 | - uses: release-drafter/release-drafter@v5 36 | # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml 37 | # with: 38 | # config-name: my-config.yml 39 | # disable-autolabeler: true 40 | env: 41 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 42 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: $RESOLVED_VERSION 2 | tag-template: $RESOLVED_VERSION 3 | categories: 4 | - title: 🚀 Features 5 | label: Enhancement / Feature 6 | - title: 🐛 Bug Fixes 7 | label: Bug 8 | - title: 🧰 Improvements 9 | label: Improvement 10 | - title: down arrow Dependency Updates 11 | label: Dependencies 12 | change-template: '- $TITLE (#$NUMBER)' 13 | version-resolver: 14 | major: 15 | labels: 16 | - 'major' 17 | minor: 18 | labels: 19 | - 'minor' 20 | patch: 21 | labels: 22 | - 'patch' 23 | default: patch 24 | template: | 25 | ## Other Changes 26 | 27 | $CHANGES 28 | -------------------------------------------------------------------------------- /.github/workflows/project.yml: -------------------------------------------------------------------------------- 1 | name: Add issues to project 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | 8 | jobs: 9 | add-to-project: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Add issue to project 13 | uses: actions/add-to-project@v1.0.2 14 | with: 15 | # SDK Web Project 16 | project-url: https://github.com/orgs/OneSignal/projects/9 17 | github-token: ${{ secrets.GH_PROJECTS_TOKEN }} 18 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 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 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | 6 | # builds 7 | build 8 | dist 9 | .rpt2_cache 10 | 11 | # misc 12 | .DS_Store 13 | .env 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | 6 | # builds 7 | build 8 | .rpt2_cache 9 | 10 | # misc 11 | .DS_Store 12 | .env 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | .babelrc; 18 | 19 | npm-debug.log* 20 | example 21 | 22 | .github 23 | .releaserc.json 24 | 25 | .eslintignore 26 | .gitignore -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": ["main"], 3 | "tagFormat": "${version}", 4 | "plugins": [ 5 | [ 6 | "@semantic-release/commit-analyzer", 7 | { 8 | "releaseRules": [ 9 | { 10 | "breaking": true, 11 | "release": "minor" 12 | }, 13 | { 14 | "type": "feat", 15 | "release": "minor" 16 | }, 17 | { 18 | "type": "fix", 19 | "release": "patch" 20 | }, 21 | { 22 | "type": "docs", 23 | "release": "patch" 24 | }, 25 | { 26 | "type": "perf", 27 | "release": "patch" 28 | }, 29 | { 30 | "type": "refactor", 31 | "release": "patch" 32 | }, 33 | { 34 | "type": "style", 35 | "release": "patch" 36 | }, 37 | { 38 | "type": "test", 39 | "release": "patch" 40 | }, 41 | { 42 | "type": "build", 43 | "release": "patch" 44 | }, 45 | { 46 | "type": "chore", 47 | "scope": "deps", 48 | "release": "patch" 49 | } 50 | ] 51 | } 52 | ], 53 | [ 54 | "@semantic-release/release-notes-generator", 55 | { 56 | "preset": "conventionalcommits", 57 | "writerOpts": { 58 | "types": [ 59 | { 60 | "type": "feat", 61 | "section": "Features" 62 | }, 63 | { 64 | "type": "fix", 65 | "section": "Bug Fixes" 66 | }, 67 | { 68 | "type": "docs", 69 | "section": "Documentation", 70 | "hidden": false 71 | }, 72 | { 73 | "type": "deps", 74 | "section": "Dependency Updates", 75 | "hidden": false 76 | }, 77 | { 78 | "type": "chore", 79 | "hidden": true 80 | }, 81 | { 82 | "type": "style", 83 | "hidden": true 84 | }, 85 | { 86 | "type": "refactor", 87 | "hidden": true 88 | }, 89 | { 90 | "type": "perf", 91 | "hidden": true 92 | }, 93 | { 94 | "type": "test", 95 | "hidden": true 96 | } 97 | ] 98 | } 99 | } 100 | ], 101 | [ 102 | "@semantic-release/changelog", 103 | { 104 | "changelogFile": "CHANGELOG.md", 105 | "changelogTitle": "# Changelog" 106 | } 107 | ], 108 | [ 109 | "@semantic-release/npm", 110 | { 111 | "pkgRoot": "." 112 | } 113 | ], 114 | [ 115 | "@semantic-release/git", 116 | { 117 | "assets": ["dist/**", "package.json", "CHANGELOG.md"], 118 | "message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes} [skip ci]" 119 | } 120 | ], 121 | "@semantic-release/github" 122 | ] 123 | } 124 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [2.2.2](https://github.com/OneSignal/onesignal-vue3/compare/2.2.1...2.2.2) (2025-06-06) 4 | 5 | ### Bug Fixes 6 | 7 | * sync with web-shim-codegen v3.0.5 ([127de33](https://github.com/OneSignal/onesignal-vue3/commit/127de33d807f0458fe2471401c192e5b3d824ef3)) 8 | 9 | ## [2.2.1](https://github.com/OneSignal/onesignal-vue3/compare/2.2.0...2.2.1) (2025-03-28) 10 | 11 | ### Bug Fixes 12 | 13 | * add promise reject for init call ([da28464](https://github.com/OneSignal/onesignal-vue3/commit/da28464e8c233ae37824db57b349ab49f01fca55)) 14 | 15 | ## [2.2.0](https://github.com/OneSignal/onesignal-vue3/compare/2.1.0...2.2.0) (2025-03-24) 16 | 17 | ### Features 18 | 19 | * sync with web-shim-codegen v3.0.2 ([7bca3c5](https://github.com/OneSignal/onesignal-vue3/commit/7bca3c52704d04a55beb179f23ef5bd3d35e660f)) 20 | 21 | ## [2.1.0](https://github.com/OneSignal/onesignal-vue3/compare/2.0.1...2.1.0) (2025-03-18) 22 | 23 | ### Features 24 | 25 | * sync with web-shim-codegen v3.0.1 ([ce65df3](https://github.com/OneSignal/onesignal-vue3/commit/ce65df3d95781939b291ca79fed9639f29bf8a3e)), closes [#143](https://github.com/OneSignal/onesignal-vue3/issues/143) 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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. 25 | -------------------------------------------------------------------------------- /MigrationGuide.md: -------------------------------------------------------------------------------- 1 | 2 | # Migration Guide 3 | 4 | ## Version 2 5 | ### Intro 6 | In this release, we are making a significant shift from a device-centered model to a user-centered model. This means that instead of identifying devices, we now focus on identifying individual users. This update is part of a larger effort to shift towards a user-oriented omni-channel messaging system. 7 | 8 | To facilitate this change, the externalId approach for identifying users is being replaced by the login and logout methods. In addition, the SDK now makes use of namespaces such as User, Notifications, and Slidedown to better separate code. 9 | 10 | This guide will walk you through these and other important changes in the version 16 update. 11 | 12 | ### Overview 13 | Under the new model, the concept of a "player" is being updated to include three new concepts: users, subscriptions, and aliases. 14 | 15 | ### Users 16 | Users own subscriptions and are identified by aliases which are used to point to users using different alias schemes. 17 | 18 | ### Subscriptions 19 | 20 | Subscriptions refer to the way in which a user can receive various communication methods offered by OneSignal, including push notifications, SMS, and email. 21 | 22 | ### Aliases 23 | Aliases are identifiers that point to users and are made up of an alias label and id. Users can have multiple aliases. Consider the need to identify a user with your own application's unique identifier as well as identifiers from other integrated applications. 24 | 25 | The SDK will use `external_id` as the default alias label for the public `OneSignal.login("1234")` method. 26 | 27 | **Alias Example:** 28 | ``` 29 | "aliases": [ 30 | { 31 | "label": "external_id", 32 | "id": "1234" 33 | }, 34 | { 35 | "label": "my_alias", 36 | "id": "5678" 37 | } 38 | ] 39 | ``` 40 | 41 | ```js 42 | // WebSDK-specific example 43 | { 44 | external_id: "1234", 45 | my_alias: "5678" 46 | } 47 | ``` 48 | 49 | # Guide 50 | ## 1. Setup Changes 51 | ### Service Worker File 52 | 53 | From: 54 | ```js 55 | importScripts("https://onesignal.com/sdks/OneSignalSDKWorker.js"); 56 | ``` 57 | 58 | To: 59 | ```js 60 | importScripts("https://onesignal.com/sdks/web/v16/OneSignalSDK.sw.js"); 61 | ``` 62 | 63 | ## 2. External User ID 64 | Update any usages of `OneSignal.setExternalId` to `OneSignal.login` or `OneSignal.logout` 65 | From: 66 | ```js 67 | OneSignal.setExternalId("myId"); 68 | ``` 69 | 70 | To: 71 | ```js 72 | OneSignal.login("myId"); 73 | ``` 74 | 75 | Use `OneSignal.logout();` instead anywhere you have `OneSignal.setExternalId("");` or are setting it to `null`. 76 | 77 | ## 3. API Changes 78 | Update your code to use the new API. The following namespaces are on the `OneSignal` object. 79 | 80 | ### User Namespace 81 | 82 | Example: 83 | ```js 84 | OneSignal.User.addAlias("my_alias", "1234"); 85 | ``` 86 | 87 | All user functions are synchronous. 88 | 89 | | Function Name | Description | Argument List | 90 | | --------------- | ---------------------------------------------- | ------------------------------------ | 91 | | `addAlias` | Adds a new alias for the current user. | `label: string, id: string` | 92 | | `addAliases` | Adds multiple aliases for the current user. | `aliases: { [key: string]: string }` | 93 | | `removeAlias` | Removes an alias for the current user. | `label: string` | 94 | | `removeAliases` | Removes multiple aliases for the current user. | `labels: string[]` | 95 | | `addEmail` | Adds an email address for the current user. | `email: string` | 96 | | `removeEmail` | Removes an email address for the current user. | `email: string` | 97 | | `addSms` | Adds an SMS number for the current user. | `smsNumber: string` | 98 | | `removeSms` | Removes an SMS number for the current user. | `smsNumber: string` | 99 | | `addTag` | Adds a tag for the current user. | `key: string, value: string` | 100 | | `addTags` | Adds multiple tags for the current user. | `tags: { [key: string]: string }` | 101 | | `removeTag` | Removes a tag for the current user. | `key: string` | 102 | | `removeTags` | Removes multiple tags for the current user. | `keys: string[]` | 103 | 104 | ### Notifications Namespace 105 | 106 | Example: 107 | ```js 108 | await OneSignal.Notifications.requestPermission(); 109 | ``` 110 | 111 | | Sync/Async | Property/Function | Description | Argument List | 112 | | ---------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | 113 | | `async` | `setDefaultUrl()` | Sets the default URL for notifications. | `url` (string) | 114 | | `async` | `setDefaultTitle()` | Sets the default title for notifications. | `title` (string) | 115 | | `sync` | `isPushSupported()` | Returns true if the current browser supports web push. | | 116 | | `async` | `requestPermission()` | Requests push notifications permission via the native browser prompt. | | 117 | | | `permission` | Returns true if your site has permission to display notifications. | | 118 | | | `permissionNative` | Returns browser's native notification permission status; `"default"`(end-user has not accept or decided yet), `"granted"`, or `"denied"`. | | 119 | | `sync` | `addEventListener()` | Adds an event listener for the following events:

- `click`
- `foregroundWillDisplay`
- `dismiss`
- `permissionPromptDisplay`
- `permissionChange`*
* argument type: bool | - `` (string)
- `(arg: ) => {}` (callback) | 120 | | `sync` | `removeEventListener()` | Removes the event listener. | `() => {}` (the event listener you want to remove) | 121 | 122 | 123 | 124 | ### Slidedown Namespace 125 | 126 | Example: 127 | ```js 128 | await OneSignal.Slidedown.promptPush(); 129 | ``` 130 | 131 | | Sync/Async | Function Name | Description | Argument List | 132 | | ---------- | ---------------------- | ------------------------------------------------------------------------ | ---------------------------------------------------------------------------- | 133 | | `async` | `promptPush` | Displays the notification permission prompt. | `options` (AutoPromptOptions) | 134 | | `async` | `promptPushCategories` | Displays the notification permission prompt for notification categories. | `options` (AutoPromptOptions) | 135 | | `async` | `promptSms` | Displays the SMS subscription prompt. | `options` (AutoPromptOptions) | 136 | | `async` | `promptEmail` | Displays the email subscription prompt. | `options` (AutoPromptOptions) | 137 | | `async` | `promptSmsAndEmail` | Displays the SMS and email subscription prompts. | `options` (AutoPromptOptions) | 138 | | `sync` | `addEventListener` | Adds an event listener for the `slidedownShown` event. | - `event` ("slidedownShown"),
- `listener` ((wasShown: boolean) => void) | 139 | | `sync` | `removeEventListener` | Removes an event listener for the `slidedownShown` event. | - `event` ("slidedownShown")
- `listener` ((wasShown: boolean) => void) | 140 | 141 | 142 | 143 | ### Push Subscription Namespace 144 | 145 | Example: 146 | ```js 147 | OneSignal.User.PushSubscription.optIn(); 148 | ``` 149 | 150 | | Sync/Async | Property/Function | Description | Argument List | 151 | | ---------- | ----------------------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | 152 | | | `id` | Gets the current user's ID. | | 153 | | | `token` | Gets the current user's push notification token. | | 154 | | | `optedIn` | Gets a boolean value indicating whether the current user is subscribed to push notifications. | | 155 | | `async` | `optIn()` | Subscribes the current user to push notifications. | | 156 | | `async` | `optOut()` | Unsubscribes the current user from push notifications. | | 157 | | `sync` | `addEventListener()` | Adds an event listener for the `change` event. | - `event` ("change")
- `listener` ((change: SubscriptionChangeEvent) => void) | 158 | | `sync` | `removeEventListener()` | Removes an event listener for the `change` event. | - `event` ("change")
- `listener` ((change: SubscriptionChangeEvent) => void) | 159 | 160 | ### Debug Namespace 161 | 162 | Example: 163 | ```js 164 | OneSignal.Debug.setLogLevel(“trace”); 165 | ``` 166 | 167 | | Function Name | Description | Argument List | 168 | | --------------- | ---------------------------------------------- | ------------------------------------ | 169 | | `setLogLevel` | Turns on logging with the given log level. | `setLogLevel: string`
- `"trace"`
- `"debug"`
- `"info"`
- `"warn"`
- `"error"` | 170 | 171 | # Limitations 172 | * HTTP environments are no longer supported. 173 | * AMP environments are not supported. 174 | * Identity verification not available yet, coming soon. 175 | 176 | # Glossary 177 | 178 | **OneSignal user** 179 | 180 |       *(noun) lowercase* 181 | 182 |       A user of the OneSignal service. 183 | 184 | **user** 185 | 186 |       *(noun) lowercase* 187 | 188 |       An end-user of an application using the OneSignal service. They may or may not have a subscription. 189 | 190 | **user ID** 191 | 192 |       *(noun) lowercase* 193 | 194 |       A OneSignal-provisioned unique identifier for Users (User.onesignal_id). 195 | 196 | 197 | **user external ID** 198 | 199 |       *(noun) lowercase* 200 | 201 |       A customer-provisioned unique identifier for Users (User.external_id). 202 | 203 | 204 | **user alias** 205 | 206 |       *(noun) lowercase* 207 | 208 |       A customer provisioned key-value pair used to uniquely identify a User. 209 | 210 | 211 | **subscription** 212 | 213 |       *(noun) lowercase* 214 | 215 |       An established communication channel between an App and its User, such as a push-subscribed device, email address, or SMS-subscribed phone number. 216 | 217 | 218 | **subscription ID** 219 | 220 |       *(noun) lowercase* 221 | 222 |       A OneSignal-provisioned unique identifier for a single subscription. 223 | 224 | 225 | **notification** 226 | 227 |       *(noun) lowercase* 228 | 229 |       A unidirectional outbound communication message from an App to one or more Users via their Subscriptions. 230 | 231 | 232 | **notification ID** 233 | 234 |       *(noun) lowercase* 235 | 236 |       A OneSignal-provisioned unique identifier for Notifications (Notification.id). 237 | 238 | 239 | **notification external ID** 240 | 241 |       *(noun) lowercase* 242 | 243 |       A customer-provisioned unique identifier for Notifications (Notification.external_id). 244 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Welcome to onesignal-vue3 👋

2 |

3 | 4 | Version 5 | 6 | 7 | Documentation 8 | 9 | 10 | Maintenance 11 | 12 | 13 | Twitter: onesignal 14 | 15 |

16 | 17 | > 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. 18 | 19 | - 🏠 [Homepage](https://onesignal.com) 20 | - 🖤 [npm](https://www.npmjs.com/package/@onesignal/onesignal-vue3) 21 | 22 | OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 2 million+ developers to send 12 billion Push Notifications per day. 23 | 24 | You can find more information on OneSignal [here](https://onesignal.com/). 25 | 26 | > Upgrading from Version 1? 27 | > See our [migration guide](./MigrationGuide.md) to get started with v2. 28 | 29 | ## Contents 30 | 31 | - [Install](#install) 32 | - [Usage](#usage) 33 | - [API](#onesignal-api) 34 | - [Advanced Usage](#advanced-usage) 35 | 36 | --- 37 | 38 | ## Vue Compatibility 39 | 40 | Make sure you install a plugin version compatible with your Vue environment. 41 | 42 | | Vue | OneSignal Plugin | 43 | | --- | ----------------------------------------------------------- | 44 | | 2 | [onesignal-vue](https://github.com/OneSignal/onesignal-vue) | 45 | | 3 | onesignal-vue3 | 46 | 47 | ## Install 48 | 49 | Run `npm install` 50 | 51 | ### Yarn 52 | 53 | ```bash 54 | yarn add @onesignal/onesignal-vue3 55 | ``` 56 | 57 | ### npm 58 | 59 | ```bash 60 | npm install --save @onesignal/onesignal-vue3 61 | ``` 62 | 63 | ### Yarn 64 | 65 | ```bash 66 | yarn add @onesignal/onesignal-vue3 67 | ``` 68 | 69 | --- 70 | 71 | ## Usage 72 | 73 | ## Plugin setup 74 | 75 | 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. 76 | 77 | ```js 78 | // main 79 | import { createApp } from 'vue'; 80 | import OneSignalVuePlugin from '@onesignal/onesignal-vue3'; 81 | 82 | createApp(App) 83 | .use(OneSignalVuePlugin, { 84 | appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 85 | }) 86 | .mount('#app'); 87 | ``` 88 | 89 | or 90 | 91 | ```js 92 | //main 93 | import { createApp } from 'vue'; 94 | import OneSignalVuePlugin from '@onesignal/onesignal-vue3'; 95 | 96 | createApp(App).use(OneSignalVuePlugin).mount('#app'); 97 | 98 | // component 99 | this.$OneSignal.init({ 100 | appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 101 | }); 102 | ``` 103 | 104 | The OneSignal plugin automatically exposes a `$OneSignal` global property accessible inside the application. 105 | 106 | ### Composition API 107 | 108 | 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). 109 | 110 | ## Reference 111 | 112 | ### Initialization 113 | 114 | The `init` function returns a promise that resolves when OneSignal is loaded. 115 | 116 | **Examples** 117 | 118 | ```js 119 | await this.$OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }); 120 | // do other stuff 121 | ``` 122 | 123 | ```js 124 | this.$OneSignal 125 | .init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }) 126 | .then(() => { 127 | // do other stuff 128 | }); 129 | ``` 130 | 131 | ### Init Options 132 | 133 | You can pass other [options](https://documentation.onesignal.com/docs/web-sdk-reference#init) to the `init` function. Use these options to configure personalized prompt options, auto-resubscribe, and more. 134 | 135 |
136 | Expand to see more options 137 | 138 | | Property Name | Type | Description | 139 | | -------------------------------- | -------------------- | -------------------------------------------------------- | 140 | | `appId` | `string` | The ID of your OneSignal app. | 141 | | `autoRegister` | `boolean` (optional) | Whether or not to automatically register the user. | 142 | | `autoResubscribe` | `boolean` (optional) | Whether or not to automatically resubscribe the user. | 143 | | `path` | `string` (optional) | The path to the OneSignal service worker file. | 144 | | `serviceWorkerPath` | `string` (optional) | The path to the OneSignal service worker script. | 145 | | `serviceWorkerUpdaterPath` | `string` (optional) | The path to the OneSignal service worker updater script. | 146 | | `subdomainName` | `string` (optional) | The subdomain of your OneSignal app. | 147 | | `allowLocalhostAsSecureOrigin` | `boolean` (optional) | Whether or not to allow localhost as a secure origin. | 148 | | `requiresUserPrivacyConsent` | `boolean` (optional) | Whether or not the user's consent is required. | 149 | | `persistNotification` | `boolean` (optional) | Whether or not notifications should persist. | 150 | | `notificationClickHandlerMatch` | `string` (optional) | The URL match pattern for notification clicks. | 151 | | `notificationClickHandlerAction` | `string` (optional) | The action to perform when a notification is clicked. | 152 | | `welcomeNotification` | `object` (optional) | The welcome notification configuration. | 153 | | `notifyButton` | `object` (optional) | The notify button configuration. | 154 | | `promptOptions` | `object` (optional) | Additional options for the subscription prompt. | 155 | | `webhooks` | `object` (optional) | The webhook configuration. | 156 | | `[key: string]` | `any` | Additional properties can be added as needed. | 157 | 158 | **Service Worker Params** 159 | 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). 160 | 161 | In this distribution, you can specify the parameters via the following: 162 | 163 | | Field | Details | 164 | | -------------------- | -------------------------------------------------------------------------------------------------------------------- | 165 | | `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` | 166 | | `serviceWorkerPath` | The path to the service worker file. | 167 | 168 |
169 | 170 | --- 171 | 172 | ### Service Worker File 173 | 174 | 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)). 175 | 176 | 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). 177 | 178 | **Tip:** 179 | Visit `https://yoursite.com/OneSignalSDKWorker.js` in the address bar to make sure the files are being served successfully. 180 | 181 | ### Code completion 182 | 183 | If IntelliSense is not working as expected in your `.vue` file, try adding an import from the OneSignal plugin. 184 | 185 | ![intellisense](https://user-images.githubusercontent.com/11739227/164801900-96592534-f991-49e0-ba36-e02bb04f31b8.png) 186 | 187 | ### Typescript 188 | 189 | This package includes Typescript support. 190 | 191 | ```ts 192 | interface IOneSignalOneSignal { 193 | Slidedown: IOneSignalSlidedown; 194 | Notifications: IOneSignalNotifications; 195 | Session: IOneSignalSession; 196 | User: IOneSignalUser; 197 | Debug: IOneSignalDebug; 198 | login(externalId: string, jwtToken?: string): Promise; 199 | logout(): Promise; 200 | init(options: IInitObject): Promise; 201 | setConsentGiven(consent: boolean): Promise; 202 | setConsentRequired(requiresConsent: boolean): Promise; 203 | } 204 | ``` 205 | 206 | ### OneSignal API 207 | 208 | See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/docs/web-sdk) for information on all available SDK functions. 209 | 210 | --- 211 | 212 | ## Advanced Usage 213 | 214 | ### Events and Event Listeners 215 | 216 | Use listeners to react to OneSignal-related events: 217 | 218 | ### Notifications Namespace 219 | 220 | | Event Name | Callback Argument Type | 221 | | ------------------------- | -------------------------------------- | 222 | | 'click' | NotificationClickEvent | 223 | | 'foregroundWillDisplay' | NotificationForegroundWillDisplayEvent | 224 | | 'dismiss' | NotificationDismissEvent | 225 | | 'permissionChange' | boolean | 226 | | 'permissionPromptDisplay' | void | 227 | 228 | ### Slidedown Namespace 229 | 230 | | Event Name | Callback Argument Type | 231 | | ---------------- | ---------------------- | 232 | | 'slidedownShown' | boolean | 233 | 234 | ### Push Subscription Namespace 235 | 236 | | Event Name | Callback Argument Type | 237 | | ---------- | ---------------------- | 238 | | 'change' | boolean | 239 | 240 | **Example** 241 | 242 | ```js 243 | this.$OneSignal.Notifications.addEventListener('change', (event) => { 244 | console.log('The notification was clicked!', event); 245 | }); 246 | ``` 247 | 248 | See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/docs/web-sdk-reference#addeventlistener-push-notification) for all available event listeners. 249 | 250 | --- 251 | 252 | ## 🤝 Contributing 253 | 254 | Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/OneSignal/onesignal-vue3/issues). 255 | 256 | ## Show your support 257 | 258 | Give a ⭐️ if this project helped you! 259 | 260 | ## OneSignal 261 | 262 | - [Website](https://onesignal.com) 263 | - Twitter: [@onesignal](https://twitter.com/onesignal) 264 | - Github: [@OneSignal](https://github.com/OneSignal) 265 | - LinkedIn: [@onesignal](https://linkedin.com/company/onesignal) 266 | 267 | ## Discord 268 | 269 | Reach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)! 270 | 271 | ## 📝 License 272 | 273 | Copyright © 2023 [OneSignal](https://github.com/OneSignal).
274 | This project is [Modified MIT](https://github.com/OneSignal/onesignal-vue3/blob/main/LICENSE) licensed. 275 | 276 | Enjoy! 277 | -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | import { App } from 'vue'; 2 | declare module 'vue' { 3 | interface ComponentCustomProperties { 4 | $OneSignal: IOneSignalOneSignal; 5 | } 6 | } 7 | declare global { 8 | interface Window { 9 | OneSignalDeferred?: OneSignalDeferredLoadedCallback[]; 10 | OneSignal?: IOneSignalOneSignal; 11 | safari?: { 12 | pushNotification: any; 13 | }; 14 | } 15 | } 16 | export interface AutoPromptOptions { 17 | force?: boolean; 18 | forceSlidedownOverNative?: boolean; 19 | slidedownPromptOptions?: IOneSignalAutoPromptOptions; 20 | } 21 | export interface IOneSignalAutoPromptOptions { 22 | force?: boolean; 23 | forceSlidedownOverNative?: boolean; 24 | isInUpdateMode?: boolean; 25 | categoryOptions?: IOneSignalCategories; 26 | } 27 | export interface IOneSignalCategories { 28 | positiveUpdateButton: string; 29 | negativeUpdateButton: string; 30 | savingButtonText: string; 31 | errorButtonText: string; 32 | updateMessage: string; 33 | tags: IOneSignalTagCategory[]; 34 | } 35 | export interface IOneSignalTagCategory { 36 | tag: string; 37 | label: string; 38 | checked?: boolean; 39 | } 40 | export type PushSubscriptionNamespaceProperties = { 41 | id: string | null | undefined; 42 | token: string | null | undefined; 43 | optedIn: boolean; 44 | }; 45 | export type SubscriptionChangeEvent = { 46 | previous: PushSubscriptionNamespaceProperties; 47 | current: PushSubscriptionNamespaceProperties; 48 | }; 49 | export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay'; 50 | export type SlidedownEventName = 'slidedownAllowClick' | 'slidedownCancelClick' | 'slidedownClosed' | 'slidedownQueued' | 'slidedownShown'; 51 | export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void; 52 | export interface IOSNotification { 53 | /** 54 | * The OneSignal notification id; 55 | * - Primary id on OneSignal's REST API and dashboard 56 | */ 57 | readonly notificationId: string; 58 | /** 59 | * Visible title text on the notification 60 | */ 61 | readonly title?: string; 62 | /** 63 | * Visible body text on the notification 64 | */ 65 | readonly body: string; 66 | /** 67 | * Visible icon the notification; URL format 68 | */ 69 | readonly icon?: string; 70 | /** 71 | * Visible small badgeIcon that displays on some devices; URL format 72 | * Example: On Android's status bar 73 | */ 74 | readonly badgeIcon?: string; 75 | /** 76 | * Visible image on the notification; URL format 77 | */ 78 | readonly image?: string; 79 | /** 80 | * Visible buttons on the notification 81 | */ 82 | readonly actionButtons?: IOSNotificationActionButton[]; 83 | /** 84 | * If this value is the same as existing notification, it will replace it 85 | * Can be set when creating the notification with "Web Push Topic" on the dashboard 86 | * or web_push_topic from the REST API. 87 | */ 88 | readonly topic?: string; 89 | /** 90 | * Custom object that was sent with the notification; 91 | * definable when creating the notification from the OneSignal REST API or dashboard 92 | */ 93 | readonly additionalData?: object; 94 | /** 95 | * URL to open when clicking or tapping on the notification 96 | */ 97 | readonly launchURL?: string; 98 | /** 99 | * Confirm the push was received by reporting back to OneSignal 100 | */ 101 | readonly confirmDelivery: boolean; 102 | } 103 | export interface IOSNotificationActionButton { 104 | /** 105 | * Any unique identifier to represent which button was clicked. This is typically passed back to the service worker 106 | * and host page through events to identify which button was clicked. 107 | * e.g. 'like-button' 108 | */ 109 | readonly actionId: string; 110 | /** 111 | * The notification action button's text. 112 | */ 113 | readonly text: string; 114 | /** 115 | * A valid publicly reachable HTTPS URL to an image. 116 | */ 117 | readonly icon?: string; 118 | /** 119 | * The URL to open the web browser to when this action button is clicked. 120 | */ 121 | readonly launchURL?: string; 122 | } 123 | export interface NotificationClickResult { 124 | readonly actionId?: string; 125 | readonly url?: string; 126 | } 127 | export type NotificationEventTypeMap = { 128 | 'click': NotificationClickEvent; 129 | 'foregroundWillDisplay': NotificationForegroundWillDisplayEvent; 130 | 'dismiss': NotificationDismissEvent; 131 | 'permissionChange': boolean; 132 | 'permissionPromptDisplay': void; 133 | }; 134 | export interface NotificationForegroundWillDisplayEvent { 135 | readonly notification: IOSNotification; 136 | preventDefault(): void; 137 | } 138 | export interface NotificationDismissEvent { 139 | notification: IOSNotification; 140 | } 141 | export interface NotificationClickEvent { 142 | readonly notification: IOSNotification; 143 | readonly result: NotificationClickResult; 144 | } 145 | export type UserChangeEvent = { 146 | current: UserNamespaceProperties; 147 | }; 148 | export type UserNamespaceProperties = { 149 | onesignalId: string | undefined; 150 | externalId: string | undefined; 151 | }; 152 | export interface IInitObject { 153 | appId: string; 154 | subdomainName?: string; 155 | requiresUserPrivacyConsent?: boolean; 156 | promptOptions?: { 157 | slidedown: { 158 | prompts: { 159 | /** 160 | * Whether to automatically display the prompt. 161 | * `true` will display the prompt based on the delay options. 162 | * `false` will prevent the prompt from displaying until the Slidedowns methods are used. 163 | */ 164 | autoPrompt: boolean; 165 | /** 166 | * Only available for type: category. Up to 10 categories. 167 | * @example 168 | * categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt. 169 | */ 170 | categories: { 171 | /** Should identify the action. */ 172 | tag: string; 173 | /** What the user will see. */ 174 | label: string; 175 | }[]; 176 | /** 177 | * The delay options for the prompt. 178 | * @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view. 179 | */ 180 | delay: { 181 | /** The number of pages a user needs to visit before the prompt is displayed. */ 182 | pageViews?: number; 183 | /** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */ 184 | timeDelay?: number; 185 | }; 186 | /** 187 | * The text to display in the prompt. 188 | */ 189 | text?: { 190 | /** The callout asking the user to opt-in. Up to 90 characters. */ 191 | actionMessage?: string; 192 | /** Triggers the opt-in. Up to 15 characters. */ 193 | acceptButton?: string; 194 | /** Cancels opt-in. Up to 15 characters. */ 195 | cancelMessage?: string; 196 | /** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */ 197 | confirmMessage?: string; 198 | /** Identifies the email text field. Up to 15 characters. */ 199 | emailLabel?: string; 200 | /** Cancels the category update. Up to 15 characters. */ 201 | negativeUpdateButton?: string; 202 | /** Saves the updated category tags. Up to 15 characters. */ 203 | positiveUpdateButton?: string; 204 | /** Identifies the phone number text field. Up to 15 characters. */ 205 | smsLabel?: string; 206 | /** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */ 207 | updateMessage?: string; 208 | }; 209 | /** 210 | * The type of prompt to display. 211 | * `push` which is the Slide Prompt without categories. 212 | * `category` which is the Slide Prompt with categories. 213 | * `sms` only asks for phone number. 214 | * `email` only asks for email address. 215 | * `smsAndEmail` asks for both phone number and email address. 216 | */ 217 | type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail'; 218 | }[]; 219 | }; 220 | }; 221 | welcomeNotification?: { 222 | /** 223 | * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need. 224 | * @deprecated Use 'disable' instead. This will be removed in a future version. 225 | */ 226 | disabled?: boolean; 227 | /** 228 | * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need. 229 | */ 230 | disable?: boolean; 231 | /** 232 | * The welcome notification's message. You can localize this to your own language. 233 | * If left blank or set to blank, the default of 'Thanks for subscribing!' will be used. 234 | */ 235 | message: string; 236 | /** 237 | * The welcome notification's title. You can localize this to your own language. If not set, or left blank, the site's title will be used. 238 | * Set to one space ' ' to clear the title, although this is not recommended. 239 | */ 240 | title?: string; 241 | /** 242 | * By default, clicking the welcome notification does not open any link. 243 | * This is recommended because the user has just visited your site and subscribed. 244 | */ 245 | url?: string; 246 | }; 247 | /** 248 | * Will enable customization of the notify/subscription bell button. 249 | */ 250 | notifyButton?: { 251 | /** 252 | * A function you define that returns true to show the Subscription Bell, or false to hide it. 253 | * Typically used the hide the Subscription Bell after the user is subscribed. 254 | * This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show. 255 | */ 256 | displayPredicate?: () => boolean | Promise; 257 | /** 258 | * Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default. 259 | */ 260 | enable?: boolean; 261 | /** Specify CSS-valid pixel offsets using bottom, left, and right. */ 262 | offset?: { 263 | bottom: string; 264 | left: string; 265 | right: string; 266 | }; 267 | /** 268 | * If `true`, the Subscription Bell will display an icon that there is 1 unread message. 269 | * When hovering over the Subscription Bell, the user will see custom text set by message.prenotify. 270 | */ 271 | prenotify: boolean; 272 | /** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */ 273 | position?: 'bottom-left' | 'bottom-right'; 274 | /** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */ 275 | showCredit: boolean; 276 | /** 277 | * The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes. 278 | */ 279 | size?: 'small' | 'medium' | 'large'; 280 | /** Customize the Subscription Bell text. */ 281 | text: { 282 | 'dialog.blocked.message': string; 283 | 'dialog.blocked.title': string; 284 | 'dialog.main.button.subscribe': string; 285 | 'dialog.main.button.unsubscribe': string; 286 | 'dialog.main.title': string; 287 | 'message.action.resubscribed': string; 288 | 'message.action.subscribed': string; 289 | 'message.action.subscribing': string; 290 | 'message.action.unsubscribed': string; 291 | 'message.prenotify': string; 292 | 'tip.state.blocked': string; 293 | 'tip.state.subscribed': string; 294 | 'tip.state.unsubscribed': string; 295 | }; 296 | }; 297 | persistNotification?: boolean; 298 | webhooks?: { 299 | /** 300 | * Enable this setting only if your server has CORS enabled and supports non-simple CORS requests. 301 | * If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers. 302 | * The simplest option is to leave it disabled. 303 | * @default false 304 | */ 305 | cors: boolean; 306 | /** 307 | * This event occurs after a notification is clicked. 308 | * @example https://site.com/hook 309 | */ 310 | 'notification.clicked'?: string; 311 | /** 312 | * This event occurs after a notification is intentionally dismissed by the user (clicking the notification body or one of the notification action buttons does not trigger the dismissed webhook), 313 | * after a group of notifications are all dismissed (with this notification as part of that group), or after a notification expires on its own time and disappears. This event is supported on Chrome only. 314 | * @example https://site.com/hook 315 | */ 316 | 'notification.dismissed'?: string; 317 | /** 318 | * This event occurs after a notification is displayed. 319 | * @example https://site.com/hook 320 | */ 321 | 'notification.willDisplay'?: string; 322 | }; 323 | autoResubscribe?: boolean; 324 | autoRegister?: boolean; 325 | notificationClickHandlerMatch?: string; 326 | notificationClickHandlerAction?: string; 327 | path?: string; 328 | serviceWorkerParam?: { 329 | scope: string; 330 | }; 331 | serviceWorkerPath?: string; 332 | serviceWorkerOverrideForTypical?: boolean; 333 | serviceWorkerUpdaterPath?: string; 334 | allowLocalhostAsSecureOrigin?: boolean; 335 | [key: string]: any; 336 | } 337 | export interface IOneSignalOneSignal { 338 | Slidedown: IOneSignalSlidedown; 339 | Notifications: IOneSignalNotifications; 340 | Session: IOneSignalSession; 341 | User: IOneSignalUser; 342 | Debug: IOneSignalDebug; 343 | login(externalId: string, jwtToken?: string): Promise; 344 | logout(): Promise; 345 | init(options: IInitObject): Promise; 346 | setConsentGiven(consent: boolean): Promise; 347 | setConsentRequired(requiresConsent: boolean): Promise; 348 | } 349 | export interface IOneSignalNotifications { 350 | permissionNative: NotificationPermission; 351 | permission: boolean; 352 | setDefaultUrl(url: string): Promise; 353 | setDefaultTitle(title: string): Promise; 354 | isPushSupported(): boolean; 355 | requestPermission(): Promise; 356 | addEventListener(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void; 357 | removeEventListener(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void; 358 | } 359 | export interface IOneSignalSlidedown { 360 | promptPush(options?: AutoPromptOptions): Promise; 361 | promptPushCategories(options?: AutoPromptOptions): Promise; 362 | promptSms(options?: AutoPromptOptions): Promise; 363 | promptEmail(options?: AutoPromptOptions): Promise; 364 | promptSmsAndEmail(options?: AutoPromptOptions): Promise; 365 | addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void; 366 | removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void; 367 | } 368 | export interface IOneSignalDebug { 369 | setLogLevel(logLevel: 'trace' | 'debug' | 'info' | 'warn' | 'error'): void; 370 | } 371 | export interface IOneSignalSession { 372 | sendOutcome(outcomeName: string, outcomeWeight?: number): Promise; 373 | sendUniqueOutcome(outcomeName: string): Promise; 374 | } 375 | export interface IOneSignalUser { 376 | onesignalId: string | undefined; 377 | externalId: string | undefined; 378 | PushSubscription: IOneSignalPushSubscription; 379 | addAlias(label: string, id: string): void; 380 | addAliases(aliases: { 381 | [key: string]: string; 382 | }): void; 383 | removeAlias(label: string): void; 384 | removeAliases(labels: string[]): void; 385 | addEmail(email: string): void; 386 | removeEmail(email: string): void; 387 | addSms(smsNumber: string): void; 388 | removeSms(smsNumber: string): void; 389 | addTag(key: string, value: string): void; 390 | addTags(tags: { 391 | [key: string]: string; 392 | }): void; 393 | removeTag(key: string): void; 394 | removeTags(keys: string[]): void; 395 | getTags(): { 396 | [key: string]: string; 397 | }; 398 | addEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void; 399 | removeEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void; 400 | setLanguage(language: string): void; 401 | getLanguage(): string; 402 | } 403 | export interface IOneSignalPushSubscription { 404 | id: string | null | undefined; 405 | token: string | null | undefined; 406 | optedIn: boolean | undefined; 407 | optIn(): Promise; 408 | optOut(): Promise; 409 | addEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void; 410 | removeEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void; 411 | } 412 | export declare const useOneSignal: () => IOneSignalOneSignal; 413 | declare const OneSignalVuePlugin: { 414 | install(app: App, options: IInitObject): void; 415 | }; 416 | export default OneSignalVuePlugin; 417 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 2 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | const ONESIGNAL_SDK_ID = 'onesignal-sdk'; 11 | const ONE_SIGNAL_SCRIPT_SRC = 'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js'; 12 | // true if the script is successfully loaded from CDN. 13 | let isOneSignalInitialized = false; 14 | // true if the script fails to load from CDN. A separate flag is necessary 15 | // to disambiguate between a CDN load failure and a delayed call to 16 | // OneSignal#init. 17 | let isOneSignalScriptFailed = false; 18 | if (typeof window !== 'undefined') { 19 | window.OneSignalDeferred = window.OneSignalDeferred || []; 20 | addSDKScript(); 21 | } 22 | /* H E L P E R S */ 23 | function handleOnError() { 24 | isOneSignalScriptFailed = true; 25 | } 26 | function addSDKScript() { 27 | const script = document.createElement('script'); 28 | script.id = ONESIGNAL_SDK_ID; 29 | script.defer = true; 30 | script.src = ONE_SIGNAL_SCRIPT_SRC; 31 | // Always resolve whether or not the script is successfully initialized. 32 | // This is important for users who may block cdn.onesignal.com w/ adblock. 33 | script.onerror = () => { 34 | handleOnError(); 35 | }; 36 | document.head.appendChild(script); 37 | } 38 | /* O N E S I G N A L A P I */ 39 | /** 40 | * @PublicApi 41 | */ 42 | const init = (options) => { 43 | var _a; 44 | if (isOneSignalInitialized) { 45 | return Promise.reject(`OneSignal is already initialized.`); 46 | } 47 | if (!options || !options.appId) { 48 | return Promise.reject('You need to provide your OneSignal appId.'); 49 | } 50 | if (!document) { 51 | return Promise.reject(`Document is not defined.`); 52 | } 53 | // Handle both disabled and disable keys for welcome notification 54 | if (((_a = options.welcomeNotification) === null || _a === void 0 ? void 0 : _a.disabled) !== undefined) { 55 | options.welcomeNotification.disable = options.welcomeNotification.disabled; 56 | } 57 | return new Promise((resolve, reject) => { 58 | var _a; 59 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 60 | OneSignal.init(options) 61 | .then(() => { 62 | isOneSignalInitialized = true; 63 | resolve(); 64 | }) 65 | .catch(reject); 66 | }); 67 | }); 68 | }; 69 | /** 70 | * The following code is copied directly from the native SDK source file BrowserSupportsPush.ts 71 | * S T A R T 72 | */ 73 | // Checks if the browser supports push notifications by checking if specific 74 | // classes and properties on them exist 75 | function isPushNotificationsSupported() { 76 | return supportsVapidPush() || supportsSafariPush(); 77 | } 78 | function isMacOSSafariInIframe() { 79 | // Fallback detection for Safari on macOS in an iframe context 80 | return (window.top !== window && // isContextIframe 81 | navigator.vendor === 'Apple Computer, Inc.' && // isSafari 82 | navigator.platform === 'MacIntel'); // isMacOS 83 | } 84 | function supportsSafariPush() { 85 | return ((window.safari && typeof window.safari.pushNotification !== 'undefined') || 86 | isMacOSSafariInIframe()); 87 | } 88 | // Does the browser support the standard Push API 89 | function supportsVapidPush() { 90 | return (typeof PushSubscriptionOptions !== 'undefined' && 91 | PushSubscriptionOptions.prototype.hasOwnProperty('applicationServerKey')); 92 | } 93 | /* E N D */ 94 | /** 95 | * @PublicApi 96 | */ 97 | const isPushSupported = () => { 98 | return isPushNotificationsSupported(); 99 | }; 100 | function oneSignalLogin(externalId, jwtToken) { 101 | return new Promise(function (resolve, reject) { 102 | var _a; 103 | if (isOneSignalScriptFailed) { 104 | reject(new Error('OneSignal script failed to load.')); 105 | return; 106 | } 107 | try { 108 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 109 | OneSignal.login(externalId, jwtToken).then(() => resolve()) 110 | .catch(error => reject(error)); 111 | }); 112 | } 113 | catch (error) { 114 | reject(error); 115 | } 116 | }); 117 | } 118 | function oneSignalLogout() { 119 | return new Promise(function (resolve, reject) { 120 | var _a; 121 | if (isOneSignalScriptFailed) { 122 | reject(new Error('OneSignal script failed to load.')); 123 | return; 124 | } 125 | try { 126 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 127 | OneSignal.logout().then(() => resolve()) 128 | .catch(error => reject(error)); 129 | }); 130 | } 131 | catch (error) { 132 | reject(error); 133 | } 134 | }); 135 | } 136 | function oneSignalSetConsentGiven(consent) { 137 | return new Promise(function (resolve, reject) { 138 | var _a; 139 | if (isOneSignalScriptFailed) { 140 | reject(new Error('OneSignal script failed to load.')); 141 | return; 142 | } 143 | try { 144 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 145 | OneSignal.setConsentGiven(consent).then(() => resolve()) 146 | .catch(error => reject(error)); 147 | }); 148 | } 149 | catch (error) { 150 | reject(error); 151 | } 152 | }); 153 | } 154 | function oneSignalSetConsentRequired(requiresConsent) { 155 | return new Promise(function (resolve, reject) { 156 | var _a; 157 | if (isOneSignalScriptFailed) { 158 | reject(new Error('OneSignal script failed to load.')); 159 | return; 160 | } 161 | try { 162 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 163 | OneSignal.setConsentRequired(requiresConsent).then(() => resolve()) 164 | .catch(error => reject(error)); 165 | }); 166 | } 167 | catch (error) { 168 | reject(error); 169 | } 170 | }); 171 | } 172 | function slidedownPromptPush(options) { 173 | return new Promise(function (resolve, reject) { 174 | var _a; 175 | if (isOneSignalScriptFailed) { 176 | reject(new Error('OneSignal script failed to load.')); 177 | return; 178 | } 179 | try { 180 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 181 | OneSignal.Slidedown.promptPush(options).then(() => resolve()) 182 | .catch(error => reject(error)); 183 | }); 184 | } 185 | catch (error) { 186 | reject(error); 187 | } 188 | }); 189 | } 190 | function slidedownPromptPushCategories(options) { 191 | return new Promise(function (resolve, reject) { 192 | var _a; 193 | if (isOneSignalScriptFailed) { 194 | reject(new Error('OneSignal script failed to load.')); 195 | return; 196 | } 197 | try { 198 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 199 | OneSignal.Slidedown.promptPushCategories(options).then(() => resolve()) 200 | .catch(error => reject(error)); 201 | }); 202 | } 203 | catch (error) { 204 | reject(error); 205 | } 206 | }); 207 | } 208 | function slidedownPromptSms(options) { 209 | return new Promise(function (resolve, reject) { 210 | var _a; 211 | if (isOneSignalScriptFailed) { 212 | reject(new Error('OneSignal script failed to load.')); 213 | return; 214 | } 215 | try { 216 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 217 | OneSignal.Slidedown.promptSms(options).then(() => resolve()) 218 | .catch(error => reject(error)); 219 | }); 220 | } 221 | catch (error) { 222 | reject(error); 223 | } 224 | }); 225 | } 226 | function slidedownPromptEmail(options) { 227 | return new Promise(function (resolve, reject) { 228 | var _a; 229 | if (isOneSignalScriptFailed) { 230 | reject(new Error('OneSignal script failed to load.')); 231 | return; 232 | } 233 | try { 234 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 235 | OneSignal.Slidedown.promptEmail(options).then(() => resolve()) 236 | .catch(error => reject(error)); 237 | }); 238 | } 239 | catch (error) { 240 | reject(error); 241 | } 242 | }); 243 | } 244 | function slidedownPromptSmsAndEmail(options) { 245 | return new Promise(function (resolve, reject) { 246 | var _a; 247 | if (isOneSignalScriptFailed) { 248 | reject(new Error('OneSignal script failed to load.')); 249 | return; 250 | } 251 | try { 252 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 253 | OneSignal.Slidedown.promptSmsAndEmail(options).then(() => resolve()) 254 | .catch(error => reject(error)); 255 | }); 256 | } 257 | catch (error) { 258 | reject(error); 259 | } 260 | }); 261 | } 262 | function slidedownAddEventListener(event, listener) { 263 | var _a; 264 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 265 | OneSignal.Slidedown.addEventListener(event, listener); 266 | }); 267 | } 268 | function slidedownRemoveEventListener(event, listener) { 269 | var _a; 270 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 271 | OneSignal.Slidedown.removeEventListener(event, listener); 272 | }); 273 | } 274 | function notificationsSetDefaultUrl(url) { 275 | return new Promise(function (resolve, reject) { 276 | var _a; 277 | if (isOneSignalScriptFailed) { 278 | reject(new Error('OneSignal script failed to load.')); 279 | return; 280 | } 281 | try { 282 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 283 | OneSignal.Notifications.setDefaultUrl(url).then(() => resolve()) 284 | .catch(error => reject(error)); 285 | }); 286 | } 287 | catch (error) { 288 | reject(error); 289 | } 290 | }); 291 | } 292 | function notificationsSetDefaultTitle(title) { 293 | return new Promise(function (resolve, reject) { 294 | var _a; 295 | if (isOneSignalScriptFailed) { 296 | reject(new Error('OneSignal script failed to load.')); 297 | return; 298 | } 299 | try { 300 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 301 | OneSignal.Notifications.setDefaultTitle(title).then(() => resolve()) 302 | .catch(error => reject(error)); 303 | }); 304 | } 305 | catch (error) { 306 | reject(error); 307 | } 308 | }); 309 | } 310 | function notificationsRequestPermission() { 311 | return new Promise(function (resolve, reject) { 312 | var _a; 313 | if (isOneSignalScriptFailed) { 314 | reject(new Error('OneSignal script failed to load.')); 315 | return; 316 | } 317 | try { 318 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 319 | OneSignal.Notifications.requestPermission().then(() => resolve()) 320 | .catch(error => reject(error)); 321 | }); 322 | } 323 | catch (error) { 324 | reject(error); 325 | } 326 | }); 327 | } 328 | function notificationsAddEventListener(event, listener) { 329 | var _a; 330 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 331 | OneSignal.Notifications.addEventListener(event, listener); 332 | }); 333 | } 334 | function notificationsRemoveEventListener(event, listener) { 335 | var _a; 336 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 337 | OneSignal.Notifications.removeEventListener(event, listener); 338 | }); 339 | } 340 | function sessionSendOutcome(outcomeName, outcomeWeight) { 341 | return new Promise(function (resolve, reject) { 342 | var _a; 343 | if (isOneSignalScriptFailed) { 344 | reject(new Error('OneSignal script failed to load.')); 345 | return; 346 | } 347 | try { 348 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 349 | OneSignal.Session.sendOutcome(outcomeName, outcomeWeight).then(() => resolve()) 350 | .catch(error => reject(error)); 351 | }); 352 | } 353 | catch (error) { 354 | reject(error); 355 | } 356 | }); 357 | } 358 | function sessionSendUniqueOutcome(outcomeName) { 359 | return new Promise(function (resolve, reject) { 360 | var _a; 361 | if (isOneSignalScriptFailed) { 362 | reject(new Error('OneSignal script failed to load.')); 363 | return; 364 | } 365 | try { 366 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 367 | OneSignal.Session.sendUniqueOutcome(outcomeName).then(() => resolve()) 368 | .catch(error => reject(error)); 369 | }); 370 | } 371 | catch (error) { 372 | reject(error); 373 | } 374 | }); 375 | } 376 | function userAddAlias(label, id) { 377 | var _a; 378 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 379 | OneSignal.User.addAlias(label, id); 380 | }); 381 | } 382 | function userAddAliases(aliases) { 383 | var _a; 384 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 385 | OneSignal.User.addAliases(aliases); 386 | }); 387 | } 388 | function userRemoveAlias(label) { 389 | var _a; 390 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 391 | OneSignal.User.removeAlias(label); 392 | }); 393 | } 394 | function userRemoveAliases(labels) { 395 | var _a; 396 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 397 | OneSignal.User.removeAliases(labels); 398 | }); 399 | } 400 | function userAddEmail(email) { 401 | var _a; 402 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 403 | OneSignal.User.addEmail(email); 404 | }); 405 | } 406 | function userRemoveEmail(email) { 407 | var _a; 408 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 409 | OneSignal.User.removeEmail(email); 410 | }); 411 | } 412 | function userAddSms(smsNumber) { 413 | var _a; 414 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 415 | OneSignal.User.addSms(smsNumber); 416 | }); 417 | } 418 | function userRemoveSms(smsNumber) { 419 | var _a; 420 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 421 | OneSignal.User.removeSms(smsNumber); 422 | }); 423 | } 424 | function userAddTag(key, value) { 425 | var _a; 426 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 427 | OneSignal.User.addTag(key, value); 428 | }); 429 | } 430 | function userAddTags(tags) { 431 | var _a; 432 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 433 | OneSignal.User.addTags(tags); 434 | }); 435 | } 436 | function userRemoveTag(key) { 437 | var _a; 438 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 439 | OneSignal.User.removeTag(key); 440 | }); 441 | } 442 | function userRemoveTags(keys) { 443 | var _a; 444 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 445 | OneSignal.User.removeTags(keys); 446 | }); 447 | } 448 | // @ts-expect-error - return non-Promise type despite needing to await OneSignalDeferred 449 | function userGetTags() { 450 | var _a; 451 | return __awaiter(this, void 0, void 0, function* () { 452 | let retVal; 453 | yield ((_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 454 | retVal = OneSignal.User.getTags(); 455 | })); 456 | return retVal; 457 | }); 458 | } 459 | function userAddEventListener(event, listener) { 460 | var _a; 461 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 462 | OneSignal.User.addEventListener(event, listener); 463 | }); 464 | } 465 | function userRemoveEventListener(event, listener) { 466 | var _a; 467 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 468 | OneSignal.User.removeEventListener(event, listener); 469 | }); 470 | } 471 | function userSetLanguage(language) { 472 | var _a; 473 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 474 | OneSignal.User.setLanguage(language); 475 | }); 476 | } 477 | // @ts-expect-error - return non-Promise type despite needing to await OneSignalDeferred 478 | function userGetLanguage() { 479 | var _a; 480 | return __awaiter(this, void 0, void 0, function* () { 481 | let retVal; 482 | yield ((_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 483 | retVal = OneSignal.User.getLanguage(); 484 | })); 485 | return retVal; 486 | }); 487 | } 488 | function pushSubscriptionOptIn() { 489 | return new Promise(function (resolve, reject) { 490 | var _a; 491 | if (isOneSignalScriptFailed) { 492 | reject(new Error('OneSignal script failed to load.')); 493 | return; 494 | } 495 | try { 496 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 497 | OneSignal.User.PushSubscription.optIn().then(() => resolve()) 498 | .catch(error => reject(error)); 499 | }); 500 | } 501 | catch (error) { 502 | reject(error); 503 | } 504 | }); 505 | } 506 | function pushSubscriptionOptOut() { 507 | return new Promise(function (resolve, reject) { 508 | var _a; 509 | if (isOneSignalScriptFailed) { 510 | reject(new Error('OneSignal script failed to load.')); 511 | return; 512 | } 513 | try { 514 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 515 | OneSignal.User.PushSubscription.optOut().then(() => resolve()) 516 | .catch(error => reject(error)); 517 | }); 518 | } 519 | catch (error) { 520 | reject(error); 521 | } 522 | }); 523 | } 524 | function pushSubscriptionAddEventListener(event, listener) { 525 | var _a; 526 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 527 | OneSignal.User.PushSubscription.addEventListener(event, listener); 528 | }); 529 | } 530 | function pushSubscriptionRemoveEventListener(event, listener) { 531 | var _a; 532 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 533 | OneSignal.User.PushSubscription.removeEventListener(event, listener); 534 | }); 535 | } 536 | function debugSetLogLevel(logLevel) { 537 | var _a; 538 | (_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { 539 | OneSignal.Debug.setLogLevel(logLevel); 540 | }); 541 | } 542 | const PushSubscriptionNamespace = { 543 | get id() { var _a, _b, _c; return (_c = (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.PushSubscription) === null || _c === void 0 ? void 0 : _c.id; }, 544 | get token() { var _a, _b, _c; return (_c = (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.PushSubscription) === null || _c === void 0 ? void 0 : _c.token; }, 545 | get optedIn() { var _a, _b, _c; return (_c = (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.PushSubscription) === null || _c === void 0 ? void 0 : _c.optedIn; }, 546 | optIn: pushSubscriptionOptIn, 547 | optOut: pushSubscriptionOptOut, 548 | addEventListener: pushSubscriptionAddEventListener, 549 | removeEventListener: pushSubscriptionRemoveEventListener, 550 | }; 551 | const UserNamespace = { 552 | get onesignalId() { var _a, _b; return (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.onesignalId; }, 553 | get externalId() { var _a, _b; return (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.User) === null || _b === void 0 ? void 0 : _b.externalId; }, 554 | addAlias: userAddAlias, 555 | addAliases: userAddAliases, 556 | removeAlias: userRemoveAlias, 557 | removeAliases: userRemoveAliases, 558 | addEmail: userAddEmail, 559 | removeEmail: userRemoveEmail, 560 | addSms: userAddSms, 561 | removeSms: userRemoveSms, 562 | addTag: userAddTag, 563 | addTags: userAddTags, 564 | removeTag: userRemoveTag, 565 | removeTags: userRemoveTags, 566 | getTags: userGetTags, 567 | addEventListener: userAddEventListener, 568 | removeEventListener: userRemoveEventListener, 569 | setLanguage: userSetLanguage, 570 | getLanguage: userGetLanguage, 571 | PushSubscription: PushSubscriptionNamespace, 572 | }; 573 | const SessionNamespace = { 574 | sendOutcome: sessionSendOutcome, 575 | sendUniqueOutcome: sessionSendUniqueOutcome, 576 | }; 577 | const DebugNamespace = { 578 | setLogLevel: debugSetLogLevel, 579 | }; 580 | const SlidedownNamespace = { 581 | promptPush: slidedownPromptPush, 582 | promptPushCategories: slidedownPromptPushCategories, 583 | promptSms: slidedownPromptSms, 584 | promptEmail: slidedownPromptEmail, 585 | promptSmsAndEmail: slidedownPromptSmsAndEmail, 586 | addEventListener: slidedownAddEventListener, 587 | removeEventListener: slidedownRemoveEventListener, 588 | }; 589 | const NotificationsNamespace = { 590 | get permissionNative() { var _a, _b, _c; return (_c = (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.Notifications) === null || _b === void 0 ? void 0 : _b.permissionNative) !== null && _c !== void 0 ? _c : 'default'; }, 591 | get permission() { var _a, _b, _c; return (_c = (_b = (_a = window.OneSignal) === null || _a === void 0 ? void 0 : _a.Notifications) === null || _b === void 0 ? void 0 : _b.permission) !== null && _c !== void 0 ? _c : false; }, 592 | setDefaultUrl: notificationsSetDefaultUrl, 593 | setDefaultTitle: notificationsSetDefaultTitle, 594 | isPushSupported, 595 | requestPermission: notificationsRequestPermission, 596 | addEventListener: notificationsAddEventListener, 597 | removeEventListener: notificationsRemoveEventListener, 598 | }; 599 | const OneSignalNamespace = { 600 | login: oneSignalLogin, 601 | logout: oneSignalLogout, 602 | init, 603 | setConsentGiven: oneSignalSetConsentGiven, 604 | setConsentRequired: oneSignalSetConsentRequired, 605 | Slidedown: SlidedownNamespace, 606 | Notifications: NotificationsNamespace, 607 | Session: SessionNamespace, 608 | User: UserNamespace, 609 | Debug: DebugNamespace, 610 | }; 611 | export const useOneSignal = () => { 612 | return OneSignalNamespace; 613 | }; 614 | const OneSignalVuePlugin = { 615 | install(app, options) { 616 | app.config.globalProperties.$OneSignal = 617 | OneSignalNamespace; 618 | app.config.globalProperties.$OneSignal.init(options); 619 | }, 620 | }; 621 | export default OneSignalVuePlugin; 622 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;AAEA,MAAM,gBAAgB,GAAG,eAAe,CAAC;AACzC,MAAM,qBAAqB,GACzB,6DAA6D,CAAC;AAEhE,sDAAsD;AACtD,IAAI,sBAAsB,GAAG,KAAK,CAAC;AACnC,0EAA0E;AAC1E,mEAAmE;AACnE,kBAAkB;AAClB,IAAI,uBAAuB,GAAG,KAAK,CAAC;AAEpC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,iBAAiB,GAAG,MAAM,C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C;AAEF,MAAM,kBAAkB,GAAG;IACzB,OAAO,CAAC,GAAQ,EAAE,OAAoB;QACpC,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU;YACpC,kBAAyC,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC"} -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example-vue3 2 | 3 | ## Project setup 4 | 5 | ``` 6 | npm install 7 | ``` 8 | 9 | ### Compiles and hot-reloads for development 10 | 11 | ``` 12 | npm run serve 13 | ``` 14 | 15 | ### Compiles and minifies for production 16 | 17 | ``` 18 | npm run build 19 | ``` 20 | 21 | ### Lints and fixes files 22 | 23 | ``` 24 | npm run lint 25 | ``` 26 | 27 | ### Customize configuration 28 | 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-vue3", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "@onesignal/onesignal-vue3": "^1.0.0", 12 | "core-js": "^3.6.5", 13 | "vue": "^3.0.0" 14 | }, 15 | "devDependencies": { 16 | "@vue/cli-plugin-babel": "~4.5.13", 17 | "@vue/cli-plugin-eslint": "~4.5.13", 18 | "@vue/cli-service": "~4.5.13", 19 | "@vue/compiler-sfc": "^3.0.0", 20 | "babel-eslint": "^10.1.0", 21 | "eslint": "^6.7.2", 22 | "eslint-plugin-vue": "^7.0.0" 23 | }, 24 | "eslintConfig": { 25 | "root": true, 26 | "env": { 27 | "node": true 28 | }, 29 | "extends": [ 30 | "plugin:vue/vue3-essential", 31 | "eslint:recommended" 32 | ], 33 | "parserOptions": { 34 | "parser": "babel-eslint" 35 | }, 36 | "rules": {} 37 | }, 38 | "browserslist": [ 39 | "> 1%", 40 | "last 2 versions", 41 | "not dead" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /example/public/OneSignalSDKWorker.js: -------------------------------------------------------------------------------- 1 | importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js"); 2 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneSignal/onesignal-vue3/8d6196b7884a287aab8b3f0292f60c4188ae73e9/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/src/App.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 40 | 41 | 51 | -------------------------------------------------------------------------------- /example/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OneSignal/onesignal-vue3/8d6196b7884a287aab8b3f0292f60c4188ae73e9/example/src/assets/logo.png -------------------------------------------------------------------------------- /example/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 42 | 43 | 44 | 60 | -------------------------------------------------------------------------------- /example/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | import OneSignalVuePlugin from '@onesignal/onesignal-vue3' 4 | 5 | createApp(App).use(OneSignalVuePlugin, { 6 | appId: "68e76706-41e1-4990-925b-8304c9a5deed", 7 | allowLocalhostAsSecureOrigin: true 8 | }).mount('#app') 9 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import { App } from 'vue'; 2 | 3 | const ONESIGNAL_SDK_ID = 'onesignal-sdk'; 4 | const ONE_SIGNAL_SCRIPT_SRC = 5 | 'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js'; 6 | 7 | // true if the script is successfully loaded from CDN. 8 | let isOneSignalInitialized = false; 9 | // true if the script fails to load from CDN. A separate flag is necessary 10 | // to disambiguate between a CDN load failure and a delayed call to 11 | // OneSignal#init. 12 | let isOneSignalScriptFailed = false; 13 | 14 | if (typeof window !== 'undefined') { 15 | window.OneSignalDeferred = window.OneSignalDeferred || []; 16 | addSDKScript(); 17 | } 18 | 19 | /* H E L P E R S */ 20 | 21 | function handleOnError() { 22 | isOneSignalScriptFailed = true; 23 | } 24 | 25 | function addSDKScript() { 26 | const script = document.createElement('script'); 27 | script.id = ONESIGNAL_SDK_ID; 28 | script.defer = true; 29 | script.src = ONE_SIGNAL_SCRIPT_SRC; 30 | 31 | // Always resolve whether or not the script is successfully initialized. 32 | // This is important for users who may block cdn.onesignal.com w/ adblock. 33 | script.onerror = () => { 34 | handleOnError(); 35 | }; 36 | 37 | document.head.appendChild(script); 38 | } 39 | /* T Y P E D E C L A R A T I O N S */ 40 | 41 | declare module 'vue' { 42 | export interface ComponentCustomProperties { 43 | $OneSignal: IOneSignalOneSignal; 44 | } 45 | } 46 | 47 | declare global { 48 | interface Window { 49 | OneSignalDeferred?: OneSignalDeferredLoadedCallback[]; 50 | OneSignal?: IOneSignalOneSignal; 51 | safari?: { 52 | pushNotification: any; 53 | }; 54 | } 55 | } 56 | 57 | /* O N E S I G N A L A P I */ 58 | 59 | /** 60 | * @PublicApi 61 | */ 62 | const init = (options: IInitObject): Promise => { 63 | if (isOneSignalInitialized) { 64 | return Promise.reject(`OneSignal is already initialized.`); 65 | } 66 | 67 | if (!options || !options.appId) { 68 | return Promise.reject('You need to provide your OneSignal appId.'); 69 | } 70 | 71 | if (!document) { 72 | return Promise.reject(`Document is not defined.`); 73 | } 74 | 75 | // Handle both disabled and disable keys for welcome notification 76 | if (options.welcomeNotification?.disabled !== undefined) { 77 | options.welcomeNotification.disable = options.welcomeNotification.disabled; 78 | } 79 | 80 | return new Promise((resolve, reject) => { 81 | window.OneSignalDeferred?.push((OneSignal) => { 82 | OneSignal.init(options) 83 | .then(() => { 84 | isOneSignalInitialized = true; 85 | resolve(); 86 | }) 87 | .catch(reject); 88 | }); 89 | }); 90 | }; 91 | 92 | /** 93 | * The following code is copied directly from the native SDK source file BrowserSupportsPush.ts 94 | * S T A R T 95 | */ 96 | 97 | // Checks if the browser supports push notifications by checking if specific 98 | // classes and properties on them exist 99 | function isPushNotificationsSupported() { 100 | return supportsVapidPush() || supportsSafariPush(); 101 | } 102 | 103 | function isMacOSSafariInIframe(): boolean { 104 | // Fallback detection for Safari on macOS in an iframe context 105 | return ( 106 | window.top !== window && // isContextIframe 107 | navigator.vendor === 'Apple Computer, Inc.' && // isSafari 108 | navigator.platform === 'MacIntel' 109 | ); // isMacOS 110 | } 111 | 112 | function supportsSafariPush(): boolean { 113 | return ( 114 | (window.safari && typeof window.safari.pushNotification !== 'undefined') || 115 | isMacOSSafariInIframe() 116 | ); 117 | } 118 | 119 | // Does the browser support the standard Push API 120 | function supportsVapidPush(): boolean { 121 | return ( 122 | typeof PushSubscriptionOptions !== 'undefined' && 123 | PushSubscriptionOptions.prototype.hasOwnProperty('applicationServerKey') 124 | ); 125 | } 126 | /* E N D */ 127 | 128 | /** 129 | * @PublicApi 130 | */ 131 | const isPushSupported = (): boolean => { 132 | return isPushNotificationsSupported(); 133 | }; 134 | 135 | export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; } 136 | export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; } 137 | export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; } 138 | export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; } 139 | export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; }; 140 | export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; }; 141 | export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay'; 142 | export type SlidedownEventName = 'slidedownAllowClick' | 'slidedownCancelClick' | 'slidedownClosed' | 'slidedownQueued' | 'slidedownShown'; 143 | export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void; 144 | export interface IOSNotification { 145 | /** 146 | * The OneSignal notification id; 147 | * - Primary id on OneSignal's REST API and dashboard 148 | */ 149 | readonly notificationId: string; 150 | 151 | /** 152 | * Visible title text on the notification 153 | */ 154 | readonly title?: string; 155 | 156 | /** 157 | * Visible body text on the notification 158 | */ 159 | readonly body: string; 160 | 161 | /** 162 | * Visible icon the notification; URL format 163 | */ 164 | readonly icon?: string; 165 | 166 | /** 167 | * Visible small badgeIcon that displays on some devices; URL format 168 | * Example: On Android's status bar 169 | */ 170 | readonly badgeIcon?: string; 171 | 172 | /** 173 | * Visible image on the notification; URL format 174 | */ 175 | readonly image?: string; 176 | 177 | /** 178 | * Visible buttons on the notification 179 | */ 180 | readonly actionButtons?: IOSNotificationActionButton[]; 181 | 182 | /** 183 | * If this value is the same as existing notification, it will replace it 184 | * Can be set when creating the notification with "Web Push Topic" on the dashboard 185 | * or web_push_topic from the REST API. 186 | */ 187 | readonly topic?: string; 188 | 189 | /** 190 | * Custom object that was sent with the notification; 191 | * definable when creating the notification from the OneSignal REST API or dashboard 192 | */ 193 | readonly additionalData?: object; 194 | 195 | /** 196 | * URL to open when clicking or tapping on the notification 197 | */ 198 | readonly launchURL?: string; 199 | 200 | /** 201 | * Confirm the push was received by reporting back to OneSignal 202 | */ 203 | readonly confirmDelivery: boolean; 204 | } 205 | 206 | export interface IOSNotificationActionButton { 207 | /** 208 | * Any unique identifier to represent which button was clicked. This is typically passed back to the service worker 209 | * and host page through events to identify which button was clicked. 210 | * e.g. 'like-button' 211 | */ 212 | readonly actionId: string; 213 | /** 214 | * The notification action button's text. 215 | */ 216 | readonly text: string; 217 | /** 218 | * A valid publicly reachable HTTPS URL to an image. 219 | */ 220 | readonly icon?: string; 221 | /** 222 | * The URL to open the web browser to when this action button is clicked. 223 | */ 224 | readonly launchURL?: string; 225 | } 226 | 227 | export interface NotificationClickResult { 228 | readonly actionId?: string; 229 | readonly url?: string; 230 | } 231 | 232 | export type NotificationEventTypeMap = { 233 | 'click': NotificationClickEvent; 234 | 'foregroundWillDisplay': NotificationForegroundWillDisplayEvent; 235 | 'dismiss': NotificationDismissEvent; 236 | 'permissionChange': boolean; 237 | 'permissionPromptDisplay': void; 238 | }; 239 | 240 | export interface NotificationForegroundWillDisplayEvent { 241 | readonly notification: IOSNotification; 242 | preventDefault(): void; 243 | } 244 | 245 | export interface NotificationDismissEvent { 246 | notification: IOSNotification; 247 | } 248 | 249 | export interface NotificationClickEvent { 250 | readonly notification: IOSNotification; 251 | readonly result: NotificationClickResult; 252 | } 253 | 254 | export type UserChangeEvent = { 255 | current: UserNamespaceProperties; 256 | }; 257 | export type UserNamespaceProperties = { 258 | onesignalId: string | undefined; 259 | externalId: string | undefined; 260 | }; 261 | 262 | export interface IInitObject { 263 | appId: string; 264 | subdomainName?: string; 265 | requiresUserPrivacyConsent?: boolean; 266 | promptOptions?: { 267 | slidedown: { 268 | prompts: { 269 | /** 270 | * Whether to automatically display the prompt. 271 | * `true` will display the prompt based on the delay options. 272 | * `false` will prevent the prompt from displaying until the Slidedowns methods are used. 273 | */ 274 | autoPrompt: boolean; 275 | 276 | /** 277 | * Only available for type: category. Up to 10 categories. 278 | * @example 279 | * categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt. 280 | */ 281 | categories: { 282 | /** Should identify the action. */ 283 | tag: string; 284 | 285 | /** What the user will see. */ 286 | label: string; 287 | }[]; 288 | 289 | /** 290 | * The delay options for the prompt. 291 | * @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view. 292 | */ 293 | delay: { 294 | /** The number of pages a user needs to visit before the prompt is displayed. */ 295 | pageViews?: number; 296 | 297 | /** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */ 298 | timeDelay?: number; 299 | }; 300 | 301 | /** 302 | * The text to display in the prompt. 303 | */ 304 | text?: { 305 | /** The callout asking the user to opt-in. Up to 90 characters. */ 306 | actionMessage?: string; 307 | 308 | /** Triggers the opt-in. Up to 15 characters. */ 309 | acceptButton?: string; 310 | 311 | /** Cancels opt-in. Up to 15 characters. */ 312 | cancelMessage?: string; 313 | 314 | /** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */ 315 | confirmMessage?: string; 316 | 317 | /** Identifies the email text field. Up to 15 characters. */ 318 | emailLabel?: string; 319 | 320 | /** Cancels the category update. Up to 15 characters. */ 321 | negativeUpdateButton?: string; 322 | 323 | /** Saves the updated category tags. Up to 15 characters. */ 324 | positiveUpdateButton?: string; 325 | 326 | /** Identifies the phone number text field. Up to 15 characters. */ 327 | smsLabel?: string; 328 | 329 | /** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */ 330 | updateMessage?: string; 331 | }; 332 | 333 | /** 334 | * The type of prompt to display. 335 | * `push` which is the Slide Prompt without categories. 336 | * `category` which is the Slide Prompt with categories. 337 | * `sms` only asks for phone number. 338 | * `email` only asks for email address. 339 | * `smsAndEmail` asks for both phone number and email address. 340 | */ 341 | type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail'; 342 | }[]; 343 | }; 344 | }; 345 | welcomeNotification?: { 346 | /** 347 | * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need. 348 | * @deprecated Use 'disable' instead. This will be removed in a future version. 349 | */ 350 | disabled?: boolean; 351 | 352 | /** 353 | * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need. 354 | */ 355 | disable?: boolean; 356 | 357 | /** 358 | * The welcome notification's message. You can localize this to your own language. 359 | * If left blank or set to blank, the default of 'Thanks for subscribing!' will be used. 360 | */ 361 | message: string; 362 | 363 | /** 364 | * The welcome notification's title. You can localize this to your own language. If not set, or left blank, the site's title will be used. 365 | * Set to one space ' ' to clear the title, although this is not recommended. 366 | */ 367 | title?: string; 368 | 369 | /** 370 | * By default, clicking the welcome notification does not open any link. 371 | * This is recommended because the user has just visited your site and subscribed. 372 | */ 373 | url?: string; 374 | }; 375 | 376 | /** 377 | * Will enable customization of the notify/subscription bell button. 378 | */ 379 | notifyButton?: { 380 | /** 381 | * A function you define that returns true to show the Subscription Bell, or false to hide it. 382 | * Typically used the hide the Subscription Bell after the user is subscribed. 383 | * This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show. 384 | */ 385 | displayPredicate?: () => boolean | Promise; 386 | 387 | /** 388 | * Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default. 389 | */ 390 | enable?: boolean; 391 | 392 | /** Specify CSS-valid pixel offsets using bottom, left, and right. */ 393 | offset?: { bottom: string; left: string; right: string }; 394 | 395 | /** 396 | * If `true`, the Subscription Bell will display an icon that there is 1 unread message. 397 | * When hovering over the Subscription Bell, the user will see custom text set by message.prenotify. 398 | */ 399 | prenotify: boolean; 400 | 401 | /** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */ 402 | position?: 'bottom-left' | 'bottom-right'; 403 | 404 | /** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */ 405 | showCredit: boolean; 406 | 407 | /** 408 | * The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes. 409 | */ 410 | size?: 'small' | 'medium' | 'large'; 411 | 412 | /** Customize the Subscription Bell text. */ 413 | text: { 414 | 'dialog.blocked.message': string; 415 | 'dialog.blocked.title': string; 416 | 'dialog.main.button.subscribe': string; 417 | 'dialog.main.button.unsubscribe': string; 418 | 'dialog.main.title': string; 419 | 'message.action.resubscribed': string; 420 | 'message.action.subscribed': string; 421 | 'message.action.subscribing': string; 422 | 'message.action.unsubscribed': string; 423 | 'message.prenotify': string; 424 | 'tip.state.blocked': string; 425 | 'tip.state.subscribed': string; 426 | 'tip.state.unsubscribed': string; 427 | }; 428 | }; 429 | 430 | persistNotification?: boolean; 431 | webhooks?: { 432 | /** 433 | * Enable this setting only if your server has CORS enabled and supports non-simple CORS requests. 434 | * If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers. 435 | * The simplest option is to leave it disabled. 436 | * @default false 437 | */ 438 | cors: boolean; 439 | 440 | /** 441 | * This event occurs after a notification is clicked. 442 | * @example https://site.com/hook 443 | */ 444 | 'notification.clicked'?: string; 445 | 446 | /** 447 | * This event occurs after a notification is intentionally dismissed by the user (clicking the notification body or one of the notification action buttons does not trigger the dismissed webhook), 448 | * after a group of notifications are all dismissed (with this notification as part of that group), or after a notification expires on its own time and disappears. This event is supported on Chrome only. 449 | * @example https://site.com/hook 450 | */ 451 | 'notification.dismissed'?: string; 452 | 453 | /** 454 | * This event occurs after a notification is displayed. 455 | * @example https://site.com/hook 456 | */ 457 | 'notification.willDisplay'?: string; 458 | }; 459 | autoResubscribe?: boolean; 460 | autoRegister?: boolean; 461 | notificationClickHandlerMatch?: string; 462 | notificationClickHandlerAction?: string; 463 | path?: string; 464 | serviceWorkerParam?: { scope: string }; 465 | serviceWorkerPath?: string; 466 | serviceWorkerOverrideForTypical?: boolean; 467 | serviceWorkerUpdaterPath?: string; 468 | allowLocalhostAsSecureOrigin?: boolean; 469 | [key: string]: any; 470 | } 471 | 472 | export interface IOneSignalOneSignal { 473 | Slidedown: IOneSignalSlidedown; 474 | Notifications: IOneSignalNotifications; 475 | Session: IOneSignalSession; 476 | User: IOneSignalUser; 477 | Debug: IOneSignalDebug; 478 | login(externalId: string, jwtToken?: string): Promise; 479 | logout(): Promise; 480 | init(options: IInitObject): Promise; 481 | setConsentGiven(consent: boolean): Promise; 482 | setConsentRequired(requiresConsent: boolean): Promise; 483 | } 484 | export interface IOneSignalNotifications { 485 | permissionNative: NotificationPermission; 486 | permission: boolean; 487 | setDefaultUrl(url: string): Promise; 488 | setDefaultTitle(title: string): Promise; 489 | isPushSupported(): boolean; 490 | requestPermission(): Promise; 491 | addEventListener(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void; 492 | removeEventListener(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void; 493 | } 494 | export interface IOneSignalSlidedown { 495 | promptPush(options?: AutoPromptOptions): Promise; 496 | promptPushCategories(options?: AutoPromptOptions): Promise; 497 | promptSms(options?: AutoPromptOptions): Promise; 498 | promptEmail(options?: AutoPromptOptions): Promise; 499 | promptSmsAndEmail(options?: AutoPromptOptions): Promise; 500 | addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void; 501 | removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void; 502 | } 503 | export interface IOneSignalDebug { 504 | setLogLevel(logLevel: 'trace' | 'debug' | 'info' | 'warn' | 'error'): void; 505 | } 506 | export interface IOneSignalSession { 507 | sendOutcome(outcomeName: string, outcomeWeight?: number): Promise; 508 | sendUniqueOutcome(outcomeName: string): Promise; 509 | } 510 | export interface IOneSignalUser { 511 | onesignalId: string | undefined; 512 | externalId: string | undefined; 513 | PushSubscription: IOneSignalPushSubscription; 514 | addAlias(label: string, id: string): void; 515 | addAliases(aliases: { [key: string]: string }): void; 516 | removeAlias(label: string): void; 517 | removeAliases(labels: string[]): void; 518 | addEmail(email: string): void; 519 | removeEmail(email: string): void; 520 | addSms(smsNumber: string): void; 521 | removeSms(smsNumber: string): void; 522 | addTag(key: string, value: string): void; 523 | addTags(tags: { [key: string]: string }): void; 524 | removeTag(key: string): void; 525 | removeTags(keys: string[]): void; 526 | getTags(): { [key: string]: string }; 527 | addEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void; 528 | removeEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void; 529 | setLanguage(language: string): void; 530 | getLanguage(): string; 531 | } 532 | export interface IOneSignalPushSubscription { 533 | id: string | null | undefined; 534 | token: string | null | undefined; 535 | optedIn: boolean | undefined; 536 | optIn(): Promise; 537 | optOut(): Promise; 538 | addEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void; 539 | removeEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void; 540 | } 541 | function oneSignalLogin(externalId: string, jwtToken?: string): Promise { 542 | return new Promise(function (resolve, reject) { 543 | if (isOneSignalScriptFailed) { 544 | reject(new Error('OneSignal script failed to load.')); 545 | return; 546 | } 547 | 548 | try { 549 | window.OneSignalDeferred?.push((OneSignal) => { 550 | OneSignal.login(externalId, jwtToken).then(() => resolve()) 551 | .catch(error => reject(error)); 552 | }); 553 | } catch (error) { 554 | reject(error); 555 | } 556 | }); 557 | } 558 | function oneSignalLogout(): Promise { 559 | return new Promise(function (resolve, reject) { 560 | if (isOneSignalScriptFailed) { 561 | reject(new Error('OneSignal script failed to load.')); 562 | return; 563 | } 564 | 565 | try { 566 | window.OneSignalDeferred?.push((OneSignal) => { 567 | OneSignal.logout().then(() => resolve()) 568 | .catch(error => reject(error)); 569 | }); 570 | } catch (error) { 571 | reject(error); 572 | } 573 | }); 574 | } 575 | function oneSignalSetConsentGiven(consent: boolean): Promise { 576 | return new Promise(function (resolve, reject) { 577 | if (isOneSignalScriptFailed) { 578 | reject(new Error('OneSignal script failed to load.')); 579 | return; 580 | } 581 | 582 | try { 583 | window.OneSignalDeferred?.push((OneSignal) => { 584 | OneSignal.setConsentGiven(consent).then(() => resolve()) 585 | .catch(error => reject(error)); 586 | }); 587 | } catch (error) { 588 | reject(error); 589 | } 590 | }); 591 | } 592 | function oneSignalSetConsentRequired(requiresConsent: boolean): Promise { 593 | return new Promise(function (resolve, reject) { 594 | if (isOneSignalScriptFailed) { 595 | reject(new Error('OneSignal script failed to load.')); 596 | return; 597 | } 598 | 599 | try { 600 | window.OneSignalDeferred?.push((OneSignal) => { 601 | OneSignal.setConsentRequired(requiresConsent).then(() => resolve()) 602 | .catch(error => reject(error)); 603 | }); 604 | } catch (error) { 605 | reject(error); 606 | } 607 | }); 608 | } 609 | function slidedownPromptPush(options?: AutoPromptOptions): Promise { 610 | return new Promise(function (resolve, reject) { 611 | if (isOneSignalScriptFailed) { 612 | reject(new Error('OneSignal script failed to load.')); 613 | return; 614 | } 615 | 616 | try { 617 | window.OneSignalDeferred?.push((OneSignal) => { 618 | OneSignal.Slidedown.promptPush(options).then(() => resolve()) 619 | .catch(error => reject(error)); 620 | }); 621 | } catch (error) { 622 | reject(error); 623 | } 624 | }); 625 | } 626 | function slidedownPromptPushCategories(options?: AutoPromptOptions): Promise { 627 | return new Promise(function (resolve, reject) { 628 | if (isOneSignalScriptFailed) { 629 | reject(new Error('OneSignal script failed to load.')); 630 | return; 631 | } 632 | 633 | try { 634 | window.OneSignalDeferred?.push((OneSignal) => { 635 | OneSignal.Slidedown.promptPushCategories(options).then(() => resolve()) 636 | .catch(error => reject(error)); 637 | }); 638 | } catch (error) { 639 | reject(error); 640 | } 641 | }); 642 | } 643 | function slidedownPromptSms(options?: AutoPromptOptions): Promise { 644 | return new Promise(function (resolve, reject) { 645 | if (isOneSignalScriptFailed) { 646 | reject(new Error('OneSignal script failed to load.')); 647 | return; 648 | } 649 | 650 | try { 651 | window.OneSignalDeferred?.push((OneSignal) => { 652 | OneSignal.Slidedown.promptSms(options).then(() => resolve()) 653 | .catch(error => reject(error)); 654 | }); 655 | } catch (error) { 656 | reject(error); 657 | } 658 | }); 659 | } 660 | function slidedownPromptEmail(options?: AutoPromptOptions): Promise { 661 | return new Promise(function (resolve, reject) { 662 | if (isOneSignalScriptFailed) { 663 | reject(new Error('OneSignal script failed to load.')); 664 | return; 665 | } 666 | 667 | try { 668 | window.OneSignalDeferred?.push((OneSignal) => { 669 | OneSignal.Slidedown.promptEmail(options).then(() => resolve()) 670 | .catch(error => reject(error)); 671 | }); 672 | } catch (error) { 673 | reject(error); 674 | } 675 | }); 676 | } 677 | function slidedownPromptSmsAndEmail(options?: AutoPromptOptions): Promise { 678 | return new Promise(function (resolve, reject) { 679 | if (isOneSignalScriptFailed) { 680 | reject(new Error('OneSignal script failed to load.')); 681 | return; 682 | } 683 | 684 | try { 685 | window.OneSignalDeferred?.push((OneSignal) => { 686 | OneSignal.Slidedown.promptSmsAndEmail(options).then(() => resolve()) 687 | .catch(error => reject(error)); 688 | }); 689 | } catch (error) { 690 | reject(error); 691 | } 692 | }); 693 | } 694 | function slidedownAddEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void { 695 | 696 | window.OneSignalDeferred?.push((OneSignal) => { 697 | OneSignal.Slidedown.addEventListener(event, listener); 698 | }); 699 | 700 | } 701 | function slidedownRemoveEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void { 702 | 703 | window.OneSignalDeferred?.push((OneSignal) => { 704 | OneSignal.Slidedown.removeEventListener(event, listener); 705 | }); 706 | 707 | } 708 | function notificationsSetDefaultUrl(url: string): Promise { 709 | return new Promise(function (resolve, reject) { 710 | if (isOneSignalScriptFailed) { 711 | reject(new Error('OneSignal script failed to load.')); 712 | return; 713 | } 714 | 715 | try { 716 | window.OneSignalDeferred?.push((OneSignal) => { 717 | OneSignal.Notifications.setDefaultUrl(url).then(() => resolve()) 718 | .catch(error => reject(error)); 719 | }); 720 | } catch (error) { 721 | reject(error); 722 | } 723 | }); 724 | } 725 | function notificationsSetDefaultTitle(title: string): Promise { 726 | return new Promise(function (resolve, reject) { 727 | if (isOneSignalScriptFailed) { 728 | reject(new Error('OneSignal script failed to load.')); 729 | return; 730 | } 731 | 732 | try { 733 | window.OneSignalDeferred?.push((OneSignal) => { 734 | OneSignal.Notifications.setDefaultTitle(title).then(() => resolve()) 735 | .catch(error => reject(error)); 736 | }); 737 | } catch (error) { 738 | reject(error); 739 | } 740 | }); 741 | } 742 | function notificationsRequestPermission(): Promise { 743 | return new Promise(function (resolve, reject) { 744 | if (isOneSignalScriptFailed) { 745 | reject(new Error('OneSignal script failed to load.')); 746 | return; 747 | } 748 | 749 | try { 750 | window.OneSignalDeferred?.push((OneSignal) => { 751 | OneSignal.Notifications.requestPermission().then(() => resolve()) 752 | .catch(error => reject(error)); 753 | }); 754 | } catch (error) { 755 | reject(error); 756 | } 757 | }); 758 | } 759 | function notificationsAddEventListener(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void { 760 | 761 | window.OneSignalDeferred?.push((OneSignal) => { 762 | OneSignal.Notifications.addEventListener(event, listener); 763 | }); 764 | 765 | } 766 | function notificationsRemoveEventListener(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void { 767 | 768 | window.OneSignalDeferred?.push((OneSignal) => { 769 | OneSignal.Notifications.removeEventListener(event, listener); 770 | }); 771 | 772 | } 773 | function sessionSendOutcome(outcomeName: string, outcomeWeight?: number): Promise { 774 | return new Promise(function (resolve, reject) { 775 | if (isOneSignalScriptFailed) { 776 | reject(new Error('OneSignal script failed to load.')); 777 | return; 778 | } 779 | 780 | try { 781 | window.OneSignalDeferred?.push((OneSignal) => { 782 | OneSignal.Session.sendOutcome(outcomeName, outcomeWeight).then(() => resolve()) 783 | .catch(error => reject(error)); 784 | }); 785 | } catch (error) { 786 | reject(error); 787 | } 788 | }); 789 | } 790 | function sessionSendUniqueOutcome(outcomeName: string): Promise { 791 | return new Promise(function (resolve, reject) { 792 | if (isOneSignalScriptFailed) { 793 | reject(new Error('OneSignal script failed to load.')); 794 | return; 795 | } 796 | 797 | try { 798 | window.OneSignalDeferred?.push((OneSignal) => { 799 | OneSignal.Session.sendUniqueOutcome(outcomeName).then(() => resolve()) 800 | .catch(error => reject(error)); 801 | }); 802 | } catch (error) { 803 | reject(error); 804 | } 805 | }); 806 | } 807 | function userAddAlias(label: string, id: string): void { 808 | 809 | window.OneSignalDeferred?.push((OneSignal) => { 810 | OneSignal.User.addAlias(label, id); 811 | }); 812 | 813 | } 814 | function userAddAliases(aliases: { [key: string]: string }): void { 815 | 816 | window.OneSignalDeferred?.push((OneSignal) => { 817 | OneSignal.User.addAliases(aliases); 818 | }); 819 | 820 | } 821 | function userRemoveAlias(label: string): void { 822 | 823 | window.OneSignalDeferred?.push((OneSignal) => { 824 | OneSignal.User.removeAlias(label); 825 | }); 826 | 827 | } 828 | function userRemoveAliases(labels: string[]): void { 829 | 830 | window.OneSignalDeferred?.push((OneSignal) => { 831 | OneSignal.User.removeAliases(labels); 832 | }); 833 | 834 | } 835 | function userAddEmail(email: string): void { 836 | 837 | window.OneSignalDeferred?.push((OneSignal) => { 838 | OneSignal.User.addEmail(email); 839 | }); 840 | 841 | } 842 | function userRemoveEmail(email: string): void { 843 | 844 | window.OneSignalDeferred?.push((OneSignal) => { 845 | OneSignal.User.removeEmail(email); 846 | }); 847 | 848 | } 849 | function userAddSms(smsNumber: string): void { 850 | 851 | window.OneSignalDeferred?.push((OneSignal) => { 852 | OneSignal.User.addSms(smsNumber); 853 | }); 854 | 855 | } 856 | function userRemoveSms(smsNumber: string): void { 857 | 858 | window.OneSignalDeferred?.push((OneSignal) => { 859 | OneSignal.User.removeSms(smsNumber); 860 | }); 861 | 862 | } 863 | function userAddTag(key: string, value: string): void { 864 | 865 | window.OneSignalDeferred?.push((OneSignal) => { 866 | OneSignal.User.addTag(key, value); 867 | }); 868 | 869 | } 870 | function userAddTags(tags: { [key: string]: string }): void { 871 | 872 | window.OneSignalDeferred?.push((OneSignal) => { 873 | OneSignal.User.addTags(tags); 874 | }); 875 | 876 | } 877 | function userRemoveTag(key: string): void { 878 | 879 | window.OneSignalDeferred?.push((OneSignal) => { 880 | OneSignal.User.removeTag(key); 881 | }); 882 | 883 | } 884 | function userRemoveTags(keys: string[]): void { 885 | 886 | window.OneSignalDeferred?.push((OneSignal) => { 887 | OneSignal.User.removeTags(keys); 888 | }); 889 | 890 | } 891 | // @ts-expect-error - return non-Promise type despite needing to await OneSignalDeferred 892 | async function userGetTags(): { [key: string]: string } { 893 | let retVal: { [key: string]: string }; 894 | await window.OneSignalDeferred?.push((OneSignal) => { 895 | retVal = OneSignal.User.getTags(); 896 | }); 897 | return retVal; 898 | } 899 | function userAddEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void { 900 | 901 | window.OneSignalDeferred?.push((OneSignal) => { 902 | OneSignal.User.addEventListener(event, listener); 903 | }); 904 | 905 | } 906 | function userRemoveEventListener(event: 'change', listener: (change: UserChangeEvent) => void): void { 907 | 908 | window.OneSignalDeferred?.push((OneSignal) => { 909 | OneSignal.User.removeEventListener(event, listener); 910 | }); 911 | 912 | } 913 | function userSetLanguage(language: string): void { 914 | 915 | window.OneSignalDeferred?.push((OneSignal) => { 916 | OneSignal.User.setLanguage(language); 917 | }); 918 | 919 | } 920 | // @ts-expect-error - return non-Promise type despite needing to await OneSignalDeferred 921 | async function userGetLanguage(): string { 922 | let retVal: string; 923 | await window.OneSignalDeferred?.push((OneSignal) => { 924 | retVal = OneSignal.User.getLanguage(); 925 | }); 926 | return retVal; 927 | } 928 | function pushSubscriptionOptIn(): Promise { 929 | return new Promise(function (resolve, reject) { 930 | if (isOneSignalScriptFailed) { 931 | reject(new Error('OneSignal script failed to load.')); 932 | return; 933 | } 934 | 935 | try { 936 | window.OneSignalDeferred?.push((OneSignal) => { 937 | OneSignal.User.PushSubscription.optIn().then(() => resolve()) 938 | .catch(error => reject(error)); 939 | }); 940 | } catch (error) { 941 | reject(error); 942 | } 943 | }); 944 | } 945 | function pushSubscriptionOptOut(): Promise { 946 | return new Promise(function (resolve, reject) { 947 | if (isOneSignalScriptFailed) { 948 | reject(new Error('OneSignal script failed to load.')); 949 | return; 950 | } 951 | 952 | try { 953 | window.OneSignalDeferred?.push((OneSignal) => { 954 | OneSignal.User.PushSubscription.optOut().then(() => resolve()) 955 | .catch(error => reject(error)); 956 | }); 957 | } catch (error) { 958 | reject(error); 959 | } 960 | }); 961 | } 962 | function pushSubscriptionAddEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void { 963 | 964 | window.OneSignalDeferred?.push((OneSignal) => { 965 | OneSignal.User.PushSubscription.addEventListener(event, listener); 966 | }); 967 | 968 | } 969 | function pushSubscriptionRemoveEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void { 970 | 971 | window.OneSignalDeferred?.push((OneSignal) => { 972 | OneSignal.User.PushSubscription.removeEventListener(event, listener); 973 | }); 974 | 975 | } 976 | function debugSetLogLevel(logLevel: 'trace' | 'debug' | 'info' | 'warn' | 'error'): void { 977 | 978 | window.OneSignalDeferred?.push((OneSignal) => { 979 | OneSignal.Debug.setLogLevel(logLevel); 980 | }); 981 | 982 | } 983 | const PushSubscriptionNamespace: IOneSignalPushSubscription = { 984 | get id(): string | null | undefined { return window.OneSignal?.User?.PushSubscription?.id; }, 985 | get token(): string | null | undefined { return window.OneSignal?.User?.PushSubscription?.token; }, 986 | get optedIn(): boolean | undefined { return window.OneSignal?.User?.PushSubscription?.optedIn; }, 987 | optIn: pushSubscriptionOptIn, 988 | optOut: pushSubscriptionOptOut, 989 | addEventListener: pushSubscriptionAddEventListener, 990 | removeEventListener: pushSubscriptionRemoveEventListener, 991 | }; 992 | 993 | const UserNamespace: IOneSignalUser = { 994 | get onesignalId(): string | undefined { return window.OneSignal?.User?.onesignalId; }, 995 | get externalId(): string | undefined { return window.OneSignal?.User?.externalId; }, 996 | addAlias: userAddAlias, 997 | addAliases: userAddAliases, 998 | removeAlias: userRemoveAlias, 999 | removeAliases: userRemoveAliases, 1000 | addEmail: userAddEmail, 1001 | removeEmail: userRemoveEmail, 1002 | addSms: userAddSms, 1003 | removeSms: userRemoveSms, 1004 | addTag: userAddTag, 1005 | addTags: userAddTags, 1006 | removeTag: userRemoveTag, 1007 | removeTags: userRemoveTags, 1008 | getTags: userGetTags, 1009 | addEventListener: userAddEventListener, 1010 | removeEventListener: userRemoveEventListener, 1011 | setLanguage: userSetLanguage, 1012 | getLanguage: userGetLanguage, 1013 | PushSubscription: PushSubscriptionNamespace, 1014 | }; 1015 | 1016 | const SessionNamespace: IOneSignalSession = { 1017 | sendOutcome: sessionSendOutcome, 1018 | sendUniqueOutcome: sessionSendUniqueOutcome, 1019 | }; 1020 | 1021 | const DebugNamespace: IOneSignalDebug = { 1022 | setLogLevel: debugSetLogLevel, 1023 | }; 1024 | 1025 | const SlidedownNamespace: IOneSignalSlidedown = { 1026 | promptPush: slidedownPromptPush, 1027 | promptPushCategories: slidedownPromptPushCategories, 1028 | promptSms: slidedownPromptSms, 1029 | promptEmail: slidedownPromptEmail, 1030 | promptSmsAndEmail: slidedownPromptSmsAndEmail, 1031 | addEventListener: slidedownAddEventListener, 1032 | removeEventListener: slidedownRemoveEventListener, 1033 | }; 1034 | 1035 | const NotificationsNamespace: IOneSignalNotifications = { 1036 | get permissionNative(): NotificationPermission { return window.OneSignal?.Notifications?.permissionNative ?? 'default'; }, 1037 | get permission(): boolean { return window.OneSignal?.Notifications?.permission ?? false; }, 1038 | setDefaultUrl: notificationsSetDefaultUrl, 1039 | setDefaultTitle: notificationsSetDefaultTitle, 1040 | isPushSupported, 1041 | requestPermission: notificationsRequestPermission, 1042 | addEventListener: notificationsAddEventListener, 1043 | removeEventListener: notificationsRemoveEventListener, 1044 | }; 1045 | 1046 | const OneSignalNamespace: IOneSignalOneSignal = { 1047 | login: oneSignalLogin, 1048 | logout: oneSignalLogout, 1049 | init, 1050 | setConsentGiven: oneSignalSetConsentGiven, 1051 | setConsentRequired: oneSignalSetConsentRequired, 1052 | Slidedown: SlidedownNamespace, 1053 | Notifications: NotificationsNamespace, 1054 | Session: SessionNamespace, 1055 | User: UserNamespace, 1056 | Debug: DebugNamespace, 1057 | }; 1058 | 1059 | export const useOneSignal = () => { 1060 | return OneSignalNamespace; 1061 | }; 1062 | 1063 | const OneSignalVuePlugin = { 1064 | install(app: App, options: IInitObject) { 1065 | app.config.globalProperties.$OneSignal = 1066 | OneSignalNamespace as IOneSignalOneSignal; 1067 | app.config.globalProperties.$OneSignal.init(options); 1068 | }, 1069 | }; 1070 | 1071 | export default OneSignalVuePlugin; 1072 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@onesignal/onesignal-vue3", 3 | "version": "2.2.2", 4 | "description": "Vue 3 OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!", 5 | "type": "module", 6 | "contributors": [ 7 | { 8 | "name": "Rodrigo Gomez-Palacio" 9 | }, 10 | { 11 | "name": "Enzo Innocenzi" 12 | } 13 | ], 14 | "license": "MIT", 15 | "repository": "OneSignal/onesignal-vue3", 16 | "main": "dist/index.js", 17 | "types": "dist/index.d.ts", 18 | "scripts": { 19 | "lint": "eslint . --ext .ts", 20 | "build": "npm run lint && tsc", 21 | "prepare": "npm run build" 22 | }, 23 | "dependencies": { 24 | "vue": "^3.2.0" 25 | }, 26 | "devDependencies": { 27 | "@typescript-eslint/eslint-plugin": "^5.20.0", 28 | "@typescript-eslint/parser": "^5.20.0", 29 | "eslint": "^8.13.0", 30 | "eslint-plugin-vue": "^9.17.0", 31 | "typescript": "^4.6.3" 32 | }, 33 | "files": [ 34 | "dist", 35 | "README.md", 36 | "LICENSE", 37 | "CHANGELOG.md", 38 | "MigrationGuide.md" 39 | ], 40 | "keywords": [ 41 | "onesignal", 42 | "push", 43 | "notification", 44 | "push notification", 45 | "vue" 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "module": "esnext", 5 | "target": "es6", 6 | "lib": ["es6", "dom", "es2016", "es2017"], 7 | "sourceMap": true, 8 | "allowJs": true, 9 | "declaration": true, 10 | "moduleResolution": "node", 11 | "forceConsistentCasingInFileNames": true, 12 | "noImplicitReturns": true, 13 | "noImplicitThis": true, 14 | "noImplicitAny": false, 15 | "strictNullChecks": false, 16 | "noUnusedLocals": true, 17 | "noUnusedParameters": true, 18 | "allowSyntheticDefaultImports": true, 19 | "downlevelIteration": true, 20 | "skipLibCheck": true 21 | }, 22 | "include": ["index.ts"], 23 | "exclude": ["node_modules", "build", "dist", "example"] 24 | } 25 | --------------------------------------------------------------------------------