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

onesignal-cordova-plugin

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onesignal-cordova-plugin - npm Package Compare versions

Comparing version

to
5.1.0

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

export { OSInAppMessage, InAppMessageWillDisplayEvent, InAppMessageDidDisplayEvent, InAppMessageWillDismissEvent, InAppMessageDidDismissEvent, InAppMessageClickEvent, InAppMessageClickResult, InAppMessageActionUrlType, } from "./models/InAppMessage";
export { UserState, UserChangedState, } from "./UserNamespace";
export default OneSignal;

@@ -16,6 +16,15 @@ import { NotificationEventName, NotificationEventTypeMap } from "./models/NotificationClicked";

/**
* Sets initial permission value and adds observer for changes
* Sets initial permission value and adds observer for changes.
* This internal method is kept to support the deprecated method {@link hasPermission}.
*/
_setPropertyAndObserver(): void;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getPermissionAsync}.
*/
hasPermission(): boolean;
/**
* Whether this app has push notification permission. Returns true if the user has accepted permissions,
* or if the app has ephemeral or provisional permission.
*/
getPermissionAsync(): Promise<boolean>;
/** iOS Only.

@@ -22,0 +31,0 @@ * Returns the enum for the native permission of the device. It will be one of:

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -25,8 +61,9 @@ exports.OSNotificationPermission = void 0;

/**
* Sets initial permission value and adds observer for changes
* Sets initial permission value and adds observer for changes.
* This internal method is kept to support the deprecated method {@link hasPermission}.
*/
Notifications.prototype._setPropertyAndObserver = function () {
var _this = this;
var getPermissionCallback = function (obj) {
_this._permission = obj.value;
var getPermissionCallback = function (granted) {
_this._permission = granted;
};

@@ -38,5 +75,21 @@ window.cordova.exec(getPermissionCallback, function () { }, "OneSignalPush", "getPermissionInternal");

};
/**
* @deprecated This method is deprecated. It has been replaced by {@link getPermissionAsync}.
*/
Notifications.prototype.hasPermission = function () {
return this._permission || false;
};
/**
* Whether this app has push notification permission. Returns true if the user has accepted permissions,
* or if the app has ephemeral or provisional permission.
*/
Notifications.prototype.getPermissionAsync = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPermissionInternal");
})];
});
});
};
/** iOS Only.

@@ -67,6 +120,2 @@ * Returns the enum for the native permission of the device. It will be one of:

Notifications.prototype.requestPermission = function (fallbackToSettings) {
// if permission already exists, return early as the native call will not resolve
if (this.hasPermission()) {
return Promise.resolve(true);
}
var fallback = fallbackToSettings !== null && fallbackToSettings !== void 0 ? fallbackToSettings : false;

@@ -73,0 +122,0 @@ return new Promise(function (resolve, reject) {

@@ -17,8 +17,29 @@ export interface PushSubscriptionState {

/**
* Sets initial Push Subscription properties and adds observer for changes
* Sets initial Push Subscription properties and adds observer for changes.
* This internal method is kept to support the deprecated methods {@link id}, {@link token}, {@link optedIn}.
*/
_setPropertiesAndObserver(): void;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getIdAsync}.
*/
get id(): string | null | undefined;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getTokenAsync}.
*/
get token(): string | null | undefined;
/**
* @deprecated This method is deprecated. It has been replaced by {@link getOptedInAsync}.
*/
get optedIn(): boolean;
/**
* The readonly push subscription ID.
* @returns {Promise<string | null>}
*/
getIdAsync(): Promise<string | null>;
/**
* The readonly push token.
* @returns {Promise<string | null>}
*/
getTokenAsync(): Promise<string | null>;
/**
* Gets a boolean value indicating whether the current user is opted in to push notifications.

@@ -28,4 +49,5 @@ * This returns true when the app has notifications permission and optOut() is NOT called.

* This boolean may return true but push notifications may still not be received by the user.
* @returns {Promise<boolean>}
*/
get optedIn(): boolean;
getOptedInAsync(): Promise<boolean>;
/**

@@ -32,0 +54,0 @@ * Add a callback that fires when the OneSignal push subscription state changes.

@@ -13,3 +13,4 @@ "use strict";

/**
* Sets initial Push Subscription properties and adds observer for changes
* Sets initial Push Subscription properties and adds observer for changes.
* This internal method is kept to support the deprecated methods {@link id}, {@link token}, {@link optedIn}.
*/

