react-onesignal
Advanced tools
Comparing version
# Changelog | ||
## [3.2.0](https://github.com/OneSignal/react-onesignal/compare/3.1.1...3.2.0) (2025-03-24) | ||
### Features | ||
* sync with web-shim-codegen v3.0.2 ([1a23688](https://github.com/OneSignal/react-onesignal/commit/1a23688ba8cb42533ad561ef460eaacf2c9be6d9)) | ||
## [3.1.1](https://github.com/OneSignal/react-onesignal/compare/3.1.0...3.1.1) (2025-03-14) | ||
@@ -4,0 +10,0 @@ |
@@ -10,3 +10,3 @@ declare global { | ||
} | ||
interface AutoPromptOptions { | ||
export interface AutoPromptOptions { | ||
force?: boolean; | ||
@@ -16,3 +16,3 @@ forceSlidedownOverNative?: boolean; | ||
} | ||
interface IOneSignalAutoPromptOptions { | ||
export interface IOneSignalAutoPromptOptions { | ||
force?: boolean; | ||
@@ -23,3 +23,3 @@ forceSlidedownOverNative?: boolean; | ||
} | ||
interface IOneSignalCategories { | ||
export interface IOneSignalCategories { | ||
positiveUpdateButton: string; | ||
@@ -32,3 +32,3 @@ negativeUpdateButton: string; | ||
} | ||
interface IOneSignalTagCategory { | ||
export interface IOneSignalTagCategory { | ||
tag: string; | ||
@@ -38,3 +38,3 @@ label: string; | ||
} | ||
declare type PushSubscriptionNamespaceProperties = { | ||
export type PushSubscriptionNamespaceProperties = { | ||
id: string | null | undefined; | ||
@@ -44,10 +44,10 @@ token: string | null | undefined; | ||
}; | ||
declare type SubscriptionChangeEvent = { | ||
export type SubscriptionChangeEvent = { | ||
previous: PushSubscriptionNamespaceProperties; | ||
current: PushSubscriptionNamespaceProperties; | ||
}; | ||
declare type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay'; | ||
declare type SlidedownEventName = 'slidedownShown'; | ||
declare type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void; | ||
interface IOSNotification { | ||
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay'; | ||
export type SlidedownEventName = 'slidedownShown'; | ||
export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void; | ||
export interface IOSNotification { | ||
/** | ||
@@ -103,3 +103,3 @@ * The OneSignal notification id; | ||
} | ||
interface IOSNotificationActionButton { | ||
export interface IOSNotificationActionButton { | ||
/** | ||
@@ -124,7 +124,7 @@ * Any unique identifier to represent which button was clicked. This is typically passed back to the service worker | ||
} | ||
interface NotificationClickResult { | ||
export interface NotificationClickResult { | ||
readonly actionId?: string; | ||
readonly url?: string; | ||
} | ||
declare type NotificationEventTypeMap = { | ||
export type NotificationEventTypeMap = { | ||
'click': NotificationClickEvent; | ||
@@ -136,29 +136,186 @@ 'foregroundWillDisplay': NotificationForegroundWillDisplayEvent; | ||
}; | ||
interface NotificationForegroundWillDisplayEvent { | ||
export interface NotificationForegroundWillDisplayEvent { | ||
readonly notification: IOSNotification; | ||
preventDefault(): void; | ||
} | ||
interface NotificationDismissEvent { | ||
export interface NotificationDismissEvent { | ||
notification: IOSNotification; | ||
} | ||
interface NotificationClickEvent { | ||
export interface NotificationClickEvent { | ||
readonly notification: IOSNotification; | ||
readonly result: NotificationClickResult; | ||
} | ||
declare type UserChangeEvent = { | ||
export type UserChangeEvent = { | ||
current: UserNamespaceProperties; | ||
}; | ||
declare type UserNamespaceProperties = { | ||
export type UserNamespaceProperties = { | ||
onesignalId: string | undefined; | ||
externalId: string | undefined; | ||
}; | ||
interface IInitObject { | ||
export interface IInitObject { | ||
appId: string; | ||
subdomainName?: string; | ||
requiresUserPrivacyConsent?: boolean; | ||
promptOptions?: object; | ||
welcomeNotification?: object; | ||
notifyButton?: object; | ||
promptOptions?: { | ||
slidedown: { | ||
prompts: { | ||
/** | ||
* Whether to automatically display the prompt. | ||
* `true` will display the prompt based on the delay options. | ||
* `false` will prevent the prompt from displaying until the Slidedowns methods are used. | ||
*/ | ||
autoPrompt: boolean; | ||
/** | ||
* Only available for type: category. Up to 10 categories. | ||
* @example | ||
* categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt. | ||
*/ | ||
categories: { | ||
/** Should identify the action. */ | ||
tag: string; | ||
/** What the user will see. */ | ||
label: string; | ||
}[]; | ||
/** | ||
* The delay options for the prompt. | ||
* @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view. | ||
*/ | ||
delay: { | ||
/** The number of pages a user needs to visit before the prompt is displayed. */ | ||
pageViews?: number; | ||
/** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */ | ||
timeDelay?: number; | ||
}; | ||
/** | ||
* The text to display in the prompt. | ||
*/ | ||
text?: { | ||
/** The callout asking the user to opt-in. Up to 90 characters. */ | ||
actionMessage?: string; | ||
/** Triggers the opt-in. Up to 15 characters. */ | ||
acceptButton?: string; | ||
/** Cancels opt-in. Up to 15 characters. */ | ||
cancelMessage?: string; | ||
/** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */ | ||
confirmMessage?: string; | ||
/** Identifies the email text field. Up to 15 characters. */ | ||
emailLabel?: string; | ||
/** Cancels the category update. Up to 15 characters. */ | ||
negativeUpdateButton?: string; | ||
/** Saves the updated category tags. Up to 15 characters. */ | ||
positiveUpdateButton?: string; | ||
/** Identifies the phone number text field. Up to 15 characters. */ | ||
smsLabel?: string; | ||
/** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */ | ||
updateMessage?: string; | ||
}; | ||
/** | ||
* The type of prompt to display. | ||
* `push` which is the Slide Prompt without categories. | ||
* `category` which is the Slide Prompt with categories. | ||
* `sms` only asks for phone number. | ||
* `email` only asks for email address. | ||
* `smsAndEmail` asks for both phone number and email address. | ||
*/ | ||
type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail'; | ||
}[]; | ||
}; | ||
}; | ||
welcomeNotification?: { | ||
/** | ||
* Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need. | ||
*/ | ||
disabled?: 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. | ||
*/ | ||
message: string; | ||
/** | ||
* 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. | ||
* Set to one space ' ' to clear the title, although this is not recommended. | ||
*/ | ||
title?: string; | ||
/** | ||
* 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; | ||
}; | ||
/** | ||
* Will enable customization of the notify/subscription bell button. | ||
*/ | ||
notifyButton?: { | ||
/** | ||
* A function you define that returns true to show the Subscription Bell, or false to hide it. | ||
* Typically used the hide the Subscription Bell after the user is subscribed. | ||
* This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show. | ||
*/ | ||
displayPredicate?: () => boolean | Promise<boolean>; | ||
/** | ||
* Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default. | ||
*/ | ||
enable?: boolean; | ||
/** Specify CSS-valid pixel offsets using bottom, left, and right. */ | ||
offset?: { | ||
bottom: string; | ||
left: string; | ||
right: string; | ||
}; | ||
/** | ||
* If `true`, the Subscription Bell will display an icon that there is 1 unread message. | ||
* When hovering over the Subscription Bell, the user will see custom text set by message.prenotify. | ||
*/ | ||
prenotify: boolean; | ||
/** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */ | ||
position?: 'bottom-left' | 'bottom-right'; | ||
/** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */ | ||
showCredit: boolean; | ||
/** | ||
* The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes. | ||
*/ | ||
size?: 'small' | 'medium' | 'large'; | ||
/** Customize the Subscription Bell text. */ | ||
text: { | ||
'dialog.blocked.message': string; | ||
'dialog.blocked.title': string; | ||
'dialog.main.button.subscribe': string; | ||
'dialog.main.button.unsubscribe': string; | ||
'dialog.main.title': string; | ||
'message.action.resubscribed': string; | ||
'message.action.subscribed': string; | ||
'message.action.subscribing': string; | ||
'message.action.unsubscribed': string; | ||
'message.prenotify': string; | ||
'tip.state.blocked': string; | ||
'tip.state.subscribed': string; | ||
'tip.state.unsubscribed': string; | ||
}; | ||
}; | ||
persistNotification?: boolean; | ||
webhooks?: object; | ||
webhooks?: { | ||
/** | ||
* Enable this setting only if your server has CORS enabled and supports non-simple CORS requests. | ||
* If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers. | ||
* The simplest option is to leave it disabled. | ||
* @default false | ||
*/ | ||
cors: boolean; | ||
/** | ||
* This event occurs after a notification is clicked. | ||
* @example https://site.com/hook | ||
*/ | ||
'notification.clicked'?: string; | ||
/** | ||
* 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), | ||
* 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. | ||
* @example https://site.com/hook | ||
*/ | ||
'notification.dismissed'?: string; | ||
/** | ||
* This event occurs after a notification is displayed. | ||
* @example https://site.com/hook | ||
*/ | ||
'notification.willDisplay'?: string; | ||
}; | ||
autoResubscribe?: boolean; | ||
@@ -178,3 +335,3 @@ autoRegister?: boolean; | ||
} | ||
interface IOneSignalOneSignal { | ||
export interface IOneSignalOneSignal { | ||
Slidedown: IOneSignalSlidedown; | ||
@@ -191,3 +348,3 @@ Notifications: IOneSignalNotifications; | ||
} | ||
interface IOneSignalNotifications { | ||
export interface IOneSignalNotifications { | ||
permissionNative: NotificationPermission; | ||
@@ -202,3 +359,3 @@ permission: boolean; | ||
} | ||
interface IOneSignalSlidedown { | ||
export interface IOneSignalSlidedown { | ||
promptPush(options?: AutoPromptOptions): Promise<void>; | ||
@@ -212,10 +369,10 @@ promptPushCategories(options?: AutoPromptOptions): Promise<void>; | ||
} | ||
interface IOneSignalDebug { | ||
export interface IOneSignalDebug { | ||
setLogLevel(logLevel: string): void; | ||
} | ||
interface IOneSignalSession { | ||
export interface IOneSignalSession { | ||
sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>; | ||
sendUniqueOutcome(outcomeName: string): Promise<void>; | ||
} | ||
interface IOneSignalUser { | ||
export interface IOneSignalUser { | ||
onesignalId: string | undefined; | ||
@@ -248,3 +405,3 @@ externalId: string | undefined; | ||
} | ||
interface IOneSignalPushSubscription { | ||
export interface IOneSignalPushSubscription { | ||
id: string | null | undefined; | ||
@@ -251,0 +408,0 @@ token: string | null | undefined; |
1022
dist/index.es.js
@@ -1,594 +0,530 @@ | ||
const ONESIGNAL_SDK_ID = 'onesignal-sdk'; | ||
const ONE_SIGNAL_SCRIPT_SRC = "https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js"; | ||
// true if the script is successfully loaded from CDN. | ||
let isOneSignalInitialized = false; | ||
// true if the script fails to load from CDN. A separate flag is necessary | ||
// to disambiguate between a CDN load failure and a delayed call to | ||
// OneSignal#init. | ||
let isOneSignalScriptFailed = false; | ||
if (typeof window !== 'undefined') { | ||
window.OneSignalDeferred = window.OneSignalDeferred || []; | ||
addSDKScript(); | ||
const u = "onesignal-sdk", l = "https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js"; | ||
let d = !1, s = !1; | ||
typeof window < "u" && (window.OneSignalDeferred = window.OneSignalDeferred || [], f()); | ||
function c() { | ||
s = !0; | ||
} | ||
/* H E L P E R S */ | ||
function handleOnError() { | ||
isOneSignalScriptFailed = true; | ||
function f() { | ||
const r = document.createElement("script"); | ||
r.id = u, r.defer = !0, r.src = l, r.onerror = () => { | ||
c(); | ||
}, document.head.appendChild(r); | ||
} | ||
function addSDKScript() { | ||
const script = document.createElement('script'); | ||
script.id = ONESIGNAL_SDK_ID; | ||
script.defer = true; | ||
script.src = ONE_SIGNAL_SCRIPT_SRC; | ||
// Always resolve whether or not the script is successfully initialized. | ||
// This is important for users who may block cdn.onesignal.com w/ adblock. | ||
script.onerror = () => { | ||
handleOnError(); | ||
}; | ||
document.head.appendChild(script); | ||
function w() { | ||
return g() || S(); | ||
} | ||
/** | ||
* The following code is copied directly from the native SDK source file BrowserSupportsPush.ts | ||
* S T A R T | ||
*/ | ||
// Checks if the browser supports push notifications by checking if specific | ||
// classes and properties on them exist | ||
function isPushNotificationsSupported() { | ||
return supportsVapidPush() || supportsSafariPush(); | ||
function p() { | ||
return window.top !== window && // isContextIframe | ||
navigator.vendor === "Apple Computer, Inc." && // isSafari | ||
navigator.platform === "MacIntel"; | ||
} | ||
function isMacOSSafariInIframe() { | ||
// Fallback detection for Safari on macOS in an iframe context | ||
return window.top !== window && // isContextIframe | ||
navigator.vendor === "Apple Computer, Inc." && // isSafari | ||
navigator.platform === "MacIntel"; // isMacOS | ||
function S() { | ||
return window.safari && typeof window.safari.pushNotification < "u" || p(); | ||
} | ||
function supportsSafariPush() { | ||
return (window.safari && typeof window.safari.pushNotification !== "undefined") || | ||
isMacOSSafariInIframe(); | ||
function g() { | ||
return typeof PushSubscriptionOptions < "u" && PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey"); | ||
} | ||
// Does the browser support the standard Push API | ||
function supportsVapidPush() { | ||
return typeof PushSubscriptionOptions !== "undefined" && | ||
PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey"); | ||
} | ||
/* E N D */ | ||
/** | ||
* This is a SPECIAL FUNCTION | ||
* It is a hardcoded implementation copied from the upstream/native WebSDK since we want to return a boolean immediately | ||
* Natively, this is done via the shimloading mechanism (i.e. if the SDK loads, push is supported) | ||
* @PublicApi | ||
*/ | ||
const isPushSupported = () => { | ||
return isPushNotificationsSupported(); | ||
const h = () => w(), m = (r) => { | ||
if (d) | ||
return Promise.reject("OneSignal is already initialized."); | ||
if (!r || !r.appId) | ||
throw new Error("You need to provide your OneSignal appId."); | ||
return document ? new Promise((n) => { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.init(r).then(() => { | ||
d = !0, n(); | ||
}); | ||
}); | ||
}) : Promise.reject("Document is not defined."); | ||
}; | ||
/** | ||
* @PublicApi | ||
*/ | ||
const init = (options) => { | ||
if (isOneSignalInitialized) { | ||
return Promise.reject(`OneSignal is already initialized.`); | ||
function O(r, n) { | ||
return new Promise((e, i) => { | ||
var t; | ||
if (s) { | ||
i(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
if (!options || !options.appId) { | ||
throw new Error('You need to provide your OneSignal appId.'); | ||
try { | ||
(t = window.OneSignalDeferred) == null || t.push((o) => { | ||
o.login(r, n).then(() => e()).catch((a) => i(a)); | ||
}); | ||
} catch (o) { | ||
i(o); | ||
} | ||
if (!document) { | ||
return Promise.reject(`Document is not defined.`); | ||
}); | ||
} | ||
function v() { | ||
return new Promise((r, n) => { | ||
var e; | ||
if (s) { | ||
n(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
return new Promise((resolve) => { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.init(options).then(() => { | ||
isOneSignalInitialized = true; | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
function oneSignalLogin(externalId, jwtToken) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.login(externalId, jwtToken).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
try { | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.logout().then(() => r()).catch((t) => n(t)); | ||
}); | ||
} catch (i) { | ||
n(i); | ||
} | ||
}); | ||
} | ||
function oneSignalLogout() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.logout().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function D(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.setConsentGiven(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function oneSignalSetConsentGiven(consent) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.setConsentGiven(consent).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function E(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.setConsentRequired(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function oneSignalSetConsentRequired(requiresConsent) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.setConsentRequired(requiresConsent).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function P(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Slidedown.promptPush(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function slidedownPromptPush(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptPush(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function L(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Slidedown.promptPushCategories(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function slidedownPromptPushCategories(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptPushCategories(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function U(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Slidedown.promptSms(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function slidedownPromptSms(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptSms(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function A(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Slidedown.promptEmail(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function slidedownPromptEmail(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptEmail(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function y(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Slidedown.promptSmsAndEmail(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function slidedownPromptSmsAndEmail(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptSmsAndEmail(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function N(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.Slidedown.addEventListener(r, n); | ||
}); | ||
} | ||
function slidedownAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.addEventListener(event, listener); | ||
}); | ||
function b(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.Slidedown.removeEventListener(r, n); | ||
}); | ||
} | ||
function slidedownRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.removeEventListener(event, listener); | ||
}); | ||
function I(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Notifications.setDefaultUrl(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function notificationsSetDefaultUrl(url) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.setDefaultUrl(url).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function T(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Notifications.setDefaultTitle(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function notificationsSetDefaultTitle(title) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.setDefaultTitle(title).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function R() { | ||
return new Promise((r, n) => { | ||
var e; | ||
if (s) { | ||
n(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.Notifications.requestPermission().then(() => r()).catch((t) => n(t)); | ||
}); | ||
} catch (i) { | ||
n(i); | ||
} | ||
}); | ||
} | ||
function notificationsRequestPermission() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.requestPermission().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function C(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.Notifications.addEventListener(r, n); | ||
}); | ||
} | ||
function notificationsAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.addEventListener(event, listener); | ||
}); | ||
function q(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.Notifications.removeEventListener(r, n); | ||
}); | ||
} | ||
function notificationsRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.removeEventListener(event, listener); | ||
}); | ||
function G(r, n) { | ||
return new Promise((e, i) => { | ||
var t; | ||
if (s) { | ||
i(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(t = window.OneSignalDeferred) == null || t.push((o) => { | ||
o.Session.sendOutcome(r, n).then(() => e()).catch((a) => i(a)); | ||
}); | ||
} catch (o) { | ||
i(o); | ||
} | ||
}); | ||
} | ||
function sessionSendOutcome(outcomeName, outcomeWeight) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Session.sendOutcome(outcomeName, outcomeWeight).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function _(r) { | ||
return new Promise((n, e) => { | ||
var i; | ||
if (s) { | ||
e(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(i = window.OneSignalDeferred) == null || i.push((t) => { | ||
t.Session.sendUniqueOutcome(r).then(() => n()).catch((o) => e(o)); | ||
}); | ||
} catch (t) { | ||
e(t); | ||
} | ||
}); | ||
} | ||
function sessionSendUniqueOutcome(outcomeName) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Session.sendUniqueOutcome(outcomeName).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function k(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.addAlias(r, n); | ||
}); | ||
} | ||
function userAddAlias(label, id) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addAlias(label, id); | ||
}); | ||
function K(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.addAliases(r); | ||
}); | ||
} | ||
function userAddAliases(aliases) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addAliases(aliases); | ||
}); | ||
function x(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.removeAlias(r); | ||
}); | ||
} | ||
function userRemoveAlias(label) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeAlias(label); | ||
}); | ||
function V(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.removeAliases(r); | ||
}); | ||
} | ||
function userRemoveAliases(labels) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeAliases(labels); | ||
}); | ||
function z(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.addEmail(r); | ||
}); | ||
} | ||
function userAddEmail(email) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addEmail(email); | ||
}); | ||
function M(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.removeEmail(r); | ||
}); | ||
} | ||
function userRemoveEmail(email) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeEmail(email); | ||
}); | ||
function F(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.addSms(r); | ||
}); | ||
} | ||
function userAddSms(smsNumber) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addSms(smsNumber); | ||
}); | ||
function Y(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.removeSms(r); | ||
}); | ||
} | ||
function userRemoveSms(smsNumber) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeSms(smsNumber); | ||
}); | ||
function B(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.addTag(r, n); | ||
}); | ||
} | ||
function userAddTag(key, value) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addTag(key, value); | ||
}); | ||
function H(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.addTags(r); | ||
}); | ||
} | ||
function userAddTags(tags) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addTags(tags); | ||
}); | ||
function J(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.removeTag(r); | ||
}); | ||
} | ||
function userRemoveTag(key) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeTag(key); | ||
}); | ||
function Q(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.removeTags(r); | ||
}); | ||
} | ||
function userRemoveTags(keys) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeTags(keys); | ||
}); | ||
function W() { | ||
var n; | ||
let r; | ||
return (n = window.OneSignalDeferred) == null || n.push((e) => { | ||
r = e.User.getTags(); | ||
}), r; | ||
} | ||
function userGetTags() { | ||
var _a; | ||
let retVal; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
retVal = OneSignal.User.getTags(); | ||
}); | ||
return retVal; | ||
function X(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.addEventListener(r, n); | ||
}); | ||
} | ||
function userAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addEventListener(event, listener); | ||
}); | ||
function Z(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.removeEventListener(r, n); | ||
}); | ||
} | ||
function userRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeEventListener(event, listener); | ||
}); | ||
function $(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.User.setLanguage(r); | ||
}); | ||
} | ||
function userSetLanguage(language) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.setLanguage(language); | ||
}); | ||
function j() { | ||
var n; | ||
let r; | ||
return (n = window.OneSignalDeferred) == null || n.push((e) => { | ||
r = e.User.getLanguage(); | ||
}), r; | ||
} | ||
function userGetLanguage() { | ||
var _a; | ||
let retVal; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
retVal = OneSignal.User.getLanguage(); | ||
}); | ||
return retVal; | ||
function ee() { | ||
return new Promise((r, n) => { | ||
var e; | ||
if (s) { | ||
n(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.PushSubscription.optIn().then(() => r()).catch((t) => n(t)); | ||
}); | ||
} catch (i) { | ||
n(i); | ||
} | ||
}); | ||
} | ||
function pushSubscriptionOptIn() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.optIn().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function ne() { | ||
return new Promise((r, n) => { | ||
var e; | ||
if (s) { | ||
n(new Error("OneSignal script failed to load.")); | ||
return; | ||
} | ||
try { | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.PushSubscription.optOut().then(() => r()).catch((t) => n(t)); | ||
}); | ||
} catch (i) { | ||
n(i); | ||
} | ||
}); | ||
} | ||
function pushSubscriptionOptOut() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.optOut().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
function re(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.PushSubscription.addEventListener(r, n); | ||
}); | ||
} | ||
function pushSubscriptionAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.addEventListener(event, listener); | ||
}); | ||
function ie(r, n) { | ||
var e; | ||
(e = window.OneSignalDeferred) == null || e.push((i) => { | ||
i.User.PushSubscription.removeEventListener(r, n); | ||
}); | ||
} | ||
function pushSubscriptionRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.removeEventListener(event, listener); | ||
}); | ||
function te(r) { | ||
var n; | ||
(n = window.OneSignalDeferred) == null || n.push((e) => { | ||
e.Debug.setLogLevel(r); | ||
}); | ||
} | ||
function debugSetLogLevel(logLevel) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Debug.setLogLevel(logLevel); | ||
}); | ||
} | ||
const PushSubscriptionNamespace = { | ||
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; }, | ||
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; }, | ||
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; }, | ||
optIn: pushSubscriptionOptIn, | ||
optOut: pushSubscriptionOptOut, | ||
addEventListener: pushSubscriptionAddEventListener, | ||
removeEventListener: pushSubscriptionRemoveEventListener, | ||
const oe = { | ||
get id() { | ||
var r, n, e; | ||
return (e = (n = (r = window.OneSignal) == null ? void 0 : r.User) == null ? void 0 : n.PushSubscription) == null ? void 0 : e.id; | ||
}, | ||
get token() { | ||
var r, n, e; | ||
return (e = (n = (r = window.OneSignal) == null ? void 0 : r.User) == null ? void 0 : n.PushSubscription) == null ? void 0 : e.token; | ||
}, | ||
get optedIn() { | ||
var r, n, e; | ||
return (e = (n = (r = window.OneSignal) == null ? void 0 : r.User) == null ? void 0 : n.PushSubscription) == null ? void 0 : e.optedIn; | ||
}, | ||
optIn: ee, | ||
optOut: ne, | ||
addEventListener: re, | ||
removeEventListener: ie | ||
}, se = { | ||
get onesignalId() { | ||
var r, n; | ||
return (n = (r = window.OneSignal) == null ? void 0 : r.User) == null ? void 0 : n.onesignalId; | ||
}, | ||
get externalId() { | ||
var r, n; | ||
return (n = (r = window.OneSignal) == null ? void 0 : r.User) == null ? void 0 : n.externalId; | ||
}, | ||
addAlias: k, | ||
addAliases: K, | ||
removeAlias: x, | ||
removeAliases: V, | ||
addEmail: z, | ||
removeEmail: M, | ||
addSms: F, | ||
removeSms: Y, | ||
addTag: B, | ||
addTags: H, | ||
removeTag: J, | ||
removeTags: Q, | ||
getTags: W, | ||
addEventListener: X, | ||
removeEventListener: Z, | ||
setLanguage: $, | ||
getLanguage: j, | ||
PushSubscription: oe | ||
}, ae = { | ||
sendOutcome: G, | ||
sendUniqueOutcome: _ | ||
}, de = { | ||
setLogLevel: te | ||
}, ue = { | ||
promptPush: P, | ||
promptPushCategories: L, | ||
promptSms: U, | ||
promptEmail: A, | ||
promptSmsAndEmail: y, | ||
addEventListener: N, | ||
removeEventListener: b | ||
}, le = { | ||
get permissionNative() { | ||
var r, n; | ||
return ((n = (r = window.OneSignal) == null ? void 0 : r.Notifications) == null ? void 0 : n.permissionNative) ?? "default"; | ||
}, | ||
get permission() { | ||
var r, n; | ||
return ((n = (r = window.OneSignal) == null ? void 0 : r.Notifications) == null ? void 0 : n.permission) ?? !1; | ||
}, | ||
setDefaultUrl: I, | ||
setDefaultTitle: T, | ||
isPushSupported: h, | ||
requestPermission: R, | ||
addEventListener: C, | ||
removeEventListener: q | ||
}, ce = { | ||
login: O, | ||
logout: v, | ||
init: m, | ||
setConsentGiven: D, | ||
setConsentRequired: E, | ||
Slidedown: ue, | ||
Notifications: le, | ||
Session: ae, | ||
User: se, | ||
Debug: de | ||
}, fe = ce; | ||
export { | ||
fe as default | ||
}; | ||
const UserNamespace = { | ||
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; }, | ||
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; }, | ||
addAlias: userAddAlias, | ||
addAliases: userAddAliases, | ||
removeAlias: userRemoveAlias, | ||
removeAliases: userRemoveAliases, | ||
addEmail: userAddEmail, | ||
removeEmail: userRemoveEmail, | ||
addSms: userAddSms, | ||
removeSms: userRemoveSms, | ||
addTag: userAddTag, | ||
addTags: userAddTags, | ||
removeTag: userRemoveTag, | ||
removeTags: userRemoveTags, | ||
getTags: userGetTags, | ||
addEventListener: userAddEventListener, | ||
removeEventListener: userRemoveEventListener, | ||
setLanguage: userSetLanguage, | ||
getLanguage: userGetLanguage, | ||
PushSubscription: PushSubscriptionNamespace, | ||
}; | ||
const SessionNamespace = { | ||
sendOutcome: sessionSendOutcome, | ||
sendUniqueOutcome: sessionSendUniqueOutcome, | ||
}; | ||
const DebugNamespace = { | ||
setLogLevel: debugSetLogLevel, | ||
}; | ||
const SlidedownNamespace = { | ||
promptPush: slidedownPromptPush, | ||
promptPushCategories: slidedownPromptPushCategories, | ||
promptSms: slidedownPromptSms, | ||
promptEmail: slidedownPromptEmail, | ||
promptSmsAndEmail: slidedownPromptSmsAndEmail, | ||
addEventListener: slidedownAddEventListener, | ||
removeEventListener: slidedownRemoveEventListener, | ||
}; | ||
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, | ||
requestPermission: notificationsRequestPermission, | ||
addEventListener: notificationsAddEventListener, | ||
removeEventListener: notificationsRemoveEventListener, | ||
}; | ||
const OneSignalNamespace = { | ||
login: oneSignalLogin, | ||
logout: oneSignalLogout, | ||
init, | ||
setConsentGiven: oneSignalSetConsentGiven, | ||
setConsentRequired: oneSignalSetConsentRequired, | ||
Slidedown: SlidedownNamespace, | ||
Notifications: NotificationsNamespace, | ||
Session: SessionNamespace, | ||
User: UserNamespace, | ||
Debug: DebugNamespace, | ||
}; | ||
const OneSignal = OneSignalNamespace; | ||
export default OneSignal; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,596 +0,2 @@ | ||
'use strict'; | ||
const ONESIGNAL_SDK_ID = 'onesignal-sdk'; | ||
const ONE_SIGNAL_SCRIPT_SRC = "https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js"; | ||
// true if the script is successfully loaded from CDN. | ||
let isOneSignalInitialized = false; | ||
// true if the script fails to load from CDN. A separate flag is necessary | ||
// to disambiguate between a CDN load failure and a delayed call to | ||
// OneSignal#init. | ||
let isOneSignalScriptFailed = false; | ||
if (typeof window !== 'undefined') { | ||
window.OneSignalDeferred = window.OneSignalDeferred || []; | ||
addSDKScript(); | ||
} | ||
/* H E L P E R S */ | ||
function handleOnError() { | ||
isOneSignalScriptFailed = true; | ||
} | ||
function addSDKScript() { | ||
const script = document.createElement('script'); | ||
script.id = ONESIGNAL_SDK_ID; | ||
script.defer = true; | ||
script.src = ONE_SIGNAL_SCRIPT_SRC; | ||
// Always resolve whether or not the script is successfully initialized. | ||
// This is important for users who may block cdn.onesignal.com w/ adblock. | ||
script.onerror = () => { | ||
handleOnError(); | ||
}; | ||
document.head.appendChild(script); | ||
} | ||
/** | ||
* The following code is copied directly from the native SDK source file BrowserSupportsPush.ts | ||
* S T A R T | ||
*/ | ||
// Checks if the browser supports push notifications by checking if specific | ||
// classes and properties on them exist | ||
function isPushNotificationsSupported() { | ||
return supportsVapidPush() || supportsSafariPush(); | ||
} | ||
function isMacOSSafariInIframe() { | ||
// Fallback detection for Safari on macOS in an iframe context | ||
return window.top !== window && // isContextIframe | ||
navigator.vendor === "Apple Computer, Inc." && // isSafari | ||
navigator.platform === "MacIntel"; // isMacOS | ||
} | ||
function supportsSafariPush() { | ||
return (window.safari && typeof window.safari.pushNotification !== "undefined") || | ||
isMacOSSafariInIframe(); | ||
} | ||
// Does the browser support the standard Push API | ||
function supportsVapidPush() { | ||
return typeof PushSubscriptionOptions !== "undefined" && | ||
PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey"); | ||
} | ||
/* E N D */ | ||
/** | ||
* This is a SPECIAL FUNCTION | ||
* It is a hardcoded implementation copied from the upstream/native WebSDK since we want to return a boolean immediately | ||
* Natively, this is done via the shimloading mechanism (i.e. if the SDK loads, push is supported) | ||
* @PublicApi | ||
*/ | ||
const isPushSupported = () => { | ||
return isPushNotificationsSupported(); | ||
}; | ||
/** | ||
* @PublicApi | ||
*/ | ||
const init = (options) => { | ||
if (isOneSignalInitialized) { | ||
return Promise.reject(`OneSignal is already initialized.`); | ||
} | ||
if (!options || !options.appId) { | ||
throw new Error('You need to provide your OneSignal appId.'); | ||
} | ||
if (!document) { | ||
return Promise.reject(`Document is not defined.`); | ||
} | ||
return new Promise((resolve) => { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.init(options).then(() => { | ||
isOneSignalInitialized = true; | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
function oneSignalLogin(externalId, jwtToken) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.login(externalId, jwtToken).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function oneSignalLogout() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.logout().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function oneSignalSetConsentGiven(consent) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.setConsentGiven(consent).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function oneSignalSetConsentRequired(requiresConsent) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.setConsentRequired(requiresConsent).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function slidedownPromptPush(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptPush(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function slidedownPromptPushCategories(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptPushCategories(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function slidedownPromptSms(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptSms(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function slidedownPromptEmail(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptEmail(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function slidedownPromptSmsAndEmail(options) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.promptSmsAndEmail(options).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function slidedownAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.addEventListener(event, listener); | ||
}); | ||
} | ||
function slidedownRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Slidedown.removeEventListener(event, listener); | ||
}); | ||
} | ||
function notificationsSetDefaultUrl(url) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.setDefaultUrl(url).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function notificationsSetDefaultTitle(title) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.setDefaultTitle(title).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function notificationsRequestPermission() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.requestPermission().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function notificationsAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.addEventListener(event, listener); | ||
}); | ||
} | ||
function notificationsRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Notifications.removeEventListener(event, listener); | ||
}); | ||
} | ||
function sessionSendOutcome(outcomeName, outcomeWeight) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Session.sendOutcome(outcomeName, outcomeWeight).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function sessionSendUniqueOutcome(outcomeName) { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Session.sendUniqueOutcome(outcomeName).then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function userAddAlias(label, id) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addAlias(label, id); | ||
}); | ||
} | ||
function userAddAliases(aliases) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addAliases(aliases); | ||
}); | ||
} | ||
function userRemoveAlias(label) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeAlias(label); | ||
}); | ||
} | ||
function userRemoveAliases(labels) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeAliases(labels); | ||
}); | ||
} | ||
function userAddEmail(email) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addEmail(email); | ||
}); | ||
} | ||
function userRemoveEmail(email) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeEmail(email); | ||
}); | ||
} | ||
function userAddSms(smsNumber) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addSms(smsNumber); | ||
}); | ||
} | ||
function userRemoveSms(smsNumber) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeSms(smsNumber); | ||
}); | ||
} | ||
function userAddTag(key, value) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addTag(key, value); | ||
}); | ||
} | ||
function userAddTags(tags) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addTags(tags); | ||
}); | ||
} | ||
function userRemoveTag(key) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeTag(key); | ||
}); | ||
} | ||
function userRemoveTags(keys) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeTags(keys); | ||
}); | ||
} | ||
function userGetTags() { | ||
var _a; | ||
let retVal; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
retVal = OneSignal.User.getTags(); | ||
}); | ||
return retVal; | ||
} | ||
function userAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.addEventListener(event, listener); | ||
}); | ||
} | ||
function userRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.removeEventListener(event, listener); | ||
}); | ||
} | ||
function userSetLanguage(language) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.setLanguage(language); | ||
}); | ||
} | ||
function userGetLanguage() { | ||
var _a; | ||
let retVal; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
retVal = OneSignal.User.getLanguage(); | ||
}); | ||
return retVal; | ||
} | ||
function pushSubscriptionOptIn() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.optIn().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function pushSubscriptionOptOut() { | ||
return new Promise((resolve, reject) => { | ||
var _a; | ||
if (isOneSignalScriptFailed) { | ||
reject(new Error('OneSignal script failed to load.')); | ||
return; | ||
} | ||
try { | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.optOut().then(() => resolve()) | ||
.catch((error) => reject(error)); | ||
}); | ||
} | ||
catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
} | ||
function pushSubscriptionAddEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.addEventListener(event, listener); | ||
}); | ||
} | ||
function pushSubscriptionRemoveEventListener(event, listener) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.User.PushSubscription.removeEventListener(event, listener); | ||
}); | ||
} | ||
function debugSetLogLevel(logLevel) { | ||
var _a; | ||
(_a = window.OneSignalDeferred) === null || _a === void 0 ? void 0 : _a.push((OneSignal) => { | ||
OneSignal.Debug.setLogLevel(logLevel); | ||
}); | ||
} | ||
const PushSubscriptionNamespace = { | ||
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; }, | ||
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; }, | ||
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; }, | ||
optIn: pushSubscriptionOptIn, | ||
optOut: pushSubscriptionOptOut, | ||
addEventListener: pushSubscriptionAddEventListener, | ||
removeEventListener: pushSubscriptionRemoveEventListener, | ||
}; | ||
const UserNamespace = { | ||
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; }, | ||
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; }, | ||
addAlias: userAddAlias, | ||
addAliases: userAddAliases, | ||
removeAlias: userRemoveAlias, | ||
removeAliases: userRemoveAliases, | ||
addEmail: userAddEmail, | ||
removeEmail: userRemoveEmail, | ||
addSms: userAddSms, | ||
removeSms: userRemoveSms, | ||
addTag: userAddTag, | ||
addTags: userAddTags, | ||
removeTag: userRemoveTag, | ||
removeTags: userRemoveTags, | ||
getTags: userGetTags, | ||
addEventListener: userAddEventListener, | ||
removeEventListener: userRemoveEventListener, | ||
setLanguage: userSetLanguage, | ||
getLanguage: userGetLanguage, | ||
PushSubscription: PushSubscriptionNamespace, | ||
}; | ||
const SessionNamespace = { | ||
sendOutcome: sessionSendOutcome, | ||
sendUniqueOutcome: sessionSendUniqueOutcome, | ||
}; | ||
const DebugNamespace = { | ||
setLogLevel: debugSetLogLevel, | ||
}; | ||
const SlidedownNamespace = { | ||
promptPush: slidedownPromptPush, | ||
promptPushCategories: slidedownPromptPushCategories, | ||
promptSms: slidedownPromptSms, | ||
promptEmail: slidedownPromptEmail, | ||
promptSmsAndEmail: slidedownPromptSmsAndEmail, | ||
addEventListener: slidedownAddEventListener, | ||
removeEventListener: slidedownRemoveEventListener, | ||
}; | ||
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, | ||
requestPermission: notificationsRequestPermission, | ||
addEventListener: notificationsAddEventListener, | ||
removeEventListener: notificationsRemoveEventListener, | ||
}; | ||
const OneSignalNamespace = { | ||
login: oneSignalLogin, | ||
logout: oneSignalLogout, | ||
init, | ||
setConsentGiven: oneSignalSetConsentGiven, | ||
setConsentRequired: oneSignalSetConsentRequired, | ||
Slidedown: SlidedownNamespace, | ||
Notifications: NotificationsNamespace, | ||
Session: SessionNamespace, | ||
User: UserNamespace, | ||
Debug: DebugNamespace, | ||
}; | ||
const OneSignal = OneSignalNamespace; | ||
module.exports = OneSignal; | ||
"use strict";const u="onesignal-sdk",l="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js";let d=!1,s=!1;typeof window<"u"&&(window.OneSignalDeferred=window.OneSignalDeferred||[],f());function c(){s=!0}function f(){const r=document.createElement("script");r.id=u,r.defer=!0,r.src=l,r.onerror=()=>{c()},document.head.appendChild(r)}function w(){return g()||S()}function p(){return window.top!==window&&navigator.vendor==="Apple Computer, Inc."&&navigator.platform==="MacIntel"}function S(){return window.safari&&typeof window.safari.pushNotification<"u"||p()}function g(){return typeof PushSubscriptionOptions<"u"&&PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey")}const h=()=>w(),m=r=>{if(d)return Promise.reject("OneSignal is already initialized.");if(!r||!r.appId)throw new Error("You need to provide your OneSignal appId.");return document?new Promise(n=>{var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.init(r).then(()=>{d=!0,n()})})}):Promise.reject("Document is not defined.")};function O(r,n){return new Promise((e,i)=>{var t;if(s){i(new Error("OneSignal script failed to load."));return}try{(t=window.OneSignalDeferred)==null||t.push(o=>{o.login(r,n).then(()=>e()).catch(a=>i(a))})}catch(o){i(o)}})}function v(){return new Promise((r,n)=>{var e;if(s){n(new Error("OneSignal script failed to load."));return}try{(e=window.OneSignalDeferred)==null||e.push(i=>{i.logout().then(()=>r()).catch(t=>n(t))})}catch(i){n(i)}})}function D(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.setConsentGiven(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function E(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.setConsentRequired(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function P(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Slidedown.promptPush(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function L(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Slidedown.promptPushCategories(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function U(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Slidedown.promptSms(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function A(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Slidedown.promptEmail(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function y(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Slidedown.promptSmsAndEmail(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function N(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.Slidedown.addEventListener(r,n)})}function b(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.Slidedown.removeEventListener(r,n)})}function I(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Notifications.setDefaultUrl(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function T(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Notifications.setDefaultTitle(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function R(){return new Promise((r,n)=>{var e;if(s){n(new Error("OneSignal script failed to load."));return}try{(e=window.OneSignalDeferred)==null||e.push(i=>{i.Notifications.requestPermission().then(()=>r()).catch(t=>n(t))})}catch(i){n(i)}})}function C(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.Notifications.addEventListener(r,n)})}function q(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.Notifications.removeEventListener(r,n)})}function G(r,n){return new Promise((e,i)=>{var t;if(s){i(new Error("OneSignal script failed to load."));return}try{(t=window.OneSignalDeferred)==null||t.push(o=>{o.Session.sendOutcome(r,n).then(()=>e()).catch(a=>i(a))})}catch(o){i(o)}})}function _(r){return new Promise((n,e)=>{var i;if(s){e(new Error("OneSignal script failed to load."));return}try{(i=window.OneSignalDeferred)==null||i.push(t=>{t.Session.sendUniqueOutcome(r).then(()=>n()).catch(o=>e(o))})}catch(t){e(t)}})}function k(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.addAlias(r,n)})}function K(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.addAliases(r)})}function x(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.removeAlias(r)})}function V(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.removeAliases(r)})}function z(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.addEmail(r)})}function M(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.removeEmail(r)})}function F(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.addSms(r)})}function Y(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.removeSms(r)})}function B(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.addTag(r,n)})}function H(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.addTags(r)})}function J(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.removeTag(r)})}function Q(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.removeTags(r)})}function W(){var n;let r;return(n=window.OneSignalDeferred)==null||n.push(e=>{r=e.User.getTags()}),r}function X(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.addEventListener(r,n)})}function Z(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.removeEventListener(r,n)})}function $(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.User.setLanguage(r)})}function j(){var n;let r;return(n=window.OneSignalDeferred)==null||n.push(e=>{r=e.User.getLanguage()}),r}function ee(){return new Promise((r,n)=>{var e;if(s){n(new Error("OneSignal script failed to load."));return}try{(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.PushSubscription.optIn().then(()=>r()).catch(t=>n(t))})}catch(i){n(i)}})}function ne(){return new Promise((r,n)=>{var e;if(s){n(new Error("OneSignal script failed to load."));return}try{(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.PushSubscription.optOut().then(()=>r()).catch(t=>n(t))})}catch(i){n(i)}})}function re(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.PushSubscription.addEventListener(r,n)})}function ie(r,n){var e;(e=window.OneSignalDeferred)==null||e.push(i=>{i.User.PushSubscription.removeEventListener(r,n)})}function te(r){var n;(n=window.OneSignalDeferred)==null||n.push(e=>{e.Debug.setLogLevel(r)})}const oe={get id(){var r,n,e;return(e=(n=(r=window.OneSignal)==null?void 0:r.User)==null?void 0:n.PushSubscription)==null?void 0:e.id},get token(){var r,n,e;return(e=(n=(r=window.OneSignal)==null?void 0:r.User)==null?void 0:n.PushSubscription)==null?void 0:e.token},get optedIn(){var r,n,e;return(e=(n=(r=window.OneSignal)==null?void 0:r.User)==null?void 0:n.PushSubscription)==null?void 0:e.optedIn},optIn:ee,optOut:ne,addEventListener:re,removeEventListener:ie},se={get onesignalId(){var r,n;return(n=(r=window.OneSignal)==null?void 0:r.User)==null?void 0:n.onesignalId},get externalId(){var r,n;return(n=(r=window.OneSignal)==null?void 0:r.User)==null?void 0:n.externalId},addAlias:k,addAliases:K,removeAlias:x,removeAliases:V,addEmail:z,removeEmail:M,addSms:F,removeSms:Y,addTag:B,addTags:H,removeTag:J,removeTags:Q,getTags:W,addEventListener:X,removeEventListener:Z,setLanguage:$,getLanguage:j,PushSubscription:oe},ae={sendOutcome:G,sendUniqueOutcome:_},de={setLogLevel:te},ue={promptPush:P,promptPushCategories:L,promptSms:U,promptEmail:A,promptSmsAndEmail:y,addEventListener:N,removeEventListener:b},le={get permissionNative(){var r,n;return((n=(r=window.OneSignal)==null?void 0:r.Notifications)==null?void 0:n.permissionNative)??"default"},get permission(){var r,n;return((n=(r=window.OneSignal)==null?void 0:r.Notifications)==null?void 0:n.permission)??!1},setDefaultUrl:I,setDefaultTitle:T,isPushSupported:h,requestPermission:R,addEventListener:C,removeEventListener:q},ce={login:O,logout:v,init:m,setConsentGiven:D,setConsentRequired:E,Slidedown:ue,Notifications:le,Session:ae,User:se,Debug:de},fe=ce;module.exports=fe; | ||
//# sourceMappingURL=index.js.map |
242
index.ts
@@ -113,12 +113,12 @@ const ONESIGNAL_SDK_ID = 'onesignal-sdk'; | ||
interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; } | ||
interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; } | ||
interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; } | ||
interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; } | ||
type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; }; | ||
type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; }; | ||
type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay'; | ||
type SlidedownEventName = 'slidedownShown'; | ||
type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void; | ||
interface IOSNotification { | ||
export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; } | ||
export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; } | ||
export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; } | ||
export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; } | ||
export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; }; | ||
export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; }; | ||
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay'; | ||
export type SlidedownEventName = 'slidedownShown'; | ||
export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void; | ||
export interface IOSNotification { | ||
/** | ||
@@ -185,3 +185,3 @@ * The OneSignal notification id; | ||
interface IOSNotificationActionButton { | ||
export interface IOSNotificationActionButton { | ||
/** | ||
@@ -207,3 +207,3 @@ * Any unique identifier to represent which button was clicked. This is typically passed back to the service worker | ||
interface NotificationClickResult { | ||
export interface NotificationClickResult { | ||
readonly actionId?: string; | ||
@@ -213,3 +213,3 @@ readonly url?: string; | ||
type NotificationEventTypeMap = { | ||
export type NotificationEventTypeMap = { | ||
'click': NotificationClickEvent; | ||
@@ -222,3 +222,3 @@ 'foregroundWillDisplay': NotificationForegroundWillDisplayEvent; | ||
interface NotificationForegroundWillDisplayEvent { | ||
export interface NotificationForegroundWillDisplayEvent { | ||
readonly notification: IOSNotification; | ||
@@ -228,7 +228,7 @@ preventDefault(): void; | ||
interface NotificationDismissEvent { | ||
export interface NotificationDismissEvent { | ||
notification: IOSNotification; | ||
} | ||
interface NotificationClickEvent { | ||
export interface NotificationClickEvent { | ||
readonly notification: IOSNotification; | ||
@@ -238,6 +238,6 @@ readonly result: NotificationClickResult; | ||
type UserChangeEvent = { | ||
export type UserChangeEvent = { | ||
current: UserNamespaceProperties; | ||
}; | ||
type UserNamespaceProperties = { | ||
export type UserNamespaceProperties = { | ||
onesignalId: string | undefined; | ||
@@ -247,11 +247,193 @@ externalId: string | undefined; | ||
interface IInitObject { | ||
export interface IInitObject { | ||
appId: string; | ||
subdomainName?: string; | ||
requiresUserPrivacyConsent?: boolean; | ||
promptOptions?: object; | ||
welcomeNotification?: object; | ||
notifyButton?: object; | ||
promptOptions?: { | ||
slidedown: { | ||
prompts: { | ||
/** | ||
* Whether to automatically display the prompt. | ||
* `true` will display the prompt based on the delay options. | ||
* `false` will prevent the prompt from displaying until the Slidedowns methods are used. | ||
*/ | ||
autoPrompt: boolean; | ||
/** | ||
* Only available for type: category. Up to 10 categories. | ||
* @example | ||
* categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt. | ||
*/ | ||
categories: { | ||
/** Should identify the action. */ | ||
tag: string; | ||
/** What the user will see. */ | ||
label: string; | ||
}[]; | ||
/** | ||
* The delay options for the prompt. | ||
* @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view. | ||
*/ | ||
delay: { | ||
/** The number of pages a user needs to visit before the prompt is displayed. */ | ||
pageViews?: number; | ||
/** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */ | ||
timeDelay?: number; | ||
}; | ||
/** | ||
* The text to display in the prompt. | ||
*/ | ||
text?: { | ||
/** The callout asking the user to opt-in. Up to 90 characters. */ | ||
actionMessage?: string; | ||
/** Triggers the opt-in. Up to 15 characters. */ | ||
acceptButton?: string; | ||
/** Cancels opt-in. Up to 15 characters. */ | ||
cancelMessage?: string; | ||
/** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */ | ||
confirmMessage?: string; | ||
/** Identifies the email text field. Up to 15 characters. */ | ||
emailLabel?: string; | ||
/** Cancels the category update. Up to 15 characters. */ | ||
negativeUpdateButton?: string; | ||
/** Saves the updated category tags. Up to 15 characters. */ | ||
positiveUpdateButton?: string; | ||
/** Identifies the phone number text field. Up to 15 characters. */ | ||
smsLabel?: string; | ||
/** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */ | ||
updateMessage?: string; | ||
}; | ||
/** | ||
* The type of prompt to display. | ||
* `push` which is the Slide Prompt without categories. | ||
* `category` which is the Slide Prompt with categories. | ||
* `sms` only asks for phone number. | ||
* `email` only asks for email address. | ||
* `smsAndEmail` asks for both phone number and email address. | ||
*/ | ||
type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail'; | ||
}[]; | ||
}; | ||
}; | ||
welcomeNotification?: { | ||
/** | ||
* Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need. | ||
*/ | ||
disabled?: 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. | ||
*/ | ||
message: string; | ||
/** | ||
* 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. | ||
* Set to one space ' ' to clear the title, although this is not recommended. | ||
*/ | ||
title?: string; | ||
/** | ||
* 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; | ||
}; | ||
/** | ||
* Will enable customization of the notify/subscription bell button. | ||
*/ | ||
notifyButton?: { | ||
/** | ||
* A function you define that returns true to show the Subscription Bell, or false to hide it. | ||
* Typically used the hide the Subscription Bell after the user is subscribed. | ||
* This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show. | ||
*/ | ||
displayPredicate?: () => boolean | Promise<boolean>; | ||
/** | ||
* Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default. | ||
*/ | ||
enable?: boolean; | ||
/** Specify CSS-valid pixel offsets using bottom, left, and right. */ | ||
offset?: { bottom: string; left: string; right: string }; | ||
/** | ||
* If `true`, the Subscription Bell will display an icon that there is 1 unread message. | ||
* When hovering over the Subscription Bell, the user will see custom text set by message.prenotify. | ||
*/ | ||
prenotify: boolean; | ||
/** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */ | ||
position?: 'bottom-left' | 'bottom-right'; | ||
/** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */ | ||
showCredit: boolean; | ||
/** | ||
* The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes. | ||
*/ | ||
size?: 'small' | 'medium' | 'large'; | ||
/** Customize the Subscription Bell text. */ | ||
text: { | ||
'dialog.blocked.message': string; | ||
'dialog.blocked.title': string; | ||
'dialog.main.button.subscribe': string; | ||
'dialog.main.button.unsubscribe': string; | ||
'dialog.main.title': string; | ||
'message.action.resubscribed': string; | ||
'message.action.subscribed': string; | ||
'message.action.subscribing': string; | ||
'message.action.unsubscribed': string; | ||
'message.prenotify': string; | ||
'tip.state.blocked': string; | ||
'tip.state.subscribed': string; | ||
'tip.state.unsubscribed': string; | ||
}; | ||
}; | ||
persistNotification?: boolean; | ||
webhooks?: object; | ||
webhooks?: { | ||
/** | ||
* Enable this setting only if your server has CORS enabled and supports non-simple CORS requests. | ||
* If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers. | ||
* The simplest option is to leave it disabled. | ||
* @default false | ||
*/ | ||
cors: boolean; | ||
/** | ||
* This event occurs after a notification is clicked. | ||
* @example https://site.com/hook | ||
*/ | ||
'notification.clicked'?: string; | ||
/** | ||
* 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), | ||
* 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. | ||
* @example https://site.com/hook | ||
*/ | ||
'notification.dismissed'?: string; | ||
/** | ||
* This event occurs after a notification is displayed. | ||
* @example https://site.com/hook | ||
*/ | ||
'notification.willDisplay'?: string; | ||
}; | ||
autoResubscribe?: boolean; | ||
@@ -270,3 +452,3 @@ autoRegister?: boolean; | ||
interface IOneSignalOneSignal { | ||
export interface IOneSignalOneSignal { | ||
Slidedown: IOneSignalSlidedown; | ||
@@ -283,3 +465,3 @@ Notifications: IOneSignalNotifications; | ||
} | ||
interface IOneSignalNotifications { | ||
export interface IOneSignalNotifications { | ||
permissionNative: NotificationPermission; | ||
@@ -294,3 +476,3 @@ permission: boolean; | ||
} | ||
interface IOneSignalSlidedown { | ||
export interface IOneSignalSlidedown { | ||
promptPush(options?: AutoPromptOptions): Promise<void>; | ||
@@ -304,10 +486,10 @@ promptPushCategories(options?: AutoPromptOptions): Promise<void>; | ||
} | ||
interface IOneSignalDebug { | ||
export interface IOneSignalDebug { | ||
setLogLevel(logLevel: string): void; | ||
} | ||
interface IOneSignalSession { | ||
export interface IOneSignalSession { | ||
sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>; | ||
sendUniqueOutcome(outcomeName: string): Promise<void>; | ||
} | ||
interface IOneSignalUser { | ||
export interface IOneSignalUser { | ||
onesignalId: string | undefined; | ||
@@ -334,3 +516,3 @@ externalId: string | undefined; | ||
} | ||
interface IOneSignalPushSubscription { | ||
export interface IOneSignalPushSubscription { | ||
id: string | null | undefined; | ||
@@ -337,0 +519,0 @@ token: string | null | undefined; |
{ | ||
"name": "react-onesignal", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "React OneSignal Module: Make it easy to integrate OneSignal with your React App!", | ||
"author": "rgomezp", | ||
"type": "module", | ||
"contributors": [ | ||
@@ -15,2 +15,5 @@ { | ||
"name": "Graham Marlow" | ||
}, | ||
{ | ||
"name": "Fadi George" | ||
} | ||
@@ -23,60 +26,22 @@ ], | ||
"module": "dist/index.es.js", | ||
"jsnext:main": "dist/index.es.js", | ||
"types": "dist/index.d.ts", | ||
"engines": { | ||
"node": ">=8", | ||
"npm": ">=5" | ||
"node": ">=22", | ||
"npm": ">=10" | ||
}, | ||
"scripts": { | ||
"lint": "./node_modules/.bin/eslint ./src --ext .js,.jsx,.ts,.tsx", | ||
"build": "rollup -c", | ||
"prepare": "yarn run build", | ||
"test": "yarn" | ||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx", | ||
"build": "vite build", | ||
"prepare": "npm run build" | ||
}, | ||
"peerDependencies": { | ||
"react": ">= 16.8" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-external-helpers": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0", | ||
"@babel/plugin-proposal-decorators": "^7.0.0", | ||
"@babel/plugin-proposal-do-expressions": "^7.0.0", | ||
"@babel/plugin-proposal-export-default-from": "^7.0.0", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0", | ||
"@babel/plugin-proposal-function-bind": "^7.0.0", | ||
"@babel/plugin-proposal-function-sent": "^7.0.0", | ||
"@babel/plugin-proposal-json-strings": "^7.0.0", | ||
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0", | ||
"@babel/plugin-proposal-numeric-separator": "^7.0.0", | ||
"@babel/plugin-proposal-optional-chaining": "^7.0.0", | ||
"@babel/plugin-proposal-pipeline-operator": "^7.0.0", | ||
"@babel/plugin-proposal-throw-expressions": "^7.0.0", | ||
"@babel/plugin-syntax-dynamic-import": "^7.0.0", | ||
"@babel/plugin-syntax-import-meta": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@types/jest": "^25.1.2", | ||
"@types/lodash.isequal": "^4.5.5", | ||
"@types/react": "^16.9.19", | ||
"@typescript-eslint/eslint-plugin": "^2.19.0", | ||
"@typescript-eslint/parser": "^2.19.0", | ||
"babel-eslint": "^10.0.1", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb": "^18.0.1", | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-plugin-jsx-a11y": "^6.2.3", | ||
"eslint-plugin-react": "^7.18.3", | ||
"eslint-plugin-react-hooks": "^1.7.0", | ||
"react": "^16.13.1", | ||
"rollup": "^1.1.2", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"rollup-plugin-peer-deps-external": "^2.2.0", | ||
"rollup-plugin-typescript2": "^0.17.0", | ||
"rollup-plugin-url": "^2.1.0", | ||
"typescript": "^3.7.5" | ||
"@typescript-eslint/eslint-plugin": "^5.20.0", | ||
"@typescript-eslint/parser": "^5.20.0", | ||
"eslint": "^8.13.0", | ||
"eslint-plugin-import": "^2.31.0", | ||
"eslint-plugin-jsx-a11y": "^6.10.2", | ||
"eslint-plugin-react": "^7.37.4", | ||
"typescript": "^5.8.2", | ||
"vite": "^6.2.1", | ||
"vite-plugin-dts": "^4.5.3" | ||
}, | ||
@@ -83,0 +48,0 @@ "keywords": [ |
145
README.md
@@ -19,4 +19,4 @@ <h1 align="center">Welcome to react-onesignal 👋</h1> | ||
* 🏠 [Homepage](https://github.com/OneSignal/react-onesignal#readme) | ||
* 🖤 [npm](https://www.npmjs.com/package/react-onesignal) | ||
- 🏠 [Homepage](https://github.com/OneSignal/react-onesignal#readme) | ||
- 🖤 [npm](https://www.npmjs.com/package/react-onesignal) | ||
@@ -28,5 +28,7 @@ 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. | ||
### Migration Guides | ||
Versions 3.0 were recently released and include breaking changes. See the [Migration Guide](https://github.com/OneSignal/react-onesignal/blob/main/MigrationGuide.md) to update your implementation. | ||
Version 3.0 was recently released and includes breaking changes. See the [Migration Guide](https://github.com/OneSignal/react-onesignal/blob/main/MigrationGuide.md) to update your implementation. | ||
## Contents | ||
- [Install](#install) | ||
@@ -38,19 +40,19 @@ - [Usage](#usage) | ||
--- | ||
## Install | ||
You can use `yarn` or `npm`. | ||
### npm | ||
### Yarn | ||
```bash | ||
yarn add react-onesignal | ||
npm install --save react-onesignal | ||
``` | ||
### npm | ||
### yarn | ||
```bash | ||
npm install --save react-onesignal | ||
yarn add react-onesignal | ||
``` | ||
--- | ||
## Usage | ||
@@ -69,2 +71,3 @@ | ||
**Examples** | ||
```js | ||
@@ -74,2 +77,3 @@ await OneSignal.init({ appId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }); | ||
``` | ||
--- | ||
@@ -83,6 +87,7 @@ | ||
// do other stuff | ||
}) | ||
}); | ||
``` | ||
### 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. | ||
@@ -93,21 +98,21 @@ | ||
| 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. | | ||
| 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. | | ||
@@ -119,6 +124,6 @@ **Service Worker Params** | ||
| Field | Details | | ||
|----------------------------|------------------------------------------------------------------------------------------------------------------------| | ||
| `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` | | ||
| `serviceWorkerPath` | The path to the service worker file. | | ||
| Field | Details | | ||
| -------------------- | -------------------------------------------------------------------------------------------------------------------- | | ||
| `serviceWorkerParam` | Use to specify the scope, or the path the service worker has control of. Example: `{ scope: "/js/push/onesignal/" }` | | ||
| `serviceWorkerPath` | The path to the service worker file. | | ||
@@ -130,4 +135,5 @@ </details> | ||
### Service Worker File | ||
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)). | ||
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)). | ||
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). | ||
@@ -139,3 +145,5 @@ | ||
--- | ||
### Typescript | ||
This package includes Typescript support. | ||
@@ -145,12 +153,12 @@ | ||
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>; | ||
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>; | ||
} | ||
@@ -160,32 +168,40 @@ ``` | ||
### OneSignal API | ||
See the official [OneSignal WebSDK reference](https://documentation.onesignal.com/v11.0/docs/web-sdk) for information on all available SDK functions. | ||
--- | ||
## Advanced Usage | ||
### Events and Event Listeners | ||
Use listeners to react to OneSignal-related events: | ||
### Notifications Namespace | ||
| Event Name | Callback Argument Type | | ||
|-|-| | ||
|'click' | NotificationClickEvent| | ||
|'foregroundWillDisplay'| NotificationForegroundWillDisplayEvent | ||
| 'dismiss'| NotificationDismissEvent| | ||
|'permissionChange'| boolean| | ||
|'permissionPromptDisplay'| void| | ||
| Event Name | Callback Argument Type | | ||
| ------------------------- | -------------------------------------- | | ||
| 'click' | NotificationClickEvent | | ||
| 'foregroundWillDisplay' | NotificationForegroundWillDisplayEvent | | ||
| 'dismiss' | NotificationDismissEvent | | ||
| 'permissionChange' | boolean | | ||
| 'permissionPromptDisplay' | void | | ||
### Slidedown Namespace | ||
| Event Name | Callback Argument Type | | ||
|-|-| | ||
|'slidedownShown' | boolean | | ||
| Event Name | Callback Argument Type | | ||
| ---------------- | ---------------------- | | ||
| 'slidedownShown' | boolean | | ||
### Push Subscription Namespace | ||
| Event Name | Callback Argument Type | | ||
|-|-| | ||
|'change' | boolean | | ||
| ---------- | ---------------------- | | ||
| 'change' | boolean | | ||
**Example** | ||
```js | ||
OneSignal.Notifications.addEventListener('click', (event) => { | ||
console.log("The notification was clicked!", event); | ||
console.log('The notification was clicked!', event); | ||
}); | ||
@@ -197,6 +213,9 @@ ``` | ||
## Troubleshooting | ||
### `window.OneSignal already defined as 'object'!` | ||
You will get this error if you initialize twice. Make sure you are only initializing one time. When wrapped with `React.StrictMode`, your app might be rendering twice. | ||
## Example App | ||
This repo includes an `example` React application implementing OneSignal. It was created using `create-react-app`. The app uses this repository's root level directory as the `react-onesignal` package and will bundle any changes on every run. | ||
@@ -216,8 +235,9 @@ | ||
* [Website](https://onesignal.com) | ||
* Twitter: [@onesignal](https://twitter.com/onesignal) | ||
* Github: [@OneSignal](https://github.com/OneSignal) | ||
* LinkedIn: [@onesignal](https://linkedin.com/company/onesignal) | ||
- [Website](https://onesignal.com) | ||
- Twitter: [@onesignal](https://twitter.com/onesignal) | ||
- Github: [@OneSignal](https://github.com/OneSignal) | ||
- LinkedIn: [@onesignal](https://linkedin.com/company/onesignal) | ||
## Discord | ||
Reach out to us via our [Discord server](https://discord.com/invite/EP7gf6Uz7G)! | ||
@@ -231,7 +251,8 @@ | ||
## Thanks | ||
Special thanks to [pedro-lb](https://github.com/pedro-lb) and others for work on the project this package is [based on](https://github.com/pedro-lb/react-onesignal). | ||
<a href="https://github.com/onesignal/react-onesignal/graphs/contributors"> | ||
<img src="https://user-images.githubusercontent.com/11739227/119415383-1d354700-bcb7-11eb-946d-01c40cd07010.png" /> | ||
<img src="https://user-images.githubusercontent.com/11739227/119415383-1d354700-bcb7-11eb-946d-01c40cd07010.png" /> | ||
</a> | ||
Enjoy! |
@@ -5,4 +5,4 @@ { | ||
"module": "esnext", | ||
"target": "es6", | ||
"lib": ["es6", "dom", "es2016", "es2017"], | ||
"target": "es2020", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"sourceMap": true, | ||
@@ -17,3 +17,2 @@ "allowJs": true, | ||
"strictNullChecks": false, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
@@ -20,0 +19,0 @@ "noUnusedParameters": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
213548
1.05%0
-100%9
-78.57%27
3.85%244
9.42%0
-100%Yes
NaN2116
-12.6%