Skip to content

sync with web-shim-codegen v3.0.4 #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ build

npm-debug.log*
example

.github
.releaserc.json

.eslintignore
.gitignore
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- 🏠 [Homepage](https://github.com/OneSignal/react-onesignal#readme)
- 🖤 [npm](https://www.npmjs.com/package/react-onesignal)

OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 2 million+ businesses to send 9 billion Push Notifications per day.
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.

You can find more information on OneSignal [here](https://onesignal.com/).

Expand Down Expand Up @@ -83,8 +83,7 @@ OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }).then(() => {
```

### Init Options

You can pass other [options](https://documentation.onesignal.com/v11.0/docs/web-sdk#initializing-the-sdk) to the `init` function. Use these options to configure personalized prompt options, auto-resubscribe, and more.
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.

<details>
<summary>Expand to see more options</summary>
Expand Down Expand Up @@ -155,7 +154,7 @@ interface IOneSignalOneSignal {

### OneSignal API

See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for information on all available SDK functions.
See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/docs/web-sdk-reference) for information on all available SDK functions.

---

Expand Down Expand Up @@ -195,7 +194,9 @@ OneSignal.Notifications.addEventListener('click', (event) => {
});
```

See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for all available event listeners.


See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/docs/web-sdk-reference#addeventlistener-push-notification) for all available event listeners.

## Troubleshooting

Expand Down
4 changes: 2 additions & 2 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OneSignal from './index';

const originalDocument = global.document;
const documentSpy = vi.spyOn(global, 'document', 'get');
const originalDocument = window.document;
const documentSpy = vi.spyOn(window, 'document', 'get');

const APP_ID = '123456';

Expand Down
27 changes: 20 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ const init = (options: IInitObject): Promise<void> => {
return Promise.reject(`Document is not defined.`);
}

// Handle both disabled and disable keys for welcome notification
if (options.welcomeNotification?.disabled !== undefined) {
options.welcomeNotification.disable = options.welcomeNotification.disabled;
}

return new Promise<void>((resolve, reject) => {
window.OneSignalDeferred?.push((OneSignal) => {
OneSignal.init(options)
Expand Down Expand Up @@ -332,9 +337,15 @@ export interface IInitObject {
welcomeNotification?: {
/**
* Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
* @deprecated Use 'disable' instead. This will be removed in a future version.
*/
disabled?: boolean;

/**
* Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
*/
disable?: boolean;

/**
* The welcome notification's message. You can localize this to your own language.
* If left blank or set to blank, the default of 'Thanks for subscribing!' will be used.
Expand All @@ -351,7 +362,7 @@ export interface IInitObject {
* By default, clicking the welcome notification does not open any link.
* This is recommended because the user has just visited your site and subscribed.
*/
url: string;
url?: string;
};

/**
Expand Down Expand Up @@ -482,7 +493,7 @@ export interface IOneSignalSlidedown {
removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
}
export interface IOneSignalDebug {
setLogLevel(logLevel: string): void;
setLogLevel(logLevel: 'trace' | 'debug' | 'info' | 'warn' | 'error'): void;
}
export interface IOneSignalSession {
sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>;
Expand Down Expand Up @@ -869,9 +880,10 @@ function userRemoveTags(keys: string[]): void {
});

}
function userGetTags(): { [key: string]: string } {
// @ts-expect-error - return non-Promise type despite needing to await OneSignalDeferred
async function userGetTags(): { [key: string]: string } {
let retVal: { [key: string]: string };
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
await window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
retVal = OneSignal.User.getTags();
});
return retVal;
Expand All @@ -897,9 +909,10 @@ function userSetLanguage(language: string): void {
});

}
function userGetLanguage(): string {
// @ts-expect-error - return non-Promise type despite needing to await OneSignalDeferred
async function userGetLanguage(): string {
let retVal: string;
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
await window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
retVal = OneSignal.User.getLanguage();
});
return retVal;
Expand Down Expand Up @@ -952,7 +965,7 @@ function pushSubscriptionRemoveEventListener(event: 'change', listener: (change:
});

}
function debugSetLogLevel(logLevel: string): void {
function debugSetLogLevel(logLevel: 'trace' | 'debug' | 'info' | 'warn' | 'error'): void {

window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
OneSignal.Debug.setLogLevel(logLevel);
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
"vite-plugin-dts": "^4.5.3",
"vitest": "^3.0.9"
},
"files": [
"dist",
"README.md",
"LICENSE",
"CHANGELOG.md",
"MigrationGuide.md"
],
"keywords": [
"onesignal",
"push",
Expand Down