@@ -22,4 +23,4 @@ PushSubscription.prototype._setPropertiesAndObserver = function () {

*/
var getIdCallback = function (obj) {
_this._id = obj.value;
var getIdCallback = function (id) {
_this._id = id;
};

@@ -31,4 +32,4 @@ window.cordova.exec(getIdCallback, function () { }, "OneSignalPush", "getPushSubscriptionId");

*/
var getTokenCallback = function (obj) {
_this._token = obj.value;
var getTokenCallback = function (token) {
_this._token = token;
};

@@ -38,6 +39,6 @@ window.cordova.exec(getTokenCallback, function () { }, "OneSignalPush", "getPushSubscriptionToken");

* Receive opted-in status
* @param obj
* @param granted
*/
var getOptedInCallback = function (obj) {
_this._optedIn = obj.value;
var getOptedInCallback = function (granted) {
_this._optedIn = granted;
};

@@ -52,3 +53,7 @@ window.cordova.exec(getOptedInCallback, function () { }, "OneSignalPush", "getPushSubscriptionOptedIn");

Object.defineProperty(PushSubscription.prototype, "id", {
/**
* @deprecated This method is deprecated. It has been replaced by {@link getIdAsync}.
*/
get: function () {
console.warn("OneSignal: This method has been deprecated. Use getIdAsync instead for getting push subscription id.");
return this._id;

@@ -60,3 +65,7 @@ },

Object.defineProperty(PushSubscription.prototype, "token", {
/**
* @deprecated This method is deprecated. It has been replaced by {@link getTokenAsync}.
*/
get: function () {
console.warn("OneSignal: This method has been deprecated. Use getTokenAsync instead for getting push subscription token.");
return this._token;

@@ -69,8 +78,6 @@ },

/**
* Gets a boolean value indicating whether the current user is opted in to push notifications.
* This returns true when the app has notifications permission and optOut() is NOT called.
* Note: Does not take into account the existence of the subscription ID and push token.
* This boolean may return true but push notifications may still not be received by the user.
* @deprecated This method is deprecated. It has been replaced by {@link getOptedInAsync}.
*/
get: function () {
console.warn("OneSignal: This method has been deprecated. Use getOptedInAsync instead for getting push subscription opted in status.");
return this._optedIn || false;

@@ -82,2 +89,32 @@ },

/**
* The readonly push subscription ID.
* @returns {Promise<string | null>}
*/
PushSubscription.prototype.getIdAsync = function () {
return new Promise(function (resolve, reject) {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPushSubscriptionId");
});
};
/**
* The readonly push token.
* @returns {Promise<string | null>}
*/
PushSubscription.prototype.getTokenAsync = function () {
return new Promise(function (resolve, reject) {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPushSubscriptionToken");
});
};
/**
* Gets a boolean value indicating whether the current user is opted in to push notifications.
* This returns true when the app has notifications permission and optOut() is NOT called.
* Note: Does not take into account the existence of the subscription ID and push token.
* This boolean may return true but push notifications may still not be received by the user.
* @returns {Promise<boolean>}
*/
PushSubscription.prototype.getOptedInAsync = function () {
return new Promise(function (resolve, reject) {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPushSubscriptionOptedIn");
});
};
/**
* Add a callback that fires when the OneSignal push subscription state changes.

@@ -84,0 +121,0 @@ * @param {(event: PushSubscriptionChangedState)=>void} listener

import PushSubscription from "./PushSubscriptionNamespace";
export interface UserState {
onesignalId?: string;
externalId?: string;
}
export interface UserChangedState {
current: UserState;
}
export default class User {
pushSubscription: PushSubscription;
private _userStateObserverList;
private _processFunctionList;
/**

@@ -102,2 +111,25 @@ * Explicitly set a 2-character language code for the user.

}>;
/**
* Add a callback that fires when the OneSignal User state changes.
* Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
* @param {(event: UserChangedState)=>void} listener
* @returns void
*/
addEventListener(event: "change", listener: (event: UserChangedState) => void): void;
/**
* Remove a User State observer that has been previously added.
* @param {(event: UserChangedState)=>void} listener
* @returns void
*/
removeEventListener(event: "change", listener: (event: UserChangedState) => void): void;
/**
* Get the nullable OneSignal Id associated with the current user.
* @returns {Promise<string | null>}
*/
getOnesignalId(): Promise<string | null>;
/**
* Get the nullable External Id associated with the current user.
* @returns {Promise<string | null>}
*/
getExternalId(): Promise<string | null>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -11,3 +47,9 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

this.pushSubscription = new PushSubscriptionNamespace_1.default();
this._userStateObserverList = [];
}
User.prototype._processFunctionList = function (array, param) {
for (var i = 0; i < array.length; i++) {
array[i](param);
}
};
/**

@@ -164,4 +206,55 @@ * Explicitly set a 2-character language code for the user.

;
/**
* Add a callback that fires when the OneSignal User state changes.
* Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
* @param {(event: UserChangedState)=>void} listener
* @returns void
*/
User.prototype.addEventListener = function (event, listener) {
var _this = this;
this._userStateObserverList.push(listener);
var userCallBackProcessor = function (state) {
_this._processFunctionList(_this._userStateObserverList, state);
};
window.cordova.exec(userCallBackProcessor, function () { }, "OneSignalPush", "addUserStateObserver", []);
};
/**
* Remove a User State observer that has been previously added.
* @param {(event: UserChangedState)=>void} listener
* @returns void
*/
User.prototype.removeEventListener = function (event, listener) {
var index = this._userStateObserverList.indexOf(listener);
if (index !== -1) {
this._userStateObserverList.splice(index, 1);
}
};
/**
* Get the nullable OneSignal Id associated with the current user.
* @returns {Promise<string | null>}
*/
User.prototype.getOnesignalId = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
window.cordova.exec(resolve, reject, "OneSignalPush", "getOnesignalId", []);
})];
});
});
};
/**
* Get the nullable External Id associated with the current user.
* @returns {Promise<string | null>}
*/
User.prototype.getExternalId = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
window.cordova.exec(resolve, reject, "OneSignalPush", "getExternalId", []);
})];
});
});
};
return User;
}());
exports.default = User;

@@ -225,4 +225,17 @@ # Cordova v5.0.0 Migration Guide

| `OneSignal.User.getTags();` | *Returns the local tags for the current user.* |
| `OneSignal.User.addEventListener("change", (event: UserChangedState) => void);` <br><br>***See below for usage*** | *Add a User State callback which contains the nullable onesignalId and externalId. The listener will be fired when these values change.* |
| `await OneSignal.User.getOnesignalId();` | *Returns the OneSignal ID for the current user, which can be null if it is not yet available.* |
| `await OneSignal.User.getExternalId();` | *Returns the External ID for the current user, which can be null if not set.* |
### User State Listener
**Cordova/Ionic**
```typescript
const listener = (event: UserChangedState) => {
console.log("User changed: " + (event));
};
OneSignal.User.addEventListener("change", listener);
// Remove the listener
OneSignal.User.removeEventListener("change", listener);
```

@@ -236,5 +249,8 @@ ## Push Subscription Namespace

| -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `let id = OneSignal.User.pushSubscription.id` | *The readonly push subscription ID.* |
| `let token = OneSignal.User.pushSubscription.token` | *The readonly push token.* |
| `let optedIn = OneSignal.User.pushSubscription.optedIn` | *Gets a boolean value indicating whether the current user is opted in to push notifications. This returns `true` when the app has notifications permission and `optOut()` is **not** called. ***Note:*** Does not take into account the existence of the subscription ID and push token. This boolean may return `true` but push notifications may still not be received by the user.* |
| `let id = OneSignal.User.pushSubscription.id` | **DEPRECATED**<br>use `getIdAsync()` |
| `let token = OneSignal.User.pushSubscription.token` | **DEPRECATED**<br>use `getTokenAsync()` |
| `let optedIn = OneSignal.User.pushSubscription.optedIn` | **DEPRECATED**<br>use `getOptedInAsync()` |
| `await OneSignal.User.pushSubscription.getIdAsync()` | *The readonly push subscription ID.* |
| `await OneSignal.User.pushSubscription.getTokenAsync()` | *The readonly push token.* |
| `await OneSignal.User.pushSubscription.getOptedInAsync()` | *Gets a boolean value indicating whether the current user is opted in to push notifications. This returns `true` when the app has notifications permission and `optOut()` is **not** called. ***Note:*** Does not take into account the existence of the subscription ID and push token. This boolean may return `true` but push notifications may still not be received by the user.* |
| `OneSignal.User.pushSubscription.optIn();` | *Call this method to receive push notifications on the device or to resume receiving of push notifications after calling `optOut`. If needed, this method will prompt the user for push notifications permission.* |

