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

onesignal-cordova-plugin

Package Overview
Dependencies
Maintainers
9
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onesignal-cordova-plugin - npm Package Compare versions

Comparing version 5.0.0-beta-01 to 5.0.0-beta-02

dist/LiveActivitiesNamespace.d.ts

2

dist/DebugNamespace.d.ts

@@ -1,2 +0,2 @@

export declare type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6;
export type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | 6;
export default class Debug {

@@ -3,0 +3,0 @@ /**

@@ -1,34 +0,37 @@

import { InAppMessageAction, InAppMessageLifecycleHandlerObject } from "./models/InAppMessage";
import { InAppMessageEventTypeMap, InAppMessageEventName } from "./models/InAppMessage";
export default class InAppMessages {
private _inAppMessageClickDelegate;
private _onWillDisplayInAppMessageDelegate;
private _onDidDisplayInAppMessageDelegate;
private _onWillDismissInAppMessageDelegate;
private _onDidDismissInAppMessageDelegate;
private _inAppMessageClickListeners;
private _willDisplayInAppMessageListeners;
private _didDisplayInAppMessageListeners;
private _willDismissInAppMessageListeners;
private _didDismissInAppMessageListeners;
private _processFunctionList;
/**
* Set the in-app message click handler.
* @param {(action:InAppMessageAction)=>void} handler
* @returns void
* Add event listeners for In-App Message click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setClickHandler(handler: (action: InAppMessageAction) => void): void;
addEventListener<K extends InAppMessageEventName>(event: K, listener: (event: InAppMessageEventTypeMap[K]) => void): void;
/**
* Set the in-app message lifecycle handler.
* @param {InAppMessageLifecycleHandlerObject} handlerObject
* @returns void
* Remove event listeners for In-App Message click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setLifecycleHandler(handlerObject: InAppMessageLifecycleHandlerObject): void;
removeEventListener<K extends InAppMessageEventName>(event: K, listener: (obj: InAppMessageEventTypeMap[K]) => void): void;
/**
* Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
* @param {string} key
* @param {string | number | boolean} value
* @param {string} value
* @returns void
*/
addTrigger(key: string, value: string | number | boolean): void;
addTrigger(key: string, value: string): void;
/**
* Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
* @param {[key: string]: string | number | boolean} triggers
* @param {[key: string]: string} triggers
* @returns void
*/
addTriggers(triggers: {
[key: string]: string | number | boolean;
[key: string]: string;
}): void;

@@ -35,0 +38,0 @@ /**

@@ -5,64 +5,107 @@ "use strict";

function InAppMessages() {
this._inAppMessageClickDelegate = function (action) { };
this._onWillDisplayInAppMessageDelegate = function (message) { };
this._onDidDisplayInAppMessageDelegate = function (message) { };
this._onWillDismissInAppMessageDelegate = function (message) { };
this._onDidDismissInAppMessageDelegate = function (message) { };
this._inAppMessageClickListeners = [];
this._willDisplayInAppMessageListeners = [];
this._didDisplayInAppMessageListeners = [];
this._willDismissInAppMessageListeners = [];
this._didDismissInAppMessageListeners = [];
}
/**
* Set the in-app message click handler.
* @param {(action:InAppMessageAction)=>void} handler
* @returns void
*/
InAppMessages.prototype.setClickHandler = function (handler) {
var _this = this;
this._inAppMessageClickDelegate = handler;
var inAppMessageClickHandler = function (json) {
_this._inAppMessageClickDelegate(json);
};
window.cordova.exec(inAppMessageClickHandler, function () { }, "OneSignalPush", "setClickHandler", []);
InAppMessages.prototype._processFunctionList = function (array, param) {
for (var i = 0; i < array.length; i++) {
array[i](param);
}
};
;
/**
* Set the in-app message lifecycle handler.
* @param {InAppMessageLifecycleHandlerObject} handlerObject
* @returns void
* Add event listeners for In-App Message click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
InAppMessages.prototype.setLifecycleHandler = function (handlerObject) {
InAppMessages.prototype.addEventListener = function (event, listener) {
var _this = this;
if (handlerObject.onWillDisplayInAppMessage) {
this._onWillDisplayInAppMessageDelegate = handlerObject.onWillDisplayInAppMessage;
var onWillDisplayInAppMessageHandler = function (json) {
_this._onWillDisplayInAppMessageDelegate(json);
if (event === "click") {
this._inAppMessageClickListeners.push(listener);
var inAppMessageClickListener = function (json) {
_this._processFunctionList(_this._inAppMessageClickListeners, json);
};
window.cordova.exec(onWillDisplayInAppMessageHandler, function () { }, "OneSignalPush", "setOnWillDisplayInAppMessageHandler", []);
window.cordova.exec(inAppMessageClickListener, function () { }, "OneSignalPush", "setInAppMessageClickHandler", []);
}
if (handlerObject.onDidDisplayInAppMessage) {
this._onDidDisplayInAppMessageDelegate = handlerObject.onDidDisplayInAppMessage;
var onDidDisplayInAppMessageHandler = function (json) {
_this._onDidDisplayInAppMessageDelegate(json);
else if (event === "willDisplay") {
this._willDisplayInAppMessageListeners.push(listener);
var willDisplayCallBackProcessor = function (event) {
_this._processFunctionList(_this._willDisplayInAppMessageListeners, event);
};
window.cordova.exec(onDidDisplayInAppMessageHandler, function () { }, "OneSignalPush", "setOnDidDisplayInAppMessageHandler", []);
window.cordova.exec(willDisplayCallBackProcessor, function () { }, "OneSignalPush", "setOnWillDisplayInAppMessageHandler", []);
}
if (handlerObject.onWillDismissInAppMessage) {
this._onWillDismissInAppMessageDelegate = handlerObject.onWillDismissInAppMessage;
var onWillDismissInAppMessageHandler = function (json) {
_this._onWillDismissInAppMessageDelegate(json);
else if (event === "didDisplay") {
this._didDisplayInAppMessageListeners.push(listener);
var didDisplayCallBackProcessor = function (event) {
_this._processFunctionList(_this._didDisplayInAppMessageListeners, event);
};
window.cordova.exec(onWillDismissInAppMessageHandler, function () { }, "OneSignalPush", "setOnWillDismissInAppMessageHandler", []);
window.cordova.exec(didDisplayCallBackProcessor, function () { }, "OneSignalPush", "setOnDidDisplayInAppMessageHandler", []);
}
if (handlerObject.onDidDismissInAppMessage) {
this._onDidDismissInAppMessageDelegate = handlerObject.onDidDismissInAppMessage;
var onDidDismissInAppMessageHandler = function (json) {
_this._onDidDismissInAppMessageDelegate(json);
else if (event === "willDismiss") {
this._willDismissInAppMessageListeners.push(listener);
var willDismissInAppMessageProcessor = function (event) {
_this._processFunctionList(_this._willDismissInAppMessageListeners, event);
};
window.cordova.exec(onDidDismissInAppMessageHandler, function () { }, "OneSignalPush", "setOnDidDismissInAppMessageHandler", []);
window.cordova.exec(willDismissInAppMessageProcessor, function () { }, "OneSignalPush", "setOnWillDismissInAppMessageHandler", []);
}
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setLifecycleHandler", []);
else if (event === "didDismiss") {
this._didDismissInAppMessageListeners.push(listener);
var didDismissInAppMessageCallBackProcessor = function (event) {
_this._processFunctionList(_this._didDismissInAppMessageListeners, event);
};
window.cordova.exec(didDismissInAppMessageCallBackProcessor, function () { }, "OneSignalPush", "setOnDidDismissInAppMessageHandler", []);
}
else {
return;
}
};
;
/**
* Remove event listeners for In-App Message click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
InAppMessages.prototype.removeEventListener = function (event, listener) {
if (event === "click") {
var index = this._inAppMessageClickListeners.indexOf(listener);
if (index !== -1) {
this._inAppMessageClickListeners.splice(index, 1);
}
}
else {
if (event === "willDisplay") {
var index = this._willDisplayInAppMessageListeners.indexOf(listener);
if (index !== -1) {
this._willDisplayInAppMessageListeners.splice(index, 1);
}
}
else if (event === "didDisplay") {
var index = this._didDisplayInAppMessageListeners.indexOf(listener);
if (index !== -1) {
this._willDisplayInAppMessageListeners.splice(index, 1);
}
}
else if (event === "willDismiss") {
var index = this._willDismissInAppMessageListeners.indexOf(listener);
if (index !== -1) {
this._willDismissInAppMessageListeners.splice(index, 1);
}
}
else if (event === "didDismiss") {
var index = this._didDismissInAppMessageListeners.indexOf(listener);
if (index !== -1) {
this._didDismissInAppMessageListeners.splice(index, 1);
}
}
else {
return;
}
}
};
/**
* Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
* @param {string} key
* @param {string | number | boolean} value
* @param {string} value
* @returns void

@@ -78,3 +121,3 @@ */

* Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
* @param {[key: string]: string | number | boolean} triggers
* @param {[key: string]: string} triggers
* @returns void

@@ -81,0 +124,0 @@ */

@@ -33,2 +33,3 @@ /**

import Notifications from "./NotificationsNamespace";
import LiveActivities from "./LiveActivitiesNamespace";
export declare class OneSignalPlugin {

@@ -41,2 +42,3 @@ User: User;

Notifications: Notifications;
LiveActivities: LiveActivities;
private _appID;

@@ -73,10 +75,4 @@ /**

*/
setRequiresPrivacyConsent(required: boolean): void;
setConsentRequired(required: boolean): void;
/**
* Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to true prior to the invocation of initialization to ensure compliance.
* @param {(response: boolean) => void} handler
* @returns void
*/
getRequiresPrivacyConsent(handler: (value: boolean) => void): void;
/**
* Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.

@@ -86,31 +82,5 @@ * @param {boolean} granted

*/
setPrivacyConsent(granted: boolean): void;
/**
* Whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.
* @param {(value: boolean) => void} handler
* @returns void
*/
getPrivacyConsent(handler: (value: boolean) => void): void;
/**
* Live Activities
*/
/**
* Enter a live activity
* @param {string} activityId
* @param {string} token
* @param {Function} onSuccess
* @param {Function} onFailure
* @returns void
*/
enterLiveActivity(activityId: string, token: string, onSuccess?: Function, onFailure?: Function): void;
/**
* Exit a live activity
* @param {string} activityId
* @param {Function} onSuccess
* @param {Function} onFailure
* @returns void
*/
exitLiveActivity(activityId: string, onSuccess?: Function, onFailure?: Function): void;
setConsentGiven(granted: boolean): void;
}
declare const OneSignal: OneSignalPlugin;
export default OneSignal;

@@ -39,2 +39,3 @@ "use strict";

var NotificationsNamespace_1 = __importDefault(require("./NotificationsNamespace"));
var LiveActivitiesNamespace_1 = __importDefault(require("./LiveActivitiesNamespace"));
var OneSignalPlugin = /** @class */ (function () {

@@ -48,2 +49,3 @@ function OneSignalPlugin() {

this.Notifications = new NotificationsNamespace_1.default();
this.LiveActivities = new LiveActivitiesNamespace_1.default();
this._appID = "";

@@ -97,16 +99,7 @@ }

*/
OneSignalPlugin.prototype.setRequiresPrivacyConsent = function (required) {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setRequiresPrivacyConsent", [required]);
OneSignalPlugin.prototype.setConsentRequired = function (required) {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setPrivacyConsentRequired", [required]);
};
;
/**
* Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to true prior to the invocation of initialization to ensure compliance.
* @param {(response: boolean) => void} handler
* @returns void
*/
OneSignalPlugin.prototype.getRequiresPrivacyConsent = function (handler) {
window.cordova.exec(handler, function () { }, "OneSignalPush", "getRequiresPrivacyConsent", []);
};
;
/**
* Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.

@@ -116,53 +109,6 @@ * @param {boolean} granted

*/
OneSignalPlugin.prototype.setPrivacyConsent = function (granted) {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setPrivacyConsent", [granted]);
OneSignalPlugin.prototype.setConsentGiven = function (granted) {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setPrivacyConsentGiven", [granted]);
};
;
/**
* Whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.
* @param {(value: boolean) => void} handler
* @returns void
*/
OneSignalPlugin.prototype.getPrivacyConsent = function (handler) {
window.cordova.exec(handler, function () { }, "OneSignalPush", "getPrivacyConsent", []);
};
;
/**
* Live Activities
*/
/**
* Enter a live activity
* @param {string} activityId
* @param {string} token
* @param {Function} onSuccess
* @param {Function} onFailure
* @returns void
*/
OneSignalPlugin.prototype.enterLiveActivity = function (activityId, token, onSuccess, onFailure) {
if (onSuccess == null) {
onSuccess = function () { };
}
if (onFailure == null) {
onFailure = function () { };
}
window.cordova.exec(onSuccess, onFailure, "OneSignalPush", "enterLiveActivity", [activityId, token]);
};
;
/**
* Exit a live activity
* @param {string} activityId
* @param {Function} onSuccess
* @param {Function} onFailure
* @returns void
*/
OneSignalPlugin.prototype.exitLiveActivity = function (activityId, onSuccess, onFailure) {
if (onSuccess == null) {
onSuccess = function () { };
}
if (onFailure == null) {
onFailure = function () { };
}
window.cordova.exec(onSuccess, onFailure, "OneSignalPush", "exitLiveActivity", [activityId]);
};
;
return OneSignalPlugin;

@@ -169,0 +115,0 @@ }());

@@ -1,15 +0,33 @@

export interface InAppMessageAction {
closesMessage: boolean;
isFirstClick: boolean;
clickName?: string;
clickUrl?: string;
export type InAppMessageEventName = "click" | "willDisplay" | "didDisplay" | "willDismiss" | "didDismiss";
export type InAppMessageEventTypeMap = {
click: InAppMessageClickEvent;
willDisplay: InAppMessageWillDisplayEvent;
didDisplay: InAppMessageDidDisplayEvent;
willDismiss: InAppMessageWillDismissEvent;
didDismiss: InAppMessageDidDismissEvent;
};
export interface InAppMessageClickEvent {
message: OSInAppMessage;
result: InAppMessageClickResult;
}
export interface InAppMessageClickResult {
closingMessage: boolean;
actionId?: string;
url?: string;
urlTarget?: string;
}
export interface InAppMessageWillDisplayEvent {
message: OSInAppMessage;
}
export interface InAppMessageDidDisplayEvent {
message: OSInAppMessage;
}
export interface InAppMessageWillDismissEvent {
message: OSInAppMessage;
}
export interface InAppMessageDidDismissEvent {
message: OSInAppMessage;
}
export interface OSInAppMessage {
messageId: string;
}
export interface InAppMessageLifecycleHandlerObject {
onWillDisplayInAppMessage?: (message: OSInAppMessage) => void;
onDidDisplayInAppMessage?: (message: OSInAppMessage) => void;
onWillDismissInAppMessage?: (message: OSInAppMessage) => void;
onDidDismissInAppMessage?: (message: OSInAppMessage) => void;
}
import OSNotification from './OSNotification';
export default class NotificationReceivedEvent {
export default class OSNotificationWillDisplayEvent {
private notification;
constructor(receivedEvent: OSNotification);
complete(notification?: OSNotification): void;
constructor(displayEvent: OSNotification);
preventDefault(): void;
getNotification(): OSNotification;
}

@@ -7,23 +7,15 @@ "use strict";

var OSNotification_1 = __importDefault(require("./OSNotification"));
var NotificationReceivedEvent = /** @class */ (function () {
function NotificationReceivedEvent(receivedEvent) {
this.notification = new OSNotification_1.default(receivedEvent);
var OSNotificationWillDisplayEvent = /** @class */ (function () {
function OSNotificationWillDisplayEvent(displayEvent) {
this.notification = new OSNotification_1.default(displayEvent);
}
NotificationReceivedEvent.prototype.complete = function (notification) {
if (!notification) {
// if the notificationReceivedEvent is null, we want to call the native-side
// complete/completion with null to silence the notification
cordova.exec(function () { }, function () { }, "OneSignalPush", "completeNotification", [this.notification.notificationId, false]);
return;
}
// if the notificationReceivedEvent is not null, we want to pass the specific event
// future: Android side: make the notification modifiable
// iOS & Android: the notification id is associated with the native-side complete handler / completion block
cordova.exec(function () { }, function () { }, "OneSignalPush", "completeNotification", [this.notification.notificationId, true]);
OSNotificationWillDisplayEvent.prototype.preventDefault = function () {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "preventDefault", [this.notification.notificationId]);
return;
};
NotificationReceivedEvent.prototype.getNotification = function () {
OSNotificationWillDisplayEvent.prototype.getNotification = function () {
return this.notification;
};
return NotificationReceivedEvent;
return OSNotificationWillDisplayEvent;
}());
exports.default = NotificationReceivedEvent;
exports.default = OSNotificationWillDisplayEvent;

@@ -1,7 +0,6 @@

import { OpenedEvent } from "./models/NotificationOpened";
import NotificationReceivedEvent from "./NotificationReceivedEvent";
import { NotificationEventName, NotificationEventTypeMap } from "./models/NotificationClicked";
export default class Notifications {
private _permissionObserverList;
private _notificationOpenedDelegate;
private _notificationWillShowInForegroundDelegate;
private _notificationClickedListeners;
private _notificationWillDisplayListeners;
private _processFunctionList;

@@ -56,14 +55,15 @@ private _permission?;

/**
* Sets a handler that will run whenever a notification is opened by the user.
* @param {(openedEvent:OpenedEvent) => void} handler
* @returns void
* Add event listeners for notification click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setNotificationOpenedHandler(handler: (openedEvent: OpenedEvent) => void): void;
addEventListener<K extends NotificationEventName>(event: K, listener: (event: NotificationEventTypeMap[K]) => void): void;
/**
* Sets the handler to run before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification should show or not.
* Note: this runs after the Notification Service Extension which can be used to modify the notification before showing it.
* @param {(event:NotificationReceivedEvent)=>void} handler
* @returns void
* Add event listeners for notification click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setNotificationWillShowInForegroundHandler(handler: (event: NotificationReceivedEvent) => void): void;
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
/**

@@ -70,0 +70,0 @@ * Removes all OneSignal notifications.

@@ -10,4 +10,4 @@ "use strict";

this._permissionObserverList = [];
this._notificationOpenedDelegate = function (notificationOpened) { };
this._notificationWillShowInForegroundDelegate = function (notificationReceived) { };
this._notificationClickedListeners = [];
this._notificationWillDisplayListeners = [];
}

@@ -78,10 +78,10 @@ Notifications.prototype._processFunctionList = function (array, param) {

if (typeof fallbackToSettingsOrHandler === "function") {
// Method was called like promptForPushNotificationsWithUserResponse(handler: function)
// Method was called like requestPermission(handler: function)
handler = fallbackToSettingsOrHandler;
}
else if (typeof fallbackToSettingsOrHandler === "boolean") {
// Method was called like promptForPushNotificationsWithUserResponse(fallbackToSettings: boolean, handler?: function)
// Method was called like requestPermission(fallbackToSettings: boolean, handler?: function)
fallbackToSettings = fallbackToSettingsOrHandler;
}
// Else method was called like promptForPushNotificationsWithUserResponse(), no need to modify
// Else method was called like requestPermission(), no need to modify
var internalCallback = function (response) {

@@ -106,2 +106,3 @@ if (handler) {

};
;
/**

@@ -123,30 +124,53 @@ * iOS Only

/**
* Sets a handler that will run whenever a notification is opened by the user.
* @param {(openedEvent:OpenedEvent) => void} handler
* @returns void
* Add event listeners for notification click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
Notifications.prototype.setNotificationOpenedHandler = function (handler) {
Notifications.prototype.addEventListener = function (event, listener) {
var _this = this;
this._notificationOpenedDelegate = handler;
var notificationOpenedHandler = function (json) {
_this._notificationOpenedDelegate(json);
};
window.cordova.exec(notificationOpenedHandler, function () { }, "OneSignalPush", "setNotificationOpenedHandler", []);
if (event === "click") {
this._notificationClickedListeners.push(listener);
var clickParsingHandler = function (json) {
_this._processFunctionList(_this._notificationClickedListeners, json);
};
window.cordova.exec(clickParsingHandler, function () { }, "OneSignalPush", "addNotificationClickListener", []);
}
else if (event === "foregroundWillDisplay") {
this._notificationWillDisplayListeners.push(listener);
var foregroundParsingHandler = function (notification) {
_this._notificationWillDisplayListeners.forEach(function (listener) {
listener(new NotificationReceivedEvent_1.default(notification));
});
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "proceedWithWillDisplay", [notification.notificationId]);
};
window.cordova.exec(foregroundParsingHandler, function () { }, "OneSignalPush", "addForegroundLifecycleListener", []);
}
else {
return;
}
};
;
/**
* Sets the handler to run before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification should show or not.
* Note: this runs after the Notification Service Extension which can be used to modify the notification before showing it.
* @param {(event:NotificationReceivedEvent)=>void} handler
* @returns void
* Add event listeners for notification click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
Notifications.prototype.setNotificationWillShowInForegroundHandler = function (handler) {
var _this = this;
this._notificationWillShowInForegroundDelegate = handler;
var foregroundParsingHandler = function (notificationReceived) {
_this._notificationWillShowInForegroundDelegate(new NotificationReceivedEvent_1.default(notificationReceived));
};
window.cordova.exec(foregroundParsingHandler, function () { }, "OneSignalPush", "setNotificationWillShowInForegroundHandler", []);
Notifications.prototype.removeEventListener = function (event, listener) {
if (event === "click") {
var index = this._notificationClickedListeners.indexOf(listener);
if (index !== -1) {
this._notificationClickedListeners.splice(index, 1);
}
}
else if (event === "foregroundWillDisplay") {
var index = this._notificationWillDisplayListeners.indexOf(listener);
if (index !== -1) {
this._notificationWillDisplayListeners.splice(index, 1);
}
}
else {
return;
}
};
;
/**

@@ -153,0 +177,0 @@ * Removes all OneSignal notifications.

@@ -36,2 +36,7 @@ export default class OSNotification {

constructor(receivedEvent: OSNotification);
/**
* Display the notification.
* @returns void
*/
display(): void;
}

@@ -22,3 +22,3 @@ "use strict";

}
/// If set, he launch URL will be opened when the user
/// If set, the launch URL will be opened when the user
/// taps on your push notification. You can control

@@ -32,3 +32,3 @@ /// whether or not it opens in an in-app webview or

/// Any buttons you want to add to the notification.
/// The notificationOpened handler will provide an
/// The notificationClick listener will provide an
/// OSNotificationAction object, which will contain

@@ -201,4 +201,12 @@ /// the ID of the Action the user tapped.

}
/**
* Display the notification.
* @returns void
*/
OSNotification.prototype.display = function () {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "displayNotification", [this.notificationId]);
return;
};
return OSNotification;
}());
exports.default = OSNotification;

@@ -1,2 +0,2 @@

# Cordova v5.0.0-beta-01 Migration Guide
# Cordova v5.0.0-beta-02 Migration Guide

@@ -140,3 +140,3 @@ # Intro

Below is a comprehensive reference to the `5.0.0-beta-01` OneSignal Cordova SDK.
Below is a comprehensive reference to the `5.0.0-beta-02` OneSignal Cordova SDK.

@@ -155,4 +155,4 @@ ## OneSignal

| `window.plugins.OneSignal.setLaunchURLsInApp(true);` | *This method can be used to set if launch URLs should be opened in safari or within the application. Set to `true` to launch all notifications with a URL in the app instead of the default web browser. Make sure to call `setLaunchURLsInApp` before the `initialize` call.* |
| `window.plugins.OneSignal.enterLiveActivity("ACTIVITY_ID", "TOKEN");`<br><br>***See below for usage of callbacks***|*Entering a Live Activity associates an `activityId` with a live activity temporary push `token` on OneSignal's server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time.* |
| `window.plugins.OneSignal.exitLiveActivity("ACTIVITY_ID");`<br><br>***See below for usage of callbacks*** |*Exiting a Live activity deletes the association between a customer defined `activityId` with a Live Activity temporary push `token` on OneSignal's server.* |
| `window.plugins.OneSignal.LiveActivities.enter("ACTIVITY_ID", "TOKEN");`<br><br>***See below for usage of callbacks***|*Entering a Live Activity associates an `activityId` with a live activity temporary push `token` on OneSignal's server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time.* |
| `window.plugins.OneSignal.LiveActivities.exit("ACTIVITY_ID");`<br><br>***See below for usage of callbacks*** |*Exiting a Live activity deletes the association between a customer defined `activityId` with a Live Activity temporary push `token` on OneSignal's server.* |

@@ -170,3 +170,3 @@

// Enter a Live Activity
window.plugins.OneSignal.enterLiveActivity("ACTIVITY_ID", "TOKEN", (results) => {
window.plugins.OneSignal.LiveActivities.enter("ACTIVITY_ID", "TOKEN", (results) => {
console.log("Results of entering live activity");

@@ -177,3 +177,3 @@ console.log(results);

// Exit a Live Activity
window.plugins.OneSignal.exitLiveActivity("ACTIVITY_ID", (results) => {
window.plugins.OneSignal.LiveActivities.exit("ACTIVITY_ID", (results) => {
console.log("Results of exiting live activity");

@@ -195,3 +195,3 @@ console.log(results);

| `window.plugins.OneSignal.User.removeAlias("ALIAS_LABEL");` | *Remove an alias from the current user.* |
| `window.plugins.OneSignal.User.removeAliases(["ALIAS_LABEL_01", "ALIAS_LABEL_02"]]` | *Remove aliases from the current user.* |
| `window.plugins.OneSignal.User.removeAliases(["ALIAS_LABEL_01", "ALIAS_LABEL_02"]);` | *Remove aliases from the current user.* |
| `window.plugins.OneSignal.User.addEmail("customer@company.com");` | *Add a new email subscription to the current user.* |

@@ -261,3 +261,3 @@ | `window.plugins.OneSignal.User.removeEmail("customer@company.com");` | *Results in a no-op if the specified email does not exist on the user within the SDK, and no request will be made.* |

| `window.plugins.OneSignal.Notifications.clearAll();` | *Removes all OneSignal notifications.*|
| `window.plugins.OneSignal.Notifications.removeNotification("NOTIFICATION_ID");` | *(Android only) Cancels a single OneSignal notification based on its Android notification integer ID. Use instead of Android's [android.app.NotificationManager.cancel], otherwise the notification will be restored when your app is restarted.*|
| `window.plugins.OneSignal.Notifications.removeNotification(1234567890);` | *(Android only) Cancels a single OneSignal notification based on its Android notification integer ID. Use instead of Android's [android.app.NotificationManager.cancel], otherwise the notification will be restored when your app is restarted.*|
| `window.plugins.OneSignal.Notifications.removeGroupedNotifications("GROUP_KEY");` | *(Android only) Cancels a group of OneSignal notifications with the provided group key. Grouping notifications is a OneSignal concept, there is no [android.app.NotificationManager] equivalent.*|

@@ -268,4 +268,4 @@ | `window.plugins.OneSignal.Notifications.requestPermission();`<br><br>***See below for usage*** | *Prompt the user for permission to receive push notifications. This will display the native system prompt to request push notification permission.* |

| `window.plugins.OneSignal.Notifications.removePermissionObserver(observer;`<br><br>***See below for usage*** | *Remove a push permission observer that has been previously added.*|
| `window.plugins.OneSignal.Notifications.setNotificationWillShowInForegroundHandler(handler);`<br><br>***See below for usage*** | *Sets the handler to run before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification ***should*** show or not.<br><br>***Note:*** this runs ***after*** the [Notification Service Extension](https://documentation.onesignal.com/docs/service-extensions) which can be used to modify the notification before showing it.* |
| `window.plugins.OneSignal.Notifications.setNotificationOpenedHandler();`<br><br>***See below for usage*** | *Sets a handler that will run whenever a notification is opened by the user.*|
| `window.plugins.OneSignal.Notifications.addEventListener("foregroundWillDisplay", async function (event){});`<br><br>***See below for usage*** | *Sets the listener to run before displaying a notification while the app is in focus. Use this listener to read notification data and change it or decide if the notification ***should*** show or not.<br><br>***Note:*** this runs ***after*** the [Notification Service Extension](https://documentation.onesignal.com/docs/service-extensions) which can be used to modify the notification before showing it.* \n Call `removeEventListener("foregroundWillDisplay", listener)` to remove a listener.|
| `window.plugins.OneSignal.Notifications.addEventListener("click", async function (event){});`<br><br>***See below for usage*** | *Sets a listener that will run whenever a notification is clicked by the user.\n Call `removeEventListener("click", listener)` to remove a listener.|*|

@@ -278,3 +278,3 @@ ### Prompt for Push Notification Permission

console.log("User accepted notifications: " + accepted);
});
});
```

@@ -297,18 +297,29 @@

### Notification Will Show in Foreground Handler
### Notification Lifecycle Listener
**Cordova/Ionic**
```typescript
window.plugins.OneSignal.Notifications.setNotificationWillShowInForegroundHandler(function(notificationReceivedEvent) {
notificationReceivedEvent.complete(notificationReceivedEvent.getNotification());
});
let myLifecyleListener = function(event) {
/// Display Notification, preventDefault to not display
event.preventDefault();
// Use notification.display() to display the notification after some async work
event.notification.display();
}
window.plugins.OneSignal.Notifications.addEventListener("foregroundWillDisplay", myLifecyleListener);
// Remove the listener
window.plugins.OneSignal.Notifications.removeEventListener("foregroundWillDisplay", myLifecyleListener);
```
### Notification Opened Handler
### Notification Click Listener
**Cordova/Ionic**
```typescript
window.plugins.OneSignal.Notifications.setNotificationOpenedHandler(function(opened) {
let notificationData = JSON.stringify(opened);
console.log('notificationOpenedCallback: ' + notificationData);
});
let myClickListener = async function(event) {
let notificationData = JSON.stringify(event);
};
window.plugins.OneSignal.Notifications.addEventListener("click", myClickListener);
// Remove the listener
window.plugins.OneSignal.Notifications.removeEventListener("click", myClickListener);
```

@@ -323,2 +334,3 @@

| `window.plugins.OneSignal.Location.isShared();` <br><br>***See below for usage*** | *Whether location is currently shared with OneSignal.*|
| `window.plugins.OneSignal.Location.setShared(true);` | *Enable location sharing.* |
| `window.plugins.OneSignal.Location.requestPermission();` | *Use this method to manually prompt the user for location permissions. This allows for geotagging so you send notifications to users based on location.* |

@@ -342,8 +354,8 @@

|`window.plugins.OneSignal.InAppMessages.addTrigger("triggerKey", "triggerValue");` | *Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).<br><br>If the trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user.* |
| `window.plugins.OneSignal.InAppMessages.addTriggers({"triggerKey1":"triggerValue", "triggerKey2": "triggerValue"});` | *Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).<br><br>If any trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user.* |
| `window.plugins.OneSignal.InAppMessages.addTriggers({"triggerKey1": "triggerValue", "triggerKey2": "triggerValue"});` | *Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user. See [Triggers](https://documentation.onesignal.com/docs/iam-triggers).<br><br>If any trigger key already exists, it will be replaced with the value provided here. Note that triggers are not persisted to the backend. They only exist on the local device and are applicable to the current user.* |
| `window.plugins.OneSignal.InAppMessages.removeTrigger("triggerKey");` | *Remove the trigger with the provided key from the current user.* |
| `window.plugins.OneSignal.InAppMessages.removeTriggers(["triggerKey1", "triggerKey2"]);` | *Remove multiple triggers from the current user.* |
| `window.plugins.OneSignal.InAppMessages.clearTriggers();` | *Clear all triggers from the current user.* |
| ` window.plugins.OneSignal.InAppMessages.setLifecycleHandler(handlerObject);`<br><br>***See below for usage*** | *Set the in-app message lifecycle handler.* |
| `window.plugins.OneSignal.InAppMessages.setClickHandler(handler);`<br><br>***See below for usage*** | *Set the in-app message click handler.* |
| `window.plugins.OneSignal.InAppMessages.addEventListener("eventName", async function (event){});`<br><br>***See below for usage*** | *Set listeners for in-app message lifecycle events. Call `removeEventListener("eventName", listener)` to remove a listener.* |
| `window.plugins.OneSignal.InAppMessages.addEventListener("click", async function (event){});`<br><br>***See below for usage*** | *Set an in-app message click listener. Call `removeEventListener("click", listener)` to remove a listener.* |

@@ -359,32 +371,35 @@ ### In-App Message isPaused method

### In-App Message Click Handler
### In-App Message Click Listener
**Cordova/Ionic**
```typescript
let iamClickCallback = function(result) {
let iamClickAction = JSON.stringify(jsonData);
console.log('iamClickCallback: ' + iamClickAction);
let inAppClickListener = async function(event) {
let clickData = JSON.stringify(event);
console.log("In-App Message Clicked: "+ clickData);
};
window.plugins.OneSignal.InAppMessages.setClickHandler(iamClickCallback);
window.plugins.OneSignal.InAppMessages.addEventListener("click", inAppClickListener);
```
### In-App Message Lifecycle Handler
### In-App Message Lifecycle Listeners
**Cordova/Ionic**
```typescript
window.plugins.OneSignal.InAppMessages.setLifecycleHandler({
onWillDisplayInAppMessage: message => {
console.log("OneSignal: will display IAM: ", message.messageId)
},
onDidDisplayInAppMessage: message => {
console.log("OneSignal: did display IAM: ", message.messageId)
},
onWillDismissInAppMessage: message => {
console.log("OneSignal: will dismiss IAM: ", message.messageId)
},
onDidDismissInAppMessage: message => {
console.log("OneSignal: did dismiss IAM: ", message.messageId)
}
});
let willDisplayListener = async function(event) {
console.log("OneSignal: will display IAM: "+ event.messageId);
};
let didDisplayListener = async function(event) {
console.log("OneSignal: did display IAM: "+ event.messageId);
};
let willDismissListener = async function(event) {
console.log("OneSignal: will dismiss IAM: "+ event.messageId);
};
let didDismissListener = async function(event) {
console.log("OneSignal: did dismiss IAM: "+ event.messageId);
};
// Listeners for each event added separately
window.plugins.OneSignal.InAppMessages.addEventListener("willDisplay", willDisplayListener);
window.plugins.OneSignal.InAppMessages.addEventListener("didDisplay", didDisplayListener);
window.plugins.OneSignal.InAppMessages.addEventListener("willDismiss", willDismissListener);
window.plugins.OneSignal.InAppMessages.addEventListener("didDismiss", didDismissListener);
```

@@ -398,4 +413,4 @@

| ------------------------------------------------ | ---------------------------------------------------------------------------------- |
| `window.plugins.OneSignal.Debug.setLogLevel(6);` | *Sets the log level the OneSignal SDK should be writing to the Xcode log.* |
| `window.plugins.OneSignal.Debug.setAlertLevel(0);` | *Sets the logging level to show as alert dialogs.* |
| `window.plugins.OneSignal.Debug.setLogLevel(6);` | *Sets the log level the OneSignal SDK should be writing to the Xcode log.*\n 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose |
| `window.plugins.OneSignal.Debug.setAlertLevel(0);` | *Sets the logging level to show as alert dialogs.\n 0 = None, 1 = Fatal, 2 = Errors, 3 = Warnings, 4 = Info, 5 = Debug, 6 = Verbose* |

@@ -418,4 +433,2 @@

- Identity Verification
- We will be introducing JWT in a follow up Alpha or Beta release
- User properties may not update correctly when Subscriptions are transferred
- Please report any issues you find with this
- We will be introducing JWT in a followup Alpha or Beta release
{
"version": "5.0.0-beta-01",
"version": "5.0.0-beta-02",
"name": "onesignal-cordova-plugin",

@@ -4,0 +4,0 @@ "cordova_name": "OneSignal Push Notifications",

@@ -1,2 +0,10 @@

import { InAppMessageAction, InAppMessageLifecycleHandlerObject, OSInAppMessage } from "./models/InAppMessage";
import {InAppMessageEventTypeMap,
InAppMessageEventName,
InAppMessageWillDisplayEvent,
InAppMessageDidDisplayEvent,
InAppMessageWillDismissEvent,
InAppMessageDidDismissEvent,
InAppMessageClickEvent,
InAppMessageClickResult
} from "./models/InAppMessage";

@@ -7,76 +15,102 @@ // Suppress TS warnings about window.cordova

export default class InAppMessages {
private _inAppMessageClickDelegate = function (action: InAppMessageAction) {};
private _onWillDisplayInAppMessageDelegate = function(message: OSInAppMessage) {};
private _onDidDisplayInAppMessageDelegate = function(message: OSInAppMessage) {};
private _onWillDismissInAppMessageDelegate = function(message: OSInAppMessage) {};
private _onDidDismissInAppMessageDelegate = function(message: OSInAppMessage) {};
/**
* Set the in-app message click handler.
* @param {(action:InAppMessageAction)=>void} handler
* @returns void
*/
setClickHandler(handler: (action: InAppMessageAction) => void): void {
this._inAppMessageClickDelegate = handler;
private _inAppMessageClickListeners: ((action: InAppMessageClickEvent) => void)[] = [];
private _willDisplayInAppMessageListeners: ((event: InAppMessageWillDisplayEvent) => void) [] = [];
private _didDisplayInAppMessageListeners: ((event: InAppMessageDidDisplayEvent) => void) [] = [];
private _willDismissInAppMessageListeners: ((event: InAppMessageWillDismissEvent) => void) [] = [];
private _didDismissInAppMessageListeners: ((event: InAppMessageDidDismissEvent) => void) [] = [];
const inAppMessageClickHandler = (json: InAppMessageAction) => {
this._inAppMessageClickDelegate(json);
};
private _processFunctionList(array: ((event:any)=>void)[], param: any): void {
for (let i = 0; i < array.length; i++) {
array[i](param);
}
}
window.cordova.exec(inAppMessageClickHandler, function() {}, "OneSignalPush", "setClickHandler", []);
};
/**
* Set the in-app message lifecycle handler.
* @param {InAppMessageLifecycleHandlerObject} handlerObject
* @returns void
* Add event listeners for In-App Message click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setLifecycleHandler(handlerObject: InAppMessageLifecycleHandlerObject) : void {
if (handlerObject.onWillDisplayInAppMessage) {
this._onWillDisplayInAppMessageDelegate = handlerObject.onWillDisplayInAppMessage;
const onWillDisplayInAppMessageHandler = (json: OSInAppMessage) => {
this._onWillDisplayInAppMessageDelegate(json);
addEventListener<K extends InAppMessageEventName>(event: K, listener: (event: InAppMessageEventTypeMap[K]) => void): void {
if (event === "click") {
this._inAppMessageClickListeners.push(listener as (event: InAppMessageClickEvent) => void);
const inAppMessageClickListener = (json: InAppMessageClickResult) => {
this._processFunctionList(this._inAppMessageClickListeners, json);
};
window.cordova.exec(onWillDisplayInAppMessageHandler, function() {}, "OneSignalPush", "setOnWillDisplayInAppMessageHandler", []);
}
if (handlerObject.onDidDisplayInAppMessage) {
this._onDidDisplayInAppMessageDelegate = handlerObject.onDidDisplayInAppMessage;
const onDidDisplayInAppMessageHandler = (json: OSInAppMessage) => {
this._onDidDisplayInAppMessageDelegate(json);
window.cordova.exec(inAppMessageClickListener, function () {}, "OneSignalPush", "setInAppMessageClickHandler", []);
} else if (event === "willDisplay") {
this._willDisplayInAppMessageListeners.push(listener as (event: InAppMessageWillDisplayEvent) => void);
const willDisplayCallBackProcessor = (event: InAppMessageWillDisplayEvent) => {
this._processFunctionList(this._willDisplayInAppMessageListeners, event);
};
window.cordova.exec(onDidDisplayInAppMessageHandler, function() {}, "OneSignalPush", "setOnDidDisplayInAppMessageHandler", []);
}
if (handlerObject.onWillDismissInAppMessage) {
this._onWillDismissInAppMessageDelegate = handlerObject.onWillDismissInAppMessage;
const onWillDismissInAppMessageHandler = (json: OSInAppMessage) => {
this._onWillDismissInAppMessageDelegate(json);
window.cordova.exec(willDisplayCallBackProcessor, function () {}, "OneSignalPush", "setOnWillDisplayInAppMessageHandler", []);
} else if (event === "didDisplay") {
this._didDisplayInAppMessageListeners.push(listener as (event: InAppMessageDidDisplayEvent) => void);
const didDisplayCallBackProcessor = (event: InAppMessageDidDisplayEvent) => {
this._processFunctionList(this._didDisplayInAppMessageListeners, event);
}
window.cordova.exec(didDisplayCallBackProcessor, function () {}, "OneSignalPush", "setOnDidDisplayInAppMessageHandler", []);
} else if (event === "willDismiss") {
this._willDismissInAppMessageListeners.push(listener as (event: InAppMessageWillDismissEvent) => void);
const willDismissInAppMessageProcessor = (event: InAppMessageWillDismissEvent) => {
this._processFunctionList(this._willDismissInAppMessageListeners, event);
};
window.cordova.exec(onWillDismissInAppMessageHandler, function() {}, "OneSignalPush", "setOnWillDismissInAppMessageHandler", []);
}
if (handlerObject.onDidDismissInAppMessage) {
this._onDidDismissInAppMessageDelegate = handlerObject.onDidDismissInAppMessage;
const onDidDismissInAppMessageHandler = (json: OSInAppMessage) => {
this._onDidDismissInAppMessageDelegate(json);
window.cordova.exec(willDismissInAppMessageProcessor, function () {}, "OneSignalPush", "setOnWillDismissInAppMessageHandler", []);
} else if (event === "didDismiss") {
this._didDismissInAppMessageListeners.push(listener as (event: InAppMessageDidDismissEvent) => void);
const didDismissInAppMessageCallBackProcessor = (event: InAppMessageDidDismissEvent) => {
this._processFunctionList(this._didDismissInAppMessageListeners, event);
};
window.cordova.exec(onDidDismissInAppMessageHandler, function() {}, "OneSignalPush", "setOnDidDismissInAppMessageHandler", []);
window.cordova.exec(didDismissInAppMessageCallBackProcessor, function () {}, "OneSignalPush", "setOnDidDismissInAppMessageHandler", []);
} else {
return;
}
}
/**
* Remove event listeners for In-App Message click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
removeEventListener<K extends InAppMessageEventName>(event: K, listener: (obj: InAppMessageEventTypeMap[K]) => void): void {
if (event === "click") {
const index = this._inAppMessageClickListeners.indexOf(listener);
if (index !== -1) {
this._inAppMessageClickListeners.splice(index, 1);
}
} else {
if (event === "willDisplay") {
let index = this._willDisplayInAppMessageListeners.indexOf(listener as (event: InAppMessageWillDisplayEvent) => void);
if (index !== -1) {
this._willDisplayInAppMessageListeners.splice(index, 1);
}
} else if (event === "didDisplay") {
let index = this._didDisplayInAppMessageListeners.indexOf(listener as (event: InAppMessageDidDisplayEvent) => void);
if (index !== -1) {
this._willDisplayInAppMessageListeners.splice(index, 1);
}
} else if (event === "willDismiss") {
let index = this._willDismissInAppMessageListeners.indexOf(listener as (event: InAppMessageWillDismissEvent) => void);
if (index !== -1) {
this._willDismissInAppMessageListeners.splice(index, 1);
}
} else if (event === "didDismiss") {
let index = this._didDismissInAppMessageListeners.indexOf(listener as (event: InAppMessageDidDismissEvent) => void);
if (index !== -1) {
this._didDismissInAppMessageListeners.splice(index, 1);
}
} else {
return;
}
}
}
window.cordova.exec(function() {}, function() {}, "OneSignalPush", "setLifecycleHandler", []);
};
/**
* Add a trigger for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
* @param {string} key
* @param {string | number | boolean} value
* @param {string} value
* @returns void
*/
addTrigger(key: string, value: string | number | boolean): void {
addTrigger(key: string, value: string): void {
const obj = {[key]: value};

@@ -88,7 +122,7 @@ this.addTriggers(obj);

* Add multiple triggers for the current user. Triggers are currently explicitly used to determine whether a specific IAM should be displayed to the user.
* @param {[key: string]: string | number | boolean} triggers
* @param {[key: string]: string} triggers
* @returns void
*/
addTriggers(triggers: {[key: string]: string | number | boolean}): void {
addTriggers(triggers: {[key: string]: string}): void {
Object.keys(triggers).forEach(function(key){

@@ -120,3 +154,3 @@ // forces values to be string types

if (!Array.isArray(keys)) {
console.error("OneSignal: removeTriggers: argument must be of type Array")
console.error("OneSignal: removeTriggers: argument must be of type Array");
}

@@ -123,0 +157,0 @@

@@ -34,2 +34,3 @@ /**

import Notifications from "./NotificationsNamespace";
import LiveActivities from "./LiveActivitiesNamespace";

@@ -46,2 +47,3 @@ // Suppress TS warnings about window.cordova

Notifications: Notifications = new Notifications();
LiveActivities: LiveActivities = new LiveActivities();

@@ -99,16 +101,7 @@ private _appID = "";

*/
setRequiresPrivacyConsent(required: boolean): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setRequiresPrivacyConsent", [required]);
setConsentRequired(required: boolean): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setPrivacyConsentRequired", [required]);
};
/**
* Determines whether a user must consent to privacy prior to their user data being sent up to OneSignal. This should be set to true prior to the invocation of initialization to ensure compliance.
* @param {(response: boolean) => void} handler
* @returns void
*/
getRequiresPrivacyConsent(handler: (value: boolean) => void): void {
window.cordova.exec(handler, function () { }, "OneSignalPush", "getRequiresPrivacyConsent", []);
};
/**
* Indicates whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.

@@ -118,57 +111,5 @@ * @param {boolean} granted

*/
setPrivacyConsent(granted: boolean): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setPrivacyConsent", [granted]);
setConsentGiven(granted: boolean): void {
window.cordova.exec(function () { }, function () { }, "OneSignalPush", "setPrivacyConsentGiven", [granted]);
};
/**
* Whether privacy consent has been granted. This field is only relevant when the application has opted into data privacy protections.
* @param {(value: boolean) => void} handler
* @returns void
*/
getPrivacyConsent(handler: (value: boolean) => void): void {
window.cordova.exec(handler, function () { }, "OneSignalPush", "getPrivacyConsent", []);
};
/**
* Live Activities
*/
/**
* Enter a live activity
* @param {string} activityId
* @param {string} token
* @param {Function} onSuccess
* @param {Function} onFailure
* @returns void
*/
enterLiveActivity(activityId: string, token: string, onSuccess?: Function, onFailure?: Function): void {
if (onSuccess == null) {
onSuccess = function() {};
}
if (onFailure == null) {
onFailure = function() {};
}
window.cordova.exec(onSuccess, onFailure, "OneSignalPush", "enterLiveActivity", [activityId, token]);
};
/**
* Exit a live activity
* @param {string} activityId
* @param {Function} onSuccess
* @param {Function} onFailure
* @returns void
*/
exitLiveActivity(activityId: string, onSuccess?: Function, onFailure?: Function): void {
if (onSuccess == null) {
onSuccess = function() {};
}
if (onFailure == null) {
onFailure = function() {};
}
window.cordova.exec(onSuccess, onFailure, "OneSignalPush", "exitLiveActivity", [activityId]);
};
}

@@ -175,0 +116,0 @@

@@ -1,21 +0,41 @@

export interface InAppMessageAction {
closesMessage : boolean;
isFirstClick : boolean;
clickName ?: string;
clickUrl ?: string;
// Not currently exposed in Android 5.0.0-beta1
// outcomes ?: object[];
// tags ?: object;
export type InAppMessageEventName = "click" | "willDisplay" | "didDisplay" | "willDismiss" | "didDismiss";
export type InAppMessageEventTypeMap = {
click: InAppMessageClickEvent;
willDisplay: InAppMessageWillDisplayEvent;
didDisplay: InAppMessageDidDisplayEvent;
willDismiss: InAppMessageWillDismissEvent;
didDismiss: InAppMessageDidDismissEvent;
};
export interface InAppMessageClickEvent {
message : OSInAppMessage
result : InAppMessageClickResult
}
export interface InAppMessageClickResult {
closingMessage : boolean;
actionId ?: string;
url ?: string;
urlTarget ?: string;
}
export interface InAppMessageWillDisplayEvent {
message : OSInAppMessage
}
export interface InAppMessageDidDisplayEvent {
message : OSInAppMessage
}
export interface InAppMessageWillDismissEvent {
message : OSInAppMessage
}
export interface InAppMessageDidDismissEvent {
message : OSInAppMessage
}
export interface OSInAppMessage {
messageId : string
}
export interface InAppMessageLifecycleHandlerObject {
onWillDisplayInAppMessage ?: (message: OSInAppMessage) => void;
onDidDisplayInAppMessage ?: (message: OSInAppMessage) => void;
onWillDismissInAppMessage ?: (message: OSInAppMessage) => void;
onDidDismissInAppMessage ?: (message: OSInAppMessage) => void;
}
import OSNotification from './OSNotification';
declare let cordova: any;
// Suppress TS warnings about window.cordova
export default class NotificationReceivedEvent {
declare let window: any; // turn off type checking
export default class OSNotificationWillDisplayEvent {
private notification: OSNotification;
constructor(receivedEvent: OSNotification) {
this.notification = new OSNotification(receivedEvent);
constructor(displayEvent: OSNotification) {
this.notification = new OSNotification(displayEvent);
}
complete(notification?: OSNotification): void {
if (!notification) {
// if the notificationReceivedEvent is null, we want to call the native-side
// complete/completion with null to silence the notification
cordova.exec(function(){}, function(){}, "OneSignalPush", "completeNotification", [this.notification.notificationId, false]);
return;
}
// if the notificationReceivedEvent is not null, we want to pass the specific event
// future: Android side: make the notification modifiable
// iOS & Android: the notification id is associated with the native-side complete handler / completion block
cordova.exec(function(){}, function(){}, "OneSignalPush", "completeNotification", [this.notification.notificationId, true]);
preventDefault(): void {
window.cordova.exec(function(){}, function(){}, "OneSignalPush", "preventDefault", [this.notification.notificationId]);
return;
}

@@ -24,0 +19,0 @@

@@ -1,4 +0,7 @@

import { OpenedEvent } from "./models/NotificationOpened";
import NotificationReceivedEvent from "./NotificationReceivedEvent";
import OSNotificationWillDisplayEvent from "./NotificationReceivedEvent";
import OSNotification from './OSNotification';
import { NotificationEventName,
NotificationEventTypeMap,
ClickedEvent
} from "./models/NotificationClicked";

@@ -10,6 +13,6 @@ // Suppress TS warnings about window.cordova

private _permissionObserverList: ((event:boolean)=>void)[] = [];
private _notificationOpenedDelegate = function(notificationOpened: OpenedEvent) {};
private _notificationWillShowInForegroundDelegate = function(notificationReceived: NotificationReceivedEvent) {};
private _notificationClickedListeners: ((action: ClickedEvent) => void)[] = [];
private _notificationWillDisplayListeners: ((notification: OSNotificationWillDisplayEvent) => void)[] = [];
private _processFunctionList(array: ((event:boolean)=>void)[], param: boolean): void {
private _processFunctionList(array: ((event:any)=>void)[], param: any): void {
for (let i = 0; i < array.length; i++) {

@@ -80,10 +83,10 @@ array[i](param);

if (typeof fallbackToSettingsOrHandler === "function") {
// Method was called like promptForPushNotificationsWithUserResponse(handler: function)
// Method was called like requestPermission(handler: function)
handler = fallbackToSettingsOrHandler;
}
else if (typeof fallbackToSettingsOrHandler === "boolean") {
// Method was called like promptForPushNotificationsWithUserResponse(fallbackToSettings: boolean, handler?: function)
// Method was called like requestPermission(fallbackToSettings: boolean, handler?: function)
fallbackToSettings = fallbackToSettingsOrHandler;
}
// Else method was called like promptForPushNotificationsWithUserResponse(), no need to modify
// Else method was called like requestPermission(), no need to modify

@@ -109,3 +112,3 @@ const internalCallback = (response: boolean) => {

window.cordova.exec(canRequestPermissionCallback, function(){}, "OneSignalPush", "canRequestPermission", []);
}
};

@@ -129,32 +132,50 @@ /**

/**
* Sets a handler that will run whenever a notification is opened by the user.
* @param {(openedEvent:OpenedEvent) => void} handler
* @returns void
* Add event listeners for notification click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setNotificationOpenedHandler(handler: (openedEvent: OpenedEvent) => void): void {
this._notificationOpenedDelegate = handler;
const notificationOpenedHandler = (json: OpenedEvent) => {
this._notificationOpenedDelegate(json);
};
window.cordova.exec(notificationOpenedHandler, function(){}, "OneSignalPush", "setNotificationOpenedHandler", []);
};
addEventListener<K extends NotificationEventName>(event: K, listener: (event: NotificationEventTypeMap[K]) => void): void {
if (event === "click") {
this._notificationClickedListeners.push(listener as (event: ClickedEvent) => void);
const clickParsingHandler = (json: ClickedEvent) => {
this._processFunctionList(this._notificationClickedListeners, json);
};
window.cordova.exec(clickParsingHandler, function(){}, "OneSignalPush", "addNotificationClickListener", []);
} else if (event === "foregroundWillDisplay") {
this._notificationWillDisplayListeners.push(listener as (event: OSNotificationWillDisplayEvent) => void);
const foregroundParsingHandler = (notification: OSNotification) => {
this._notificationWillDisplayListeners.forEach(listener => {
listener(new OSNotificationWillDisplayEvent(notification));
});
window.cordova.exec(function(){}, function(){}, "OneSignalPush", "proceedWithWillDisplay", [notification.notificationId]);
};
window.cordova.exec(foregroundParsingHandler, function(){}, "OneSignalPush", "addForegroundLifecycleListener", []);
} else {
return;
}
}
/**
* Sets the handler to run before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification should show or not.
* Note: this runs after the Notification Service Extension which can be used to modify the notification before showing it.
* @param {(event:NotificationReceivedEvent)=>void} handler
* @returns void
* Add event listeners for notification click and/or lifecycle events.
* @param event
* @param listener
* @returns
*/
setNotificationWillShowInForegroundHandler(handler: (event: NotificationReceivedEvent) => void): void {
this._notificationWillShowInForegroundDelegate = handler;
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void {
if (event === "click") {
let index = this._notificationClickedListeners.indexOf(listener as (ClickedEvent: ClickedEvent) => void);
if (index !== -1) {
this._notificationClickedListeners.splice(index, 1);
}
} else if (event === "foregroundWillDisplay") {
let index = this._notificationWillDisplayListeners.indexOf(listener as (event: OSNotificationWillDisplayEvent) => void);
if (index !== -1) {
this._notificationWillDisplayListeners.splice(index, 1);
}
} else {
return;
}
}
const foregroundParsingHandler = (notificationReceived: OSNotification) => {
this._notificationWillShowInForegroundDelegate(new NotificationReceivedEvent(notificationReceived));
};
window.cordova.exec(foregroundParsingHandler, function(){}, "OneSignalPush", "setNotificationWillShowInForegroundHandler", []);
};
/**

@@ -161,0 +182,0 @@ * Removes all OneSignal notifications.

@@ -0,1 +1,6 @@

declare let cordova: any;
// Suppress TS warnings about window.cordova
declare let window: any; // turn off type checking
export default class OSNotification {

@@ -60,3 +65,3 @@ body : string;

/// If set, he launch URL will be opened when the user
/// If set, the launch URL will be opened when the user
/// taps on your push notification. You can control

@@ -72,3 +77,3 @@ /// whether or not it opens in an in-app webview or

/// Any buttons you want to add to the notification.
/// The notificationOpened handler will provide an
/// The notificationClick listener will provide an
/// OSNotificationAction object, which will contain

@@ -268,2 +273,11 @@ /// the ID of the Action the user tapped.

}
/**
* Display the notification.
* @returns void
*/
display(): void {
window.cordova.exec(function(){}, function(){}, "OneSignalPush", "displayNotification", [this.notificationId]);
return;
}
}

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc