Source: mcs-notifications-cordova-plugin.js

Source: mcs-notifications-cordova-plugin.js

/* global cordova:false 1*/
/**
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
 * Oracle Mobile Hub FCM Cordova plugin, Release: 18.3.3.0, F13788-01
 */
var exec = cordova.require('cordova/exec');


(function(_module, _exports, _define, _window, _global, _self, _this) {
  var MCSNotificationsCordovaPluginGlobal;

  /******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 65);
/******/ })
/************************************************************************/
/******/ ({

/***/ 1:
/***/ (function(module, exports, __webpack_require__) {

"use strict";

/**
 * Copyright© 2016, Oracle and/or its affiliates. All rights reserved.
 * @ignore
 */
Object.defineProperty(exports, "__esModule", { value: true });
var Logger = /** @class */ (function () {
    function Logger(module) {
        this.module = module;
    }
    Logger.prototype.debug = function () {
        var params = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            params[_i] = arguments[_i];
        }
        this.log(Logger.LOG_LEVEL.DEBUG, params);
    };
    Logger.prototype.error = function () {
        var params = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            params[_i] = arguments[_i];
        }
        this.log(Logger.LOG_LEVEL.ERROR, params);
    };
    Logger.prototype.info = function () {
        var params = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            params[_i] = arguments[_i];
        }
        this.log(Logger.LOG_LEVEL.INFO, params);
    };
    Logger.prototype.warn = function () {
        var params = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            params[_i] = arguments[_i];
        }
        this.log(Logger.LOG_LEVEL.WARN, params);
    };
    Logger.prototype.log = function (level, params) {
        if (Logger.logLevel >= level) {
            params.unshift('[mcs.' + this.module + ']');
            var method = void 0;
            switch (Logger.logLevel) {
                case Logger.LOG_LEVEL.ERROR:
                    method = console.error;
                    break;
                case Logger.LOG_LEVEL.WARN:
                    method = console.warn;
                    break;
                case Logger.LOG_LEVEL.INFO:
                    method = console.info;
                    break;
                case Logger.LOG_LEVEL.DEBUG:
                    method = console.debug;
                    break;
            }
            if (Logger.historyEnabled) {
                Logger.history.push(Object.assign({}, params, { level: level }));
                if (Logger.historySize <= Logger.history.length) {
                    Logger.history.shift();
                }
            }
            method.apply(console, params);
        }
    };
    Logger.LOG_LEVEL = {
        NONE: 0,
        ERROR: 1,
        WARN: 2,
        INFO: 3,
        DEBUG: 4,
    };
    Logger.logLevel = Logger.LOG_LEVEL.ERROR;
    Logger.historyEnabled = false;
    Logger.historySize = 100;
    Logger.history = [];
    return Logger;
}());
exports.Logger = Logger;


/***/ }),

/***/ 65:
/***/ (function(module, exports, __webpack_require__) {

"use strict";

/**
 * Copyright© 2017, Oracle and/or its affiliates. All rights reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = __webpack_require__(1);
/**
 * Class responsible for receiving Firebase cloud messaging notifications.
 */
/**
 * @class
 * @global
 * @classdesc Class responsible for receiving Firebase cloud messaging notifications.
 * Callers should use MCSNotificationsCordovaPlugin global object.
 * @hideconstructor
 * @mcs
 */
var MCSNotificationsCordovaPlugin = /** @class */ (function () {
    function MCSNotificationsCordovaPlugin(cordovaExec) {
        this.cordovaExec = cordovaExec;
        this._logger = new logger_1.Logger('MCSNotificationsCordovaPlugin');
    }
    /**
     * Set log level for plugin logger
     * @param {number} level - NONE: 0, ERROR: 1, WARN: 2, INFO: 3, DEBUG: 4
     * @function
     * @name MCSNotificationsCordovaPlugin#setLogLevel
     * @mcs
     */
    MCSNotificationsCordovaPlugin.prototype.setLogLevel = function (level) {
        logger_1.Logger.logLevel = level;
    };
    /**
     * This callback called when error happen.
     * @callback MCSNotificationsCordovaPlugin~errorCallback
     * @param {object} error - error object
     * @mcs
     */
    /**
     * This callback used to retrieve device token.
     * @callback MCSNotificationsCordovaPlugin~tokenRefreshCallback
     * @param {string} token
     * @mcs
     */
    /**
     * Subscribe to token refresh event that called:
     * - to retrieve device token
     * - when the system determines that the device token need to be refreshed.
     * @param {MCSNotificationsCordovaPlugin~tokenRefreshCallback} callback - triggered on the new token received
     * @param {MCSNotificationsCordovaPlugin~errorCallback} [errorCallback] - triggered on the error
     * @function
     * @name MCSNotificationsCordovaPlugin#onTokenRefresh
     * @mcs
     */
    MCSNotificationsCordovaPlugin.prototype.onTokenRefresh = function (callback, errorCallback) {
        if (errorCallback === void 0) { errorCallback = function () { }; }
        if (typeof errorCallback !== 'function') {
            this._logger.error('errorCallback parameter not a function');
            return;
        }
        if (typeof callback !== 'function') {
            this._logger.error('callback parameter not a function');
            return;
        }
        this._exec(callback, errorCallback, MCSNotificationsCordovaPlugin._METHOD.ON_TOKEN_REFRESH, []);
    };
    /**
     * This callback used to retrieve notification messages.
     * @callback MCSNotificationsCordovaPlugin~messageReceivedCallback
     * @param {INotificationMessage} message - notification message
     * @mcs
     */
    /**
     * Subscribe to message received event
     * @param {MCSNotificationsCordovaPlugin~messageReceivedCallback} callback
     * @param {MCSNotificationsCordovaPlugin~errorCallback} [errorCallback] - triggered on the error
     * @function
     * @name MCSNotificationsCordovaPlugin#onMessageReceived
     * @mcs
     */
    MCSNotificationsCordovaPlugin.prototype.onMessageReceived = function (callback, errorCallback) {
        if (errorCallback === void 0) { errorCallback = function () { }; }
        if (typeof errorCallback !== 'function') {
            this._logger.error('errorCallback parameter not a function');
            return;
        }
        if (typeof callback !== 'function') {
            this._logger.error('callback parameter not a function');
            return;
        }
        this._exec(function (message) { return callback(typeof message === 'string' ? JSON.parse(message) : message); }, errorCallback, MCSNotificationsCordovaPlugin._METHOD.ON_MESSAGE_RECEIVED, []);
    };
    /**
     * Log message.
     * @typedef {object} LogMessage
     * @param {string} message - log message
     * @param {string} scope - log scope
     * @param {number} level - log level
     * @private
     */
    /**
     * This callback used to retrieve notification messages.
     * @callback MCSNotificationsCordovaPlugin~logReceivedCallback
     * @param {LogMessage} message - log message
     * @private
     */
    /**
     * Subscribe to log received event
     * @param {MCSNotificationsCordovaPlugin~logReceivedCallback} callback
     * @param {MCSNotificationsCordovaPlugin~errorCallback} [errorCallback] - triggered on the error
     * @function
     * @name MCSNotificationsCordovaPlugin#onLogReceived
     * @private
     */
    MCSNotificationsCordovaPlugin.prototype.onLogReceived = function (callback, errorCallback) {
        if (errorCallback === void 0) { errorCallback = function () { }; }
        if (typeof errorCallback !== 'function') {
            this._logger.error('errorCallback parameter not a function');
            return;
        }
        if (typeof callback !== 'function') {
            this._logger.error('callback parameter not a function');
            return;
        }
        this._exec(function (logMessage) { return callback(typeof logMessage === 'string' ? JSON.parse(logMessage) : logMessage); }, errorCallback, MCSNotificationsCordovaPlugin._METHOD.ON_LOG_RECEIVED, []);
    };
    /**
     * Cancel all notifications in the tray
     * @param callback
     * @param {MCSNotificationsCordovaPlugin~errorCallback} [errorCallback] - triggered on the error
     * @function
     * @name MCSNotificationsCordovaPlugin#cancelAllNotifications
     * @mcs
     */
    MCSNotificationsCordovaPlugin.prototype.cancelAllNotifications = function (callback, errorCallback) {
        if (callback === void 0) { callback = function () { }; }
        if (errorCallback === void 0) { errorCallback = function () { }; }
        this._exec(callback, errorCallback, MCSNotificationsCordovaPlugin._METHOD.CANCEL_ALL_NOTIFICATIONS, []);
    };
    MCSNotificationsCordovaPlugin.prototype._exec = function (successCallback, errorCallback, methodName) {
        var params = [];
        for (var _i = 3; _i < arguments.length; _i++) {
            params[_i - 3] = arguments[_i];
        }
        this.cordovaExec(successCallback, errorCallback, MCSNotificationsCordovaPlugin._PLUGIN_NAME, methodName, params);
    };
    MCSNotificationsCordovaPlugin._METHOD = {
        ON_TOKEN_REFRESH: 'onTokenRefresh',
        ON_MESSAGE_RECEIVED: 'onMessageReceived',
        CANCEL_ALL_NOTIFICATIONS: 'cancelAllNotifications',
        ON_LOG_RECEIVED: 'onLogReceived',
    };
    MCSNotificationsCordovaPlugin._PLUGIN_NAME = 'MCSNotificationsCordovaPlugin';
    return MCSNotificationsCordovaPlugin;
}());
exports.MCSNotificationsCordovaPlugin = MCSNotificationsCordovaPlugin;
MCSNotificationsCordovaPluginGlobal = MCSNotificationsCordovaPlugin;


/***/ })

/******/ });

  // export mcs library
  var __global;
  if (typeof _window !== 'undefined') {
    __global = _window;
  } else if (typeof _global !== 'undefined') {
    __global = _global;
  } else if (typeof _self !== 'undefined') {
    __global = _self;
  } else {
    __global = _this;
  }

  __global.MCSNotificationsCordovaPlugin = new MCSNotificationsCordovaPluginGlobal(exec);

})(typeof module === "undefined" ? undefined : module,
  typeof exports === "undefined" ? undefined : exports,
  typeof define === "undefined" ? undefined : define,
  typeof window === "undefined" ? undefined : window,
  typeof global === "undefined" ? undefined : global,
  typeof self === "undefined" ? undefined : self,
  this);