@@ -276,3 +292,4 @@ | `OneSignal.User.pushSubscription.optOut();` | *If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can call this method to opt out.* |

|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| `let permission = OneSignal.Notifications.hasPermission()` | *Whether this app has push notification permission.* |
| `let permission = OneSignal.Notifications.hasPermission()` | _**DEPRECATED**<br>use `getPermissionAsync`_ |
| `await OneSignal.Notifications.getPermissionAsync()` | *Whether this app has push notification permission.* |
| `await OneSignal.Notifications.permissionNative()` | *(ios only) Returns the enum for the native permission of the device. It will be one of: NotDetermined, Denied, Authorized, Provisional (only available in iOS 12), Ephemeral (only available in iOS 14)*|

@@ -279,0 +296,0 @@ | `await OneSignal.Notifications.canRequestPermission();` | *Whether attempting to request notification permission will show a prompt. Returns `true` if the device has not been prompted for push notification permission already.* |

{
"version": "5.0.6",
"version": "5.1.0",
"name": "onesignal-cordova-plugin",

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

@@ -18,7 +18,5 @@ <p align="center">

- Ionic: https://documentation.onesignal.com/docs/ionic-sdk-setup
- Phonegap: https://documentation.onesignal.com/docs/phonegap-sdk-setup
- Intel XDK: https://documentation.onesignal.com/docs/intel-xdk-setup
#### API
See OneSignal's [Cordova SDK API](https://documentation.onesignal.com/docs/cordova-sdk) page for a list of all available methods.
See OneSignal's [Client SDK Reference](https://documentation.onesignal.com/docs/sdk-reference) page for a list of all available methods.

@@ -25,0 +23,0 @@ #### Change Log

@@ -143,2 +143,7 @@ /**

export {
UserState,
UserChangedState,
} from "./UserNamespace";
export default OneSignal;

@@ -33,7 +33,8 @@ import { NotificationWillDisplayEvent } from "./NotificationReceivedEvent";

/**
* Sets initial permission value and adds observer for changes
* Sets initial permission value and adds observer for changes.
* This internal method is kept to support the deprecated method {@link hasPermission}.
*/
_setPropertyAndObserver():void {
const getPermissionCallback = (obj: {value: boolean}) => {
this._permission = obj.value;
const getPermissionCallback = (granted: boolean) => {
this._permission = granted;
};

@@ -47,2 +48,5 @@ window.cordova.exec(getPermissionCallback, function(){}, "OneSignalPush", "getPermissionInternal");

/**
* @deprecated This method is deprecated. It has been replaced by {@link getPermissionAsync}.
*/
hasPermission(): boolean {

@@ -52,2 +56,12 @@ return this._permission || false;

/**
* Whether this app has push notification permission. Returns true if the user has accepted permissions,
* or if the app has ephemeral or provisional permission.
*/
async getPermissionAsync(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPermissionInternal");
});
}
/** iOS Only.

@@ -79,6 +93,2 @@ * Returns the enum for the native permission of the device. It will be one of:

requestPermission(fallbackToSettings?: boolean): Promise<boolean> {
// if permission already exists, return early as the native call will not resolve
if (this.hasPermission()) {
return Promise.resolve(true);
}
let fallback = fallbackToSettings ?? false;

@@ -85,0 +95,0 @@

@@ -30,3 +30,4 @@ // Suppress TS warnings about window.cordova

/**
* Sets initial Push Subscription properties and adds observer for changes
* Sets initial Push Subscription properties and adds observer for changes.
* This internal method is kept to support the deprecated methods {@link id}, {@link token}, {@link optedIn}.
*/

@@ -38,4 +39,4 @@ _setPropertiesAndObserver():void {

*/
const getIdCallback = (obj: {value: string}) => {
this._id = obj.value;
const getIdCallback = (id: string) => {
this._id = id;
};

@@ -48,4 +49,4 @@ window.cordova.exec(getIdCallback, function(){}, "OneSignalPush", "getPushSubscriptionId");

*/
const getTokenCallback = (obj: {value: string}) => {
this._token = obj.value;
const getTokenCallback = (token: string) => {
this._token = token;
};

@@ -56,6 +57,6 @@ window.cordova.exec(getTokenCallback, function(){}, "OneSignalPush", "getPushSubscriptionToken");

* Receive opted-in status
* @param obj
* @param granted
*/
const getOptedInCallback = (obj: {value: boolean}) => {
this._optedIn = obj.value;
const getOptedInCallback = (granted: boolean) => {
this._optedIn = granted;
};

@@ -69,13 +70,49 @@ window.cordova.exec(getOptedInCallback, function(){}, "OneSignalPush", "getPushSubscriptionOptedIn");

});
}
/**
* @deprecated This method is deprecated. It has been replaced by {@link getIdAsync}.
*/
get id(): string | null | undefined {
console.warn("OneSignal: This method has been deprecated. Use getIdAsync instead for getting push subscription id.");
return this._id;
}
/**
* @deprecated This method is deprecated. It has been replaced by {@link getTokenAsync}.
*/
get token(): string | null | undefined {
console.warn("OneSignal: This method has been deprecated. Use getTokenAsync instead for getting push subscription token.");
return this._token;
}
/**
* @deprecated This method is deprecated. It has been replaced by {@link getOptedInAsync}.
*/
get optedIn(): boolean {
console.warn("OneSignal: This method has been deprecated. Use getOptedInAsync instead for getting push subscription opted in status.");
return this._optedIn || false;
}
/**
* The readonly push subscription ID.
* @returns {Promise<string | null>}
*/
getIdAsync(): Promise<string | null> {
return new Promise<string | null>((resolve, reject) => {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPushSubscriptionId");
});
}
/**
* The readonly push token.
* @returns {Promise<string | null>}
*/
getTokenAsync(): Promise<string | null> {
return new Promise<string | null>((resolve, reject) => {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPushSubscriptionToken");
});
}
/**
* Gets a boolean value indicating whether the current user is opted in to push notifications.

@@ -85,5 +122,8 @@ * This returns true when the app has notifications permission and optOut() is NOT called.

* This boolean may return true but push notifications may still not be received by the user.
* @returns {Promise<boolean>}
*/
get optedIn(): boolean {
return this._optedIn || false;
getOptedInAsync(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
window.cordova.exec(resolve, reject, "OneSignalPush", "getPushSubscriptionOptedIn");
});
}

@@ -90,0 +130,0 @@

@@ -6,2 +6,12 @@ import PushSubscription from "./PushSubscriptionNamespace";

// Represents the current user state
export interface UserState {
onesignalId ?: string;
externalId ?: string;
}
export interface UserChangedState {
current: UserState;
}
export default class User {

@@ -11,2 +21,10 @@ // The push subscription associated to the current user.

private _userStateObserverList: ((event:UserChangedState)=>void)[] = [];
private _processFunctionList(array: ((event:UserChangedState)=>void)[], param: UserChangedState): void {
for (let i = 0; i < array.length; i++) {
array[i](param);
}
}
/**

@@ -164,2 +182,48 @@ * Explicitly set a 2-character language code for the user.

};
/**
* Add a callback that fires when the OneSignal User state changes.
* Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
* @param {(event: UserChangedState)=>void} listener
* @returns void
*/
addEventListener(event: "change", listener: (event: UserChangedState) => void) {
this._userStateObserverList.push(listener as (event: UserChangedState) => void);
const userCallBackProcessor = (state: UserChangedState) => {
this._processFunctionList(this._userStateObserverList, state);
};
window.cordova.exec(userCallBackProcessor, function(){}, "OneSignalPush", "addUserStateObserver", []);
}
/**
* Remove a User State observer that has been previously added.
* @param {(event: UserChangedState)=>void} listener
* @returns void
*/
removeEventListener(event: "change", listener: (event: UserChangedState) => void) {
let index = this._userStateObserverList.indexOf(listener);
if (index !== -1) {
this._userStateObserverList.splice(index, 1);
}
}
/**
* Get the nullable OneSignal Id associated with the current user.
* @returns {Promise<string | null>}
*/
async getOnesignalId(): Promise<string | null> {
return new Promise<string | null>((resolve, reject) => {
window.cordova.exec(resolve, reject, "OneSignalPush", "getOnesignalId", []);
});
}
/**
* Get the nullable External Id associated with the current user.
* @returns {Promise<string | null>}
*/
async getExternalId(): Promise<string | null> {
return new Promise<string | null>((resolve, reject) => {
window.cordova.exec(resolve, reject, "OneSignalPush", "getExternalId", []);
});
}
}

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

Sorry, the diff of this file is not supported yet