New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-onesignal

Package Overview
Dependencies
Maintainers
9
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-onesignal - npm Package Compare versions

Comparing version 3.0.0-beta.3 to 3.0.0-beta.5

65

dist/index.d.ts

@@ -10,3 +10,2 @@ declare global {

}
declare type Action<T> = (item: T) => void;
interface AutoPromptOptions {

@@ -45,5 +44,56 @@ force?: boolean;

};
declare type NotificationEventName = 'click' | 'willDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
declare type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
interface NotificationButtonData extends NotificationAction {
url: string;
}
declare type SlidedownEventName = 'slidedownShown';
declare type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
declare type OSNotification = {
id?: string;
title?: string;
body?: string;
data?: any;
url?: string;
icon?: string;
image?: string;
tag?: string;
requireInteraction?: boolean;
renotify?: true;
actions?: Array<NotificationActionButton>;
};
declare type NotificationActionButton = {
action: string;
title: string;
icon?: string;
url?: string;
};
export declare type NotificationClickResult = {
actionId?: string;
url?: string;
};
declare type NotificationEventTypeMap = {
'click': NotificationClickResult;
'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
'dismiss': OSNotificationDataPayload;
'permissionChange': boolean;
'permissionPromptDisplay': void;
};
export declare type NotificationForegroundWillDisplayEvent = {
notification: OSNotification;
preventDefault(): void;
};
declare type OSNotificationDataPayload = {
id: string;
content: string;
heading?: string;
url?: string;
data?: object;
rr?: string;
icon?: string;
image?: string;
tag?: string;
badge?: string;
vibrate?: VibratePattern;
buttons?: NotificationButtonData[];
};
interface IInitObject {

@@ -84,9 +134,10 @@ appId: string;

interface IOneSignalNotifications {
permissionNative: NotificationPermission;
permission: boolean;
setDefaultUrl(url: string): Promise<void>;
setDefaultTitle(title: string): Promise<void>;
isPushSupported(): boolean;
getPermissionStatus(onComplete: Action<NotificationPermission>): Promise<NotificationPermission>;
requestPermission(): Promise<void>;
addEventListener(event: NotificationEventName, listener: (obj: any) => void): void;
removeEventListener(event: NotificationEventName, listener: (obj: any) => void): void;
addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
}

@@ -134,6 +185,6 @@ interface IOneSignalSlidedown {

optOut(): Promise<void>;
addEventListener(event: 'subscriptionChange', listener: (change: SubscriptionChangeEvent) => void): void;
removeEventListener(event: 'subscriptionChange', listener: (change: SubscriptionChangeEvent) => void): void;
addEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void;
removeEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void;
}
declare const OneSignal: IOneSignalOneSignal;
export default OneSignal;

27

dist/index.es.js

@@ -9,4 +9,6 @@ const ONESIGNAL_SDK_ID = 'onesignal-sdk';

let isOneSignalScriptFailed = false;
window.OneSignalDeferred = (window === null || window === void 0 ? void 0 : window.OneSignalDeferred) || [];
addSDKScript();
if (window) {
window.OneSignalDeferred = window.OneSignalDeferred || [];
addSDKScript();
}
/* H E L P E R S */

@@ -295,20 +297,2 @@ function handleOnError() {

}
function notificationsGetPermissionStatus(onComplete) {
return new Promise((resolve, reject) => {
var _a;
if (isOneSignalScriptFailed) {
reject();
}
try {
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
OneSignal.Notifications.getPermissionStatus(onComplete)
.then((value) => resolve(value))
.catch((error) => reject(error));
});
}
catch (error) {
reject(error);
}
});
}
function notificationsRequestPermission() {

@@ -547,6 +531,7 @@ return new Promise((resolve, reject) => {

const NotificationsNamespace = {
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'; },
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; },
setDefaultUrl: notificationsSetDefaultUrl,
setDefaultTitle: notificationsSetDefaultTitle,
isPushSupported,
getPermissionStatus: notificationsGetPermissionStatus,
requestPermission: notificationsRequestPermission,

@@ -553,0 +538,0 @@ addEventListener: notificationsAddEventListener,

@@ -11,4 +11,6 @@ 'use strict';

let isOneSignalScriptFailed = false;
window.OneSignalDeferred = (window === null || window === void 0 ? void 0 : window.OneSignalDeferred) || [];
addSDKScript();
if (window) {
window.OneSignalDeferred = window.OneSignalDeferred || [];
addSDKScript();
}
/* H E L P E R S */

@@ -297,20 +299,2 @@ function handleOnError() {

}
function notificationsGetPermissionStatus(onComplete) {
return new Promise((resolve, reject) => {
var _a;
if (isOneSignalScriptFailed) {
reject();
}
try {
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => {
OneSignal.Notifications.getPermissionStatus(onComplete)
.then((value) => resolve(value))
.catch((error) => reject(error));
});
}
catch (error) {
reject(error);
}
});
}
function notificationsRequestPermission() {

@@ -549,6 +533,7 @@ return new Promise((resolve, reject) => {

const NotificationsNamespace = {
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'; },
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; },
setDefaultUrl: notificationsSetDefaultUrl,
setDefaultTitle: notificationsSetDefaultTitle,
isPushSupported,
getPermissionStatus: notificationsGetPermissionStatus,
requestPermission: notificationsRequestPermission,

@@ -555,0 +540,0 @@ addEventListener: notificationsAddEventListener,

@@ -11,6 +11,7 @@ const ONESIGNAL_SDK_ID = 'onesignal-sdk';

window.OneSignalDeferred = window?.OneSignalDeferred || [];
if (window) {
window.OneSignalDeferred = window.OneSignalDeferred || [];
addSDKScript();
}
addSDKScript();
declare global {

@@ -113,3 +114,2 @@ interface Window {

type Action<T> = (item: T) => void;
interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }

@@ -121,7 +121,12 @@ interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }

type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
type NotificationEventName = 'click' | 'willDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
interface NotificationButtonData { action?: string; title?: string; icon?: string; url?: string; }
interface StructuredNotification { id: string; content: string; heading?: string; url?: string; data?: object; rr?: string; icon?: string; image?: string; tag?: string; badge?: string; vibrate?: string; buttons?: NotificationButtonData[]; }
type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
interface NotificationButtonData extends NotificationAction { url: string; };
type SlidedownEventName = 'slidedownShown';
type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
type OSNotification = { id?: string; title?: string; body?: string; data?: any; url?: string; icon?: string; image?: string; tag?: string; requireInteraction?: boolean; renotify?: true; actions?: Array<NotificationActionButton>; };
type NotificationActionButton = { action: string; title: string; icon?: string; url?: string; }
export type NotificationClickResult = { actionId?: string; url?: string; }
type NotificationEventTypeMap = { 'click': NotificationClickResult; 'foregroundWillDisplay': NotificationForegroundWillDisplayEvent; 'dismiss': OSNotificationDataPayload; 'permissionChange': boolean; 'permissionPromptDisplay': void; };
export type NotificationForegroundWillDisplayEvent = { notification: OSNotification; preventDefault(): void; }
type OSNotificationDataPayload = { id: string; content: string; heading?: string; url?: string; data?: object; rr?: string; icon?: string; image?: string; tag?: string; badge?: string; vibrate?: VibratePattern; buttons?: NotificationButtonData[]; };

@@ -162,9 +167,10 @@ interface IInitObject {

interface IOneSignalNotifications {
permissionNative: NotificationPermission;
permission: boolean;
setDefaultUrl(url: string): Promise<void>;
setDefaultTitle(title: string): Promise<void>;
isPushSupported(): boolean;
getPermissionStatus(onComplete: Action<NotificationPermission>): Promise<NotificationPermission>;
requestPermission(): Promise<void>;
addEventListener(event: NotificationEventName, listener: (obj: any) => void): void;
removeEventListener(event: NotificationEventName, listener: (obj: any) => void): void;
addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
}

@@ -208,4 +214,4 @@ interface IOneSignalSlidedown {

optOut(): Promise<void>;
addEventListener(event: 'subscriptionChange', listener: (change: SubscriptionChangeEvent) => void): void;
removeEventListener(event: 'subscriptionChange', listener: (change: SubscriptionChangeEvent) => void): void;
addEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void;
removeEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void;
}

@@ -423,20 +429,2 @@

function notificationsGetPermissionStatus(onComplete: Action<NotificationPermission>): Promise<NotificationPermission> {
return new Promise((resolve, reject) => {
if (isOneSignalScriptFailed) {
reject();
}
try {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
OneSignal.Notifications.getPermissionStatus(onComplete)
.then((value: any) => resolve(value))
.catch((error: any) => reject(error));
});
} catch (error) {
reject(error);
}
});
}
function notificationsRequestPermission(): Promise<void> {

@@ -460,7 +448,3 @@ return new Promise((resolve, reject) => {

function notificationsAddEventListener(event: 'click' | 'willDisplay' | 'dismiss', listener: (obj: StructuredNotification) => void): void;
function notificationsAddEventListener(event: 'permissionChange', listener: (obj: { to: NotificationPermission }) => void): void;
function notificationsAddEventListener(event: 'permissionPromptDisplay', listener: () => void): void;
function notificationsAddEventListener(event: NotificationEventName, listener: (obj: any) => void): void {
function notificationsAddEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {

@@ -471,7 +455,3 @@ OneSignal.Notifications.addEventListener(event, listener)

function notificationsRemoveEventListener(event: 'click' | 'willDisplay' | 'dismiss', listener: (obj: StructuredNotification) => void): void;
function notificationsRemoveEventListener(event: 'permissionChange', listener: (obj: { to: NotificationPermission }) => void): void;
function notificationsRemoveEventListener(event: 'permissionPromptDisplay', listener: () => void): void;
function notificationsRemoveEventListener(event: NotificationEventName, listener: (obj: any) => void): void {
function notificationsRemoveEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {

@@ -626,3 +606,3 @@ OneSignal.Notifications.removeEventListener(event, listener)

function pushSubscriptionAddEventListener(event: 'subscriptionChange', listener: (change: SubscriptionChangeEvent) => void): void {
function pushSubscriptionAddEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {

@@ -633,3 +613,3 @@ OneSignal.User.PushSubscription.addEventListener(event, listener)

function pushSubscriptionRemoveEventListener(event: 'subscriptionChange', listener: (change: SubscriptionChangeEvent) => void): void {
function pushSubscriptionRemoveEventListener(event: 'change', listener: (change: SubscriptionChangeEvent) => void): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {

@@ -691,6 +671,7 @@ OneSignal.User.PushSubscription.removeEventListener(event, listener)

const NotificationsNamespace: IOneSignalNotifications = {
get permissionNative(): NotificationPermission { return window.OneSignal?.Notifications?.permissionNative ?? 'default'; },
get permission(): boolean { return window.OneSignal?.Notifications?.permission ?? false; },
setDefaultUrl: notificationsSetDefaultUrl,
setDefaultTitle: notificationsSetDefaultTitle,
isPushSupported,
getPermissionStatus: notificationsGetPermissionStatus,
requestPermission: notificationsRequestPermission,

@@ -697,0 +678,0 @@ addEventListener: notificationsAddEventListener,

@@ -114,14 +114,16 @@

| Sync/Async | Function Name | Description | Argument List |
| ---------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `async` | `setDefaultUrl` | Sets the default URL for notifications. | `url` (string) |
| `async` | `setDefaultTitle` | Sets the default title for notifications. | `title` (string) |
| `sync` | `isPushSupported` | Returns true if the current browser supports web push. | |
| `async` | `getPermissionStatus` | Returns the browser's current notification permission. | `onComplete` (Action<NotificationPermission>) |
| `async` | `requestPermission` | Requests push notifications permission via the native browser prompt. | |
| `sync` | `addEventListener` | Adds an event listener for the following events:<br><br>- `click`<br>- `willDisplay`<br>- `dismiss`<br>- `permissionPromptDisplay`<br>- `permissionChange`*<br> * argument type: bool | - `<event>` (string)<br>- `(arg: <type>) => {}` (callback) |
| `sync` | `removeEventListener` | Removes the event listener. | `() => {}` (the event listener you want to remove) |
| Sync/Async | Function / Property | Description | Argument List |
| ---------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `async` | `setDefaultUrl()` | Sets the default URL for notifications. | `url` (string) |
| `async` | `setDefaultTitle()` | Sets the default title for notifications. | `title` (string) |
| `sync` | `isPushSupported()` | Returns true if the current browser supports web push. | |
| `async` | `requestPermission()` | Requests push notifications permission via the native browser prompt. | |
| `sync` | `addEventListener()` | Adds an event listener for the following events:<br><br>- `click`<br>- `willDisplay`<br>- `dismiss`<br>- `permissionPromptDisplay`<br>- `permissionChange`*<br> * argument type: bool | - `<event>` (string)<br>- `(arg: <type>) => {}` (callback) |
| `sync` | `removeEventListener()` | Removes the event listener. | `() => {}` (the event listener you want to remove) |
| | `permission` | A boolean representing whether or not the user has granted permission for push notifications. | |
| | `permissionNative` | A string representing the native push permission status: 'default', 'granted', or 'denied'. | |
### Slidedown Namespace

@@ -176,2 +178,10 @@

## May 2023
## Version 16 (beta)
Please test thoroughly prior to production use.
* Any User namespace calls must be invoked **after** initialization (async). Example: `OneSignal.User.addTag("tag", "2");`
* HTTP environments are not supported.
* AMP environments are not supported.
* Identity verification is not functional.
## January 2023

@@ -178,0 +188,0 @@ ### Version 16 (alpha)

{
"name": "react-onesignal",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.5",
"description": "React OneSignal Module: Make it easy to integrate OneSignal with your React App!",

@@ -5,0 +5,0 @@ "author": "rgomezp",

@@ -8,14 +8,15 @@ <p align="center">

# React OneSignal
---
> This is a JavaScript module that can be used to easily include [OneSignal](https://onesignal.com/) code in a website or app in practically any JS front-end codebase (not limited to React).
This is a JavaScript module that can be used to easily include [OneSignal](https://onesignal.com/) code in a website or app that uses React for its front-end codebase.
OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 800k businesses to send 5 billion Push Notifications per day.
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.
You can find more information on OneSignal [here](https://onesignal.com/).
### Migration Guide
Version 2.0 was recently released. Read the [Migration Guide](https://github.com/OneSignal/react-onesignal/blob/master/MigrationGuide.md) here if you're coming from a version 1 release of the SDK.
### Migration Guides
Versions 2.0 and 3.0 were recently released and include breaking changes. See the [Migration Guide](https://github.com/OneSignal/react-onesignal/blob/user-model/v1/MigrationGuide.md) to update your implementation.
> ATTENTION: v3 is currently in Beta 🚧 and includes a fundamental shift to the OneSignal subscriber ("player") model. Learn more [here](https://documentation.onesignal.com/v11.0/docs/user-model).
## Contents

@@ -68,5 +69,4 @@ - [Install](#install)

setInitialized(true);
OneSignal.showSlidedownPrompt().then(() => {
// do other stuff
});
OneSignal.Slidedown.promptPush();
// do other stuff
})

@@ -76,4 +76,27 @@ ```

### Init Options
You can pass other [options](https://documentation.onesignal.com/docs/web-push-sdk#init) to the `init` function. Use these options to configure personalized prompt options, auto-resubscribe, and more.
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.
<details>
<summary>Expand to see more options</summary>
| Property Name | Type | Description |
| ---------------------------| --------------------- | -------------------------------------------------- |
| `appId` | `string` | The ID of your OneSignal app. |
| `autoRegister` | `boolean` (optional) | Whether or not to automatically register the user. |
| `autoResubscribe` | `boolean` (optional) | Whether or not to automatically resubscribe the user. |
| `path` | `string` (optional) | The path to the OneSignal service worker file. |
| `serviceWorkerPath` | `string` (optional) | The path to the OneSignal service worker script. |
| `serviceWorkerUpdaterPath` | `string` (optional) | The path to the OneSignal service worker updater script. |
| `subdomainName` | `string` (optional) | The subdomain of your OneSignal app. |
| `allowLocalhostAsSecureOrigin` | `boolean` (optional) | Whether or not to allow localhost as a secure origin. |
| `requiresUserPrivacyConsent`| `boolean` (optional) | Whether or not the user's consent is required. |
| `persistNotification` | `boolean` (optional) | Whether or not notifications should persist. |
| `notificationClickHandlerMatch`| `string` (optional) | The URL match pattern for notification clicks. |
| `notificationClickHandlerAction`| `string` (optional)| The action to perform when a notification is clicked. |
| `welcomeNotification` | `object` (optional) | The welcome notification configuration. |
| `notifyButton` | `object` (optional) | The notify button configuration. |
| `promptOptions` | `object` (optional) | Additional options for the subscription prompt. |
| `webhooks` | `object` (optional) | The webhook configuration. |
| `[key: string]` | `any` | Additional properties can be added as needed. |
**Service Worker Params**

@@ -89,2 +112,6 @@ 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).

</details>
---
### Service Worker File

@@ -99,3 +126,2 @@ If you haven't done so already, you will need to add the [OneSignal Service Worker file](https://github.com/OneSignal/OneSignal-Website-SDK/files/7585231/OneSignal-Web-SDK-HTTPS-Integration-Files.zip) to your site ([learn more](https://documentation.onesignal.com/docs/web-push-quickstart#step-6-upload-files)).

---
## OneSignal API
### Typescript

@@ -105,40 +131,13 @@ This package includes Typescript support.

```ts
interface OneSignal {
init(options: IInitObject): Promise<void>;
on(event: string, listener: () => void): void;
off(event: string, listener: () => void): void;
once(event: string, listener: () => void): void;
isPushNotificationsEnabled(callback?: Action<boolean>): Promise<boolean>;
showHttpPrompt(options?: AutoPromptOptions): Promise<void>;
registerForPushNotifications(options?: RegisterOptions): Promise<void>;
setDefaultNotificationUrl(url: string): Promise<void>;
setDefaultTitle(title: string): Promise<void>;
getTags(callback?: Action<any>): Promise<void>;
sendTag(key: string, value: any, callback?: Action<Object>): Promise<Object | null>;
sendTags(tags: TagsObject<any>, callback?: Action<Object>): Promise<Object | null>;
deleteTag(tag: string): Promise<Array<string>>;
deleteTags(tags: Array<string>, callback?: Action<Array<string>>): Promise<Array<string>>;
addListenerForNotificationOpened(callback?: Action<Notification>): Promise<void>;
setSubscription(newSubscription: boolean): Promise<void>;
showHttpPermissionRequest(options?: AutoPromptOptions): Promise<any>;
showNativePrompt(): Promise<void>;
showSlidedownPrompt(options?: AutoPromptOptions): Promise<void>;
showCategorySlidedown(options?: AutoPromptOptions): Promise<void>;
showSmsSlidedown(options?: AutoPromptOptions): Promise<void>;
showEmailSlidedown(options?: AutoPromptOptions): Promise<void>;
showSmsAndEmailSlidedown(options?: AutoPromptOptions): Promise<void>;
getNotificationPermission(onComplete?: Action<NotificationPermission>): Promise<NotificationPermission>;
getUserId(callback?: Action<string | undefined | null>): Promise<string | undefined | null>;
getSubscription(callback?: Action<boolean>): Promise<boolean>;
setEmail(email: string, options?: SetEmailOptions): Promise<string | null>;
setSMSNumber(smsNumber: string, options?: SetSMSOptions): Promise<string | null>;
logoutEmail(): Promise<void>;
logoutSMS(): Promise<void>;
setExternalUserId(externalUserId: string | undefined | null, authHash?: string): Promise<void>;
removeExternalUserId(): Promise<void>;
getExternalUserId(): Promise<string | undefined | null>;
provideUserConsent(consent: boolean): Promise<void>;
getEmailId(callback?: Action<string | undefined>): Promise<string | null | undefined>;
getSMSId(callback?: Action<string | undefined>): Promise<string | null | undefined>;
sendOutcome(outcomeName: string, outcomeWeight?: number | undefined): Promise<void>;
interface IOneSignalOneSignal {
Slidedown: IOneSignalSlidedown;
Notifications: IOneSignalNotifications;
Session: IOneSignalSession;
User: IOneSignalUser;
Debug: IOneSignalDebug;
login(externalId: string, jwtToken?: string): Promise<void>;
logout(): Promise<void>;
init(options: IInitObject): Promise<void>;
setConsentGiven(consent: boolean): Promise<void>;
setConsentRequired(requiresConsent: boolean): Promise<void>;
}

@@ -148,3 +147,3 @@ ```

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

@@ -156,18 +155,93 @@ ---

* `subscriptionChange`
* `permissionPromptDisplay`
* `notificationPermissionChange`
* `popoverShown`
* `customPromptClick`
* `notificationDisplay`
* `notificationDismiss`
### Notifications Namespace
| Event Name | Callback Argument Type |
|-|-|
|'click' | NotificationClickResult|
|'foregroundWillDisplay'| NotificationForegroundWillDisplayEvent
| 'dismiss'| OSNotificationDataPayload|
|'permissionChange'| boolean|
|'permissionPromptDisplay'| void|
<details>
<summary>Expand to see associated types</summary>
#### `NotificationClickResult`
| Property | Description |
|-------------------------|---------------------------------------------|
| `actionId` | A string representing the action ID associated with the click event |
| `url` | A string representing the URL associated with the click event |
#### `NotificationForegroundWillDisplayEvent`
| Property | Description |
|-------------------------|---------------------------------------------|
| `notification` | An `OSNotification` type object |
#### `OSNotification`
| Property | Description |
|-----------------------|----------------------------------------------------------------------------------------------------------------------|
| `id` | Optional string representing the unique identifier of the notification. |
| `title` | Optional string representing the title of the notification. |
| `body` | Optional string representing the body of the notification. |
| `data` | Optional data object associated with the notification. |
| `url` | Optional string representing the URL to be opened when the notification is clicked. |
| `icon` | Optional string representing the URL of the icon to be displayed with the notification. |
| `image` | Optional string representing the URL of the image to be displayed with the notification. |
| `tag` | Optional string representing a unique identifier for a group of notifications. |
| `requireInteraction` | Optional boolean indicating whether the notification requires user interaction or not. |
| `renotify` | Optional boolean indicating whether the notification should be replaced or not, if a notification with the same tag is already displayed. |
| `actions` | Optional array of `NotificationActionButton` objects representing the action buttons associated with the notification. |
#### `NotificationActionButton`
| Property | Description |
|-------------|-----------------------------------------------------------------------------------------------|
| `action` | A string representing the action associated with the button. |
| `title` | A string representing the title of the button. |
| `icon` | Optional string representing the URL of the icon to be displayed with the button. |
| `url` | Optional string representing the URL to be opened when the button is clicked. |
#### `OSNotificationDataPayload`
| Property | Description |
|-------------|-----------------------------------------------------------------------------------------------|
| `id` | A string representing the unique identifier of the notification data payload. |
| `content` | A string representing the content of the notification data payload. |
| `heading` | Optional string representing the heading of the notification data payload. |
| `url` | Optional string representing the URL to be opened when the notification data payload is clicked. |
| `data` | Optional object containing additional data associated with the notification data payload. |
| `rr` | Optional string with value 'y' or 'n' representing whether or not the notification has [Confirmed Delivery](https://documentation.onesignal.com/docs/confirmed-deliveries). |
| `icon` | Optional string representing the URL of the icon to be displayed with the notification data payload. |
| `image` | Optional string representing the URL of the image to be displayed with the notification data payload. |
| `tag` | Optional string representing a unique identifier for a group of notification data payloads. |
| `badge` | Optional string representing the URL of the badge to be displayed with the notification data payload. |
| `vibrate` | Optional array of numbers representing the vibration pattern of the notification data payload. |
| `buttons` | Optional array of `NotificationButtonData` objects representing the button data associated with the notification data payload. |
#### `NotificationButtonData`
| Property | Description |
|----------|------------------------------------------------------------------------------------------------------|
| `url` | A string representing the URL to be opened when the button is clicked. |
| `id` | A string representing the ID of the action. |
| `action` | A string representing the type of the action (inherited from `NotificationAction`). |
| `title` | A string representing the title of the action button (inherited from `NotificationAction`). |
| `icon` | Optional string representing the URL of the icon to be displayed with the action button. |
</details>
### Slidedown Namespace
| Event Name | Callback Argument Type |
|-|-|
|'slidedownShown' | boolean |
### Push Subscription Namespace
| Event Name | Callback Argument Type |
|-|-|
|'change' | boolean |
**Example**
```js
OneSignal.on('subscriptionChange', function(isSubscribed) {
console.log("The user's subscription state is now:", isSubscribed);
OneSignal.Notifications.addEventListener('click', (result) => {
console.log("The notification was clicked!", result);
});
```
See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/docs/web-push-sdk) for all available event listeners.
See the [OneSignal WebSDK Reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for all available event listeners.

@@ -203,3 +277,3 @@ ## Troubleshooting

Copyright © 2022 [OneSignal](https://github.com/OneSignal).<br />
Copyright © 2023 [OneSignal](https://github.com/OneSignal).<br />
This project is [Modified MIT](https://github.com/OneSignal/react-onesignal/blob/master/LICENSE) licensed.

@@ -206,0 +280,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc