UNPKG

pubnub

Version:

Publish & Subscribe Real-time Messaging with PubNub

1,550 lines (1,297 loc) 572 kB
/*! 4.32.1 / Consumer */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else if(typeof exports === 'object') exports["PubNub"] = factory(); else root["PubNub"] = factory(); })(window, function() { return /******/ (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, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // 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 = 27); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } module.exports = _interopRequireDefault; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _default = { PNTimeOperation: 'PNTimeOperation', PNHistoryOperation: 'PNHistoryOperation', PNDeleteMessagesOperation: 'PNDeleteMessagesOperation', PNFetchMessagesOperation: 'PNFetchMessagesOperation', PNMessageCounts: 'PNMessageCountsOperation', PNSubscribeOperation: 'PNSubscribeOperation', PNUnsubscribeOperation: 'PNUnsubscribeOperation', PNPublishOperation: 'PNPublishOperation', PNSignalOperation: 'PNSignalOperation', PNAddMessageActionOperation: 'PNAddActionOperation', PNRemoveMessageActionOperation: 'PNRemoveMessageActionOperation', PNGetMessageActionsOperation: 'PNGetMessageActionsOperation', PNCreateUserOperation: 'PNCreateUserOperation', PNUpdateUserOperation: 'PNUpdateUserOperation', PNDeleteUserOperation: 'PNDeleteUserOperation', PNGetUserOperation: 'PNGetUsersOperation', PNGetUsersOperation: 'PNGetUsersOperation', PNCreateSpaceOperation: 'PNCreateSpaceOperation', PNUpdateSpaceOperation: 'PNUpdateSpaceOperation', PNDeleteSpaceOperation: 'PNDeleteSpaceOperation', PNGetSpaceOperation: 'PNGetSpacesOperation', PNGetSpacesOperation: 'PNGetSpacesOperation', PNGetMembersOperation: 'PNGetMembersOperation', PNUpdateMembersOperation: 'PNUpdateMembersOperation', PNGetMembershipsOperation: 'PNGetMembershipsOperation', PNUpdateMembershipsOperation: 'PNUpdateMembershipsOperation', PNListFilesOperation: 'PNListFilesOperation', PNGenerateUploadUrlOperation: 'PNGenerateUploadUrlOperation', PNPublishFileOperation: 'PNPublishFileOperation', PNGetFileUrlOperation: 'PNGetFileUrlOperation', PNDownloadFileOperation: 'PNDownloadFileOperation', PNGetAllUUIDMetadataOperation: 'PNGetAllUUIDMetadataOperation', PNGetUUIDMetadataOperation: 'PNGetUUIDMetadataOperation', PNSetUUIDMetadataOperation: 'PNSetUUIDMetadataOperation', PNRemoveUUIDMetadataOperation: 'PNRemoveUUIDMetadataOperation', PNGetAllChannelMetadataOperation: 'PNGetAllChannelMetadataOperation', PNGetChannelMetadataOperation: 'PNGetChannelMetadataOperation', PNSetChannelMetadataOperation: 'PNSetChannelMetadataOperation', PNRemoveChannelMetadataOperation: 'PNRemoveChannelMetadataOperation', PNSetMembersOperation: 'PNSetMembersOperation', PNSetMembershipsOperation: 'PNSetMembershipsOperation', PNPushNotificationEnabledChannelsOperation: 'PNPushNotificationEnabledChannelsOperation', PNRemoveAllPushNotificationsOperation: 'PNRemoveAllPushNotificationsOperation', PNWhereNowOperation: 'PNWhereNowOperation', PNSetStateOperation: 'PNSetStateOperation', PNHereNowOperation: 'PNHereNowOperation', PNGetStateOperation: 'PNGetStateOperation', PNHeartbeatOperation: 'PNHeartbeatOperation', PNChannelGroupsOperation: 'PNChannelGroupsOperation', PNRemoveGroupOperation: 'PNRemoveGroupOperation', PNChannelsForGroupOperation: 'PNChannelsForGroupOperation', PNAddChannelsToGroupOperation: 'PNAddChannelsToGroupOperation', PNRemoveChannelsFromGroupOperation: 'PNRemoveChannelsFromGroupOperation', PNAccessManagerGrant: 'PNAccessManagerGrant', PNAccessManagerGrantToken: 'PNAccessManagerGrantToken', PNAccessManagerAudit: 'PNAccessManagerAudit' }; exports["default"] = _default; module.exports = exports.default; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; module.exports = {}; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(process) { function objectToList(o) { var l = []; Object.keys(o).forEach(function (key) { return l.push(key); }); return l; } function encodeString(input) { return encodeURIComponent(input).replace(/[!~*'()]/g, function (x) { return "%".concat(x.charCodeAt(0).toString(16).toUpperCase()); }); } function objectToListSorted(o) { return objectToList(o).sort(); } function signPamFromParams(params) { var l = objectToListSorted(params); return l.map(function (paramKey) { return "".concat(paramKey, "=").concat(encodeString(params[paramKey])); }).join('&'); } function endsWith(searchString, suffix) { return searchString.indexOf(suffix, this.length - suffix.length) !== -1; } function createPromise() { var successResolve; var failureResolve; var promise = new Promise(function (fulfill, reject) { successResolve = fulfill; failureResolve = reject; }); return { promise: promise, reject: failureResolve, fulfill: successResolve }; } var deprecationMessage = "The Objects v1 API has been deprecated.\nYou can learn more about Objects v2 API at https://www.pubnub.com/docs/web-javascript/api-reference-objects.\nIf you have questions about the Objects v2 API or require additional help with migrating to the new data model, please contact PubNub Support at support@pubnub.com."; function deprecated(fn) { return function () { if (typeof process !== 'undefined') { var _process, _process$env; if (((_process = process) === null || _process === void 0 ? void 0 : (_process$env = _process.env) === null || _process$env === void 0 ? void 0 : "production") !== 'test') { console.warn(deprecationMessage); } } return fn.apply(void 0, arguments); }; } module.exports = { signPamFromParams: signPamFromParams, endsWith: endsWith, createPromise: createPromise, encodeString: encodeString, deprecated: deprecated }; /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(39))) /***/ }), /* 4 */ /***/ (function(module, exports) { function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } module.exports = _defineProperty; /***/ }), /* 5 */ /***/ (function(module, exports) { function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } module.exports = _classCallCheck; /***/ }), /* 6 */ /***/ (function(module, exports) { function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } module.exports = _createClass; /***/ }), /* 7 */ /***/ (function(module, exports) { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { module.exports = _typeof = function _typeof(obj) { return typeof obj; }; } else { module.exports = _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } module.exports = _typeof; /***/ }), /* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _interopRequireDefault = __webpack_require__(0); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(__webpack_require__(5)); var _createClass2 = _interopRequireDefault(__webpack_require__(6)); var _defineProperty2 = _interopRequireDefault(__webpack_require__(4)); var _uuid = _interopRequireDefault(__webpack_require__(17)); var _flow_interfaces = __webpack_require__(2); var PRESENCE_TIMEOUT_MINIMUM = 20; var PRESENCE_TIMEOUT_DEFAULT = 300; var _default = function () { function _default(_ref) { var _setup$fileUploadPubl, _setup$useRandomIVs; var setup = _ref.setup, db = _ref.db; (0, _classCallCheck2["default"])(this, _default); (0, _defineProperty2["default"])(this, "_db", void 0); (0, _defineProperty2["default"])(this, "subscribeKey", void 0); (0, _defineProperty2["default"])(this, "publishKey", void 0); (0, _defineProperty2["default"])(this, "secretKey", void 0); (0, _defineProperty2["default"])(this, "cipherKey", void 0); (0, _defineProperty2["default"])(this, "authKey", void 0); (0, _defineProperty2["default"])(this, "UUID", void 0); (0, _defineProperty2["default"])(this, "proxy", void 0); (0, _defineProperty2["default"])(this, "instanceId", void 0); (0, _defineProperty2["default"])(this, "sdkName", void 0); (0, _defineProperty2["default"])(this, "sdkFamily", void 0); (0, _defineProperty2["default"])(this, "partnerId", void 0); (0, _defineProperty2["default"])(this, "filterExpression", void 0); (0, _defineProperty2["default"])(this, "suppressLeaveEvents", void 0); (0, _defineProperty2["default"])(this, "secure", void 0); (0, _defineProperty2["default"])(this, "origin", void 0); (0, _defineProperty2["default"])(this, "logVerbosity", void 0); (0, _defineProperty2["default"])(this, "useInstanceId", void 0); (0, _defineProperty2["default"])(this, "useRequestId", void 0); (0, _defineProperty2["default"])(this, "keepAlive", void 0); (0, _defineProperty2["default"])(this, "keepAliveSettings", void 0); (0, _defineProperty2["default"])(this, "autoNetworkDetection", void 0); (0, _defineProperty2["default"])(this, "announceSuccessfulHeartbeats", void 0); (0, _defineProperty2["default"])(this, "announceFailedHeartbeats", void 0); (0, _defineProperty2["default"])(this, "_presenceTimeout", void 0); (0, _defineProperty2["default"])(this, "_heartbeatInterval", void 0); (0, _defineProperty2["default"])(this, "_subscribeRequestTimeout", void 0); (0, _defineProperty2["default"])(this, "_transactionalRequestTimeout", void 0); (0, _defineProperty2["default"])(this, "_useSendBeacon", void 0); (0, _defineProperty2["default"])(this, "_PNSDKSuffix", void 0); (0, _defineProperty2["default"])(this, "requestMessageCountThreshold", void 0); (0, _defineProperty2["default"])(this, "restore", void 0); (0, _defineProperty2["default"])(this, "dedupeOnSubscribe", void 0); (0, _defineProperty2["default"])(this, "maximumCacheSize", void 0); (0, _defineProperty2["default"])(this, "customEncrypt", void 0); (0, _defineProperty2["default"])(this, "customDecrypt", void 0); (0, _defineProperty2["default"])(this, "fileUploadPublishRetryLimit", void 0); (0, _defineProperty2["default"])(this, "useRandomIVs", void 0); this._PNSDKSuffix = {}; this._db = db; this.instanceId = "pn-".concat(_uuid["default"].createUUID()); this.secretKey = setup.secretKey || setup.secret_key; this.subscribeKey = setup.subscribeKey || setup.subscribe_key; this.publishKey = setup.publishKey || setup.publish_key; this.sdkName = setup.sdkName; this.sdkFamily = setup.sdkFamily; this.partnerId = setup.partnerId; this.setAuthKey(setup.authKey); this.setCipherKey(setup.cipherKey); this.setFilterExpression(setup.filterExpression); this.origin = setup.origin || 'ps.pndsn.com'; this.secure = setup.ssl || false; this.restore = setup.restore || false; this.proxy = setup.proxy; this.keepAlive = setup.keepAlive; this.keepAliveSettings = setup.keepAliveSettings; this.autoNetworkDetection = setup.autoNetworkDetection || false; this.dedupeOnSubscribe = setup.dedupeOnSubscribe || false; this.maximumCacheSize = setup.maximumCacheSize || 100; this.customEncrypt = setup.customEncrypt; this.customDecrypt = setup.customDecrypt; this.fileUploadPublishRetryLimit = (_setup$fileUploadPubl = setup.fileUploadPublishRetryLimit) !== null && _setup$fileUploadPubl !== void 0 ? _setup$fileUploadPubl : 5; this.useRandomIVs = (_setup$useRandomIVs = setup.useRandomIVs) !== null && _setup$useRandomIVs !== void 0 ? _setup$useRandomIVs : true; if (typeof location !== 'undefined' && location.protocol === 'https:') { this.secure = true; } this.logVerbosity = setup.logVerbosity || false; this.suppressLeaveEvents = setup.suppressLeaveEvents || false; this.announceFailedHeartbeats = setup.announceFailedHeartbeats || true; this.announceSuccessfulHeartbeats = setup.announceSuccessfulHeartbeats || false; this.useInstanceId = setup.useInstanceId || false; this.useRequestId = setup.useRequestId || false; this.requestMessageCountThreshold = setup.requestMessageCountThreshold; this.setTransactionTimeout(setup.transactionalRequestTimeout || 15 * 1000); this.setSubscribeTimeout(setup.subscribeRequestTimeout || 310 * 1000); this.setSendBeaconConfig(setup.useSendBeacon || true); if (setup.presenceTimeout) { this.setPresenceTimeout(setup.presenceTimeout); } else { this._presenceTimeout = PRESENCE_TIMEOUT_DEFAULT; } if (setup.heartbeatInterval != null) { this.setHeartbeatInterval(setup.heartbeatInterval); } this.setUUID(this._decideUUID(setup.uuid)); } (0, _createClass2["default"])(_default, [{ key: "getAuthKey", value: function getAuthKey() { return this.authKey; } }, { key: "setAuthKey", value: function setAuthKey(val) { this.authKey = val; return this; } }, { key: "setCipherKey", value: function setCipherKey(val) { this.cipherKey = val; return this; } }, { key: "getUUID", value: function getUUID() { return this.UUID; } }, { key: "setUUID", value: function setUUID(val) { if (this._db && this._db.set) this._db.set("".concat(this.subscribeKey, "uuid"), val); this.UUID = val; return this; } }, { key: "getFilterExpression", value: function getFilterExpression() { return this.filterExpression; } }, { key: "setFilterExpression", value: function setFilterExpression(val) { this.filterExpression = val; return this; } }, { key: "getPresenceTimeout", value: function getPresenceTimeout() { return this._presenceTimeout; } }, { key: "setPresenceTimeout", value: function setPresenceTimeout(val) { if (val >= PRESENCE_TIMEOUT_MINIMUM) { this._presenceTimeout = val; } else { this._presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', this._presenceTimeout); } this.setHeartbeatInterval(this._presenceTimeout / 2 - 1); return this; } }, { key: "setProxy", value: function setProxy(proxy) { this.proxy = proxy; } }, { key: "getHeartbeatInterval", value: function getHeartbeatInterval() { return this._heartbeatInterval; } }, { key: "setHeartbeatInterval", value: function setHeartbeatInterval(val) { this._heartbeatInterval = val; return this; } }, { key: "getSubscribeTimeout", value: function getSubscribeTimeout() { return this._subscribeRequestTimeout; } }, { key: "setSubscribeTimeout", value: function setSubscribeTimeout(val) { this._subscribeRequestTimeout = val; return this; } }, { key: "getTransactionTimeout", value: function getTransactionTimeout() { return this._transactionalRequestTimeout; } }, { key: "setTransactionTimeout", value: function setTransactionTimeout(val) { this._transactionalRequestTimeout = val; return this; } }, { key: "isSendBeaconEnabled", value: function isSendBeaconEnabled() { return this._useSendBeacon; } }, { key: "setSendBeaconConfig", value: function setSendBeaconConfig(val) { this._useSendBeacon = val; return this; } }, { key: "getVersion", value: function getVersion() { return '4.32.1'; } }, { key: "_addPnsdkSuffix", value: function _addPnsdkSuffix(name, suffix) { this._PNSDKSuffix[name] = suffix; } }, { key: "_getPnsdkSuffix", value: function _getPnsdkSuffix(separator) { var _this = this; return Object.keys(this._PNSDKSuffix).reduce(function (result, key) { return result + separator + _this._PNSDKSuffix[key]; }, ''); } }, { key: "_decideUUID", value: function _decideUUID(providedUUID) { if (providedUUID) { return providedUUID; } if (this._db && this._db.get && this._db.get("".concat(this.subscribeKey, "uuid"))) { return this._db.get("".concat(this.subscribeKey, "uuid")); } return "pn-".concat(_uuid["default"].createUUID()); } }]); return _default; }(); exports["default"] = _default; module.exports = exports.default; /***/ }), /* 9 */ /***/ (function(module, exports, __webpack_require__) { var arrayWithHoles = __webpack_require__(77); var iterableToArrayLimit = __webpack_require__(78); var unsupportedIterableToArray = __webpack_require__(79); var nonIterableRest = __webpack_require__(81); function _slicedToArray(arr, i) { return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest(); } module.exports = _slicedToArray; /***/ }), /* 10 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _default = { PNNetworkUpCategory: 'PNNetworkUpCategory', PNNetworkDownCategory: 'PNNetworkDownCategory', PNNetworkIssuesCategory: 'PNNetworkIssuesCategory', PNTimeoutCategory: 'PNTimeoutCategory', PNBadRequestCategory: 'PNBadRequestCategory', PNAccessDeniedCategory: 'PNAccessDeniedCategory', PNUnknownCategory: 'PNUnknownCategory', PNReconnectedCategory: 'PNReconnectedCategory', PNConnectedCategory: 'PNConnectedCategory', PNRequestMessageCountExceededCategory: 'PNRequestMessageCountExceededCategory' }; exports["default"] = _default; module.exports = exports.default; /***/ }), /* 11 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(72); /***/ }), /* 12 */ /***/ (function(module, exports) { function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } module.exports = _asyncToGenerator; /***/ }), /* 13 */ /***/ (function(module, exports) { function _getPrototypeOf(o) { module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } module.exports = _getPrototypeOf; /***/ }), /* 14 */ /***/ (function(module, exports, __webpack_require__) { var setPrototypeOf = __webpack_require__(15); function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) setPrototypeOf(subClass, superClass); } module.exports = _inherits; /***/ }), /* 15 */ /***/ (function(module, exports) { function _setPrototypeOf(o, p) { module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } module.exports = _setPrototypeOf; /***/ }), /* 16 */ /***/ (function(module, exports, __webpack_require__) { var _typeof = __webpack_require__(7); var assertThisInitialized = __webpack_require__(19); function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return assertThisInitialized(self); } module.exports = _possibleConstructorReturn; /***/ }), /* 17 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _interopRequireDefault = __webpack_require__(0); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _lilUuid = _interopRequireDefault(__webpack_require__(31)); var _default = { createUUID: function createUUID() { if (_lilUuid["default"].uuid) { return _lilUuid["default"].uuid(); } else { return (0, _lilUuid["default"])(); } } }; exports["default"] = _default; module.exports = exports.default; /***/ }), /* 18 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _interopRequireDefault = __webpack_require__(0); Object.defineProperty(exports, "__esModule", { value: true }); exports.createValidationError = createValidationError; exports.generatePNSDK = generatePNSDK; exports.signRequest = signRequest; exports["default"] = _default; exports.PubNubError = void 0; var _defineProperty2 = _interopRequireDefault(__webpack_require__(4)); var _classCallCheck2 = _interopRequireDefault(__webpack_require__(5)); var _inherits2 = _interopRequireDefault(__webpack_require__(14)); var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(16)); var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(13)); var _wrapNativeSuper2 = _interopRequireDefault(__webpack_require__(45)); var _uuid = _interopRequireDefault(__webpack_require__(17)); var _flow_interfaces = __webpack_require__(2); var _utils = _interopRequireDefault(__webpack_require__(3)); var _config = _interopRequireDefault(__webpack_require__(8)); var _operations = _interopRequireDefault(__webpack_require__(1)); var _categories = _interopRequireDefault(__webpack_require__(10)); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } var PubNubError = function (_Error) { (0, _inherits2["default"])(PubNubError, _Error); var _super = _createSuper(PubNubError); function PubNubError(message, status) { var _this; (0, _classCallCheck2["default"])(this, PubNubError); _this = _super.call(this, message); _this.name = _this.constructor.name; _this.status = status; _this.message = message; return _this; } return PubNubError; }((0, _wrapNativeSuper2["default"])(Error)); exports.PubNubError = PubNubError; function createError(errorPayload, type) { errorPayload.type = type; errorPayload.error = true; return errorPayload; } function createValidationError(message) { return createError({ message: message }, 'validationError'); } function decideURL(endpoint, modules, incomingParams) { if (endpoint.usePost && endpoint.usePost(modules, incomingParams)) { return endpoint.postURL(modules, incomingParams); } else if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { return endpoint.patchURL(modules, incomingParams); } else if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { return endpoint.getFileURL(modules, incomingParams); } else { return endpoint.getURL(modules, incomingParams); } } function getAuthToken(endpoint, modules, incomingParams) { var token; if (endpoint.getAuthToken) { token = endpoint.getAuthToken(modules, incomingParams); } return token; } function generatePNSDK(config) { if (config.sdkName) { return config.sdkName; } var base = "PubNub-JS-".concat(config.sdkFamily); if (config.partnerId) { base += "-".concat(config.partnerId); } base += "/".concat(config.getVersion()); var pnsdkSuffix = config._getPnsdkSuffix(' '); if (pnsdkSuffix.length > 0) { base += pnsdkSuffix; } return base; } function getHttpMethod(modules, endpoint, incomingParams) { if (endpoint.usePost && endpoint.usePost(modules, incomingParams)) { return 'POST'; } else if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { return 'PATCH'; } else if (endpoint.useDelete && endpoint.useDelete(modules, incomingParams)) { return 'DELETE'; } else if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { return 'GETFILE'; } else { return 'GET'; } } function signRequest(modules, url, outgoingParams, incomingParams, endpoint) { var config = modules.config, crypto = modules.crypto; var httpMethod = getHttpMethod(modules, endpoint, incomingParams); outgoingParams.timestamp = Math.floor(new Date().getTime() / 1000); if (endpoint.getOperation() === 'PNPublishOperation' && endpoint.usePost && endpoint.usePost(modules, incomingParams)) { httpMethod = 'GET'; } if (httpMethod === 'GETFILE') { httpMethod = 'GET'; } var signInput = "".concat(httpMethod, "\n").concat(config.publishKey, "\n").concat(url, "\n").concat(_utils["default"].signPamFromParams(outgoingParams), "\n"); if (httpMethod === 'POST') { var payload = endpoint.postPayload(modules, incomingParams); if (typeof payload === 'string') { signInput += payload; } else { signInput += JSON.stringify(payload); } } else if (httpMethod === 'PATCH') { var _payload = endpoint.patchPayload(modules, incomingParams); if (typeof _payload === 'string') { signInput += _payload; } else { signInput += JSON.stringify(_payload); } } var signature = "v2.".concat(crypto.HMACSHA256(signInput)); signature = signature.replace(/\+/g, '-'); signature = signature.replace(/\//g, '_'); signature = signature.replace(/=+$/, ''); outgoingParams.signature = signature; } function _default(modules, endpoint) { var networking = modules.networking, config = modules.config, telemetryManager = modules.telemetryManager; var requestId = _uuid["default"].createUUID(); var callback = null; var promiseComponent = null; var incomingParams = {}; if (endpoint.getOperation() === _operations["default"].PNTimeOperation || endpoint.getOperation() === _operations["default"].PNChannelGroupsOperation) { callback = arguments.length <= 2 ? undefined : arguments[2]; } else { incomingParams = arguments.length <= 2 ? undefined : arguments[2]; callback = arguments.length <= 3 ? undefined : arguments[3]; } if (typeof Promise !== 'undefined' && !callback) { promiseComponent = _utils["default"].createPromise(); } var validationResult = endpoint.validateParams(modules, incomingParams); if (validationResult) { if (callback) { return callback(createValidationError(validationResult)); } else if (promiseComponent) { promiseComponent.reject(new PubNubError('Validation failed, check status for details', createValidationError(validationResult))); return promiseComponent.promise; } return; } var outgoingParams = endpoint.prepareParams(modules, incomingParams); var url = decideURL(endpoint, modules, incomingParams); var callInstance; var networkingParams = { url: url, operation: endpoint.getOperation(), timeout: endpoint.getRequestTimeout(modules), headers: endpoint.getRequestHeaders ? endpoint.getRequestHeaders() : {}, ignoreBody: typeof endpoint.ignoreBody === 'function' ? endpoint.ignoreBody(modules) : false, forceBuffered: typeof endpoint.forceBuffered === 'function' ? endpoint.forceBuffered(modules, incomingParams) : null }; outgoingParams.uuid = config.UUID; outgoingParams.pnsdk = generatePNSDK(config); var telemetryLatencies = telemetryManager.operationsLatencyForRequest(); if (Object.keys(telemetryLatencies).length) { outgoingParams = _objectSpread(_objectSpread({}, outgoingParams), telemetryLatencies); } if (config.useInstanceId) { outgoingParams.instanceid = config.instanceId; } if (config.useRequestId) { outgoingParams.requestid = requestId; } if (endpoint.isAuthSupported()) { var token = getAuthToken(endpoint, modules, incomingParams); var tokenOrKey = token || config.getAuthKey(); if (tokenOrKey) { outgoingParams.auth = tokenOrKey; } } if (config.secretKey) { signRequest(modules, url, outgoingParams, incomingParams, endpoint); } var onResponse = function onResponse(status, payload) { var _responseP; if (status.error) { if (endpoint.handleError) { endpoint.handleError(modules, incomingParams, status); } if (callback) { callback(status); } else if (promiseComponent) { promiseComponent.reject(new PubNubError('PubNub call failed, check status for details', status)); } return; } telemetryManager.stopLatencyMeasure(endpoint.getOperation(), requestId); var responseP = endpoint.handleResponse(modules, payload, incomingParams); if (typeof ((_responseP = responseP) === null || _responseP === void 0 ? void 0 : _responseP.then) !== 'function') { responseP = Promise.resolve(responseP); } responseP.then(function (result) { if (callback) { callback(status, result); } else if (promiseComponent) { promiseComponent.fulfill(result); } })["catch"](function (e) { if (callback) { var errorData = e; if (endpoint.getOperation() === _operations["default"].PNSubscribeOperation) { errorData = { statusCode: 400, error: true, operation: endpoint.getOperation(), errorData: e, category: _categories["default"].PNUnknownCategory }; } callback(errorData, null); } else if (promiseComponent) { promiseComponent.reject(new PubNubError('PubNub call failed, check status for details', e)); } }); }; telemetryManager.startLatencyMeasure(endpoint.getOperation(), requestId); if (getHttpMethod(modules, endpoint, incomingParams) === 'POST') { var payload = endpoint.postPayload(modules, incomingParams); callInstance = networking.POST(outgoingParams, payload, networkingParams, onResponse); } else if (getHttpMethod(modules, endpoint, incomingParams) === 'PATCH') { var _payload2 = endpoint.patchPayload(modules, incomingParams); callInstance = networking.PATCH(outgoingParams, _payload2, networkingParams, onResponse); } else if (getHttpMethod(modules, endpoint, incomingParams) === 'DELETE') { callInstance = networking.DELETE(outgoingParams, networkingParams, onResponse); } else if (getHttpMethod(modules, endpoint, incomingParams) === 'GETFILE') { callInstance = networking.GETFILE(outgoingParams, networkingParams, onResponse); } else { callInstance = networking.GET(outgoingParams, networkingParams, onResponse); } if (endpoint.getOperation() === _operations["default"].PNSubscribeOperation) { return callInstance; } if (promiseComponent) { return promiseComponent.promise; } } /***/ }), /* 19 */ /***/ (function(module, exports) { function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } module.exports = _assertThisInitialized; /***/ }), /* 20 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(Buffer) { var _interopRequireDefault = __webpack_require__(0); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(__webpack_require__(5)); var _createClass2 = _interopRequireDefault(__webpack_require__(6)); var _defineProperty2 = _interopRequireDefault(__webpack_require__(4)); var _config = _interopRequireDefault(__webpack_require__(8)); var _hmacSha = _interopRequireDefault(__webpack_require__(22)); function bufferToWordArray(b) { var wa = []; var i; for (i = 0; i < b.length; i += 1) { wa[i / 4 | 0] |= b[i] << 24 - 8 * i; } return _hmacSha["default"].lib.WordArray.create(wa, b.length); } var _default = function () { function _default(_ref) { var config = _ref.config; (0, _classCallCheck2["default"])(this, _default); (0, _defineProperty2["default"])(this, "_config", void 0); (0, _defineProperty2["default"])(this, "_iv", void 0); (0, _defineProperty2["default"])(this, "_allowedKeyEncodings", void 0); (0, _defineProperty2["default"])(this, "_allowedKeyLengths", void 0); (0, _defineProperty2["default"])(this, "_allowedModes", void 0); (0, _defineProperty2["default"])(this, "_defaultOptions", void 0); this._config = config; this._iv = '0123456789012345'; this._allowedKeyEncodings = ['hex', 'utf8', 'base64', 'binary']; this._allowedKeyLengths = [128, 256]; this._allowedModes = ['ecb', 'cbc']; this._defaultOptions = { encryptKey: true, keyEncoding: 'utf8', keyLength: 256, mode: 'cbc' }; } (0, _createClass2["default"])(_default, [{ key: "HMACSHA256", value: function HMACSHA256(data) { var hash = _hmacSha["default"].HmacSHA256(data, this._config.secretKey); return hash.toString(_hmacSha["default"].enc.Base64); } }, { key: "SHA256", value: function SHA256(s) { return _hmacSha["default"].SHA256(s).toString(_hmacSha["default"].enc.Hex); } }, { key: "_parseOptions", value: function _parseOptions(incomingOptions) { var options = incomingOptions || {}; if (!options.hasOwnProperty('encryptKey')) options.encryptKey = this._defaultOptions.encryptKey; if (!options.hasOwnProperty('keyEncoding')) options.keyEncoding = this._defaultOptions.keyEncoding; if (!options.hasOwnProperty('keyLength')) options.keyLength = this._defaultOptions.keyLength; if (!options.hasOwnProperty('mode')) options.mode = this._defaultOptions.mode; if (this._allowedKeyEncodings.indexOf(options.keyEncoding.toLowerCase()) === -1) { options.keyEncoding = this._defaultOptions.keyEncoding; } if (this._allowedKeyLengths.indexOf(parseInt(options.keyLength, 10)) === -1) { options.keyLength = this._defaultOptions.keyLength; } if (this._allowedModes.indexOf(options.mode.toLowerCase()) === -1) { options.mode = this._defaultOptions.mode; } return options; } }, { key: "_decodeKey", value: function _decodeKey(key, options) { if (options.keyEncoding === 'base64') { return _hmacSha["default"].enc.Base64.parse(key); } else if (options.keyEncoding === 'hex') { return _hmacSha["default"].enc.Hex.parse(key); } else { return key; } } }, { key: "_getPaddedKey", value: function _getPaddedKey(key, options) { key = this._decodeKey(key, options); if (options.encryptKey) { return _hmacSha["default"].enc.Utf8.parse(this.SHA256(key).slice(0, 32)); } else { return key; } } }, { key: "_getMode", value: function _getMode(options) { if (options.mode === 'ecb') { return _hmacSha["default"].mode.ECB; } else { return _hmacSha["default"].mode.CBC; } } }, { key: "_getIV", value: function _getIV(options) { return options.mode === 'cbc' ? _hmacSha["default"].enc.Utf8.parse(this._iv) : null; } }, { key: "_getRandomIV", value: function _getRandomIV() { return _hmacSha["default"].lib.WordArray.random(16); } }, { key: "encrypt", value: function encrypt(data, customCipherKey, options) { if (this._config.customEncrypt) { return this._config.customEncrypt(data); } else { return this.pnEncrypt(data, customCipherKey, options); } } }, { key: "decrypt", value: function decrypt(data, customCipherKey, options) { if (this._config.customDecrypt) { return this._config.customDecrypt(data); } else { return this.pnDecrypt(data, customCipherKey, options); } } }, { key: "pnEncrypt", value: function pnEncrypt(data, customCipherKey, options) { if (!customCipherKey && !this._config.cipherKey) return data; options = this._parseOptions(options); var mode = this._getMode(options); var cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options); if (this._config.useRandomIVs) { var waIv = this._getRandomIV(); var waPayload = _hmacSha["default"].AES.encrypt(data, cipherKey, { iv: waIv, mode: mode }).ciphertext; return waIv.clone().concat(waPayload.clone()).toString(_hmacSha["default"].enc.Base64); } else { var iv = this._getIV(options); var encryptedHexArray = _hmacSha["default"].AES.encrypt(data, cipherKey, { iv: iv, mode: mode }).ciphertext; var base64Encrypted = encryptedHexArray.toString(_hmacSha["default"].enc.Base64); return base64Encrypted || data; } } }, { key: "pnDecrypt", value: function pnDecrypt(data, customCipherKey, options) { if (!customCipherKey && !this._config.cipherKey) return data; options = this._parseOptions(options); var mode = this._getMode(options); var cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options); if (this._config.useRandomIVs) { var ciphertext = Buffer.from(data, 'base64'); var iv = bufferToWordArray(ciphertext.slice(0, 16)); var payload = bufferToWordArray(ciphertext.slice(16)); try { var plainJSON = _hmacSha["default"].AES.decrypt({ ciphertext: payload }, cipherKey, { iv: iv, mode: mode }).toString(_hmacSha["default"].enc.Utf8); var plaintext = JSON.parse(plainJSON); return plaintext; } catch (e) { return null; } } else { var _iv = this._getIV(options); try { var _ciphertext = _hmacSha["default"].enc.Base64.parse(data); var _plainJSON = _hmacSha["default"].AES.decrypt({ ciphertext: _ciphertext }, cipherKey, { iv: _iv, mode: mode }).toString(_hmacSha["default"].enc.Utf8); var _plaintext = JSON.parse(_plainJSON); return _plaintext; } catch (e) { return null; } } } }]); return _default; }(); exports["default"] = _default; module.exports = exports.default; /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(21).Buffer)) /***/ }), /* 21 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(global) {/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <http://feross.org> * @license MIT */ /* eslint-disable no-proto */ var base64 = __webpack_require__(33) var ieee754 = __webpack_require__(34) var isArray = __webpack_require__(35) exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) * === false Use Object implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * * Due to various browser bugs, sometimes the Object implementation will be used even * when the browser supports typed arrays. * * Note: * * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. * * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. * * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of * incorrect length in some situations. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they * get the Object implementation, which is slower but behaves correctly. */ Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined ? global.TYPED_ARRAY_SUPPORT : typedArraySupport() /* * Export kMaxLength after typed array support is determined. */ exports.kMaxLength = kMaxLength() function typedArraySupport () { try { var arr = new Uint8Array(1) arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} return arr.foo() === 42 && // typed array instances can be augmented typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` } catch (e) { return false } } function kMaxLength () { return Buffer.TYPED_ARRAY_SUPPORT ? 0x7fffffff : 0x3fffffff } function createBuffer (that, length) { if (kMaxLength() < length) { throw new RangeError('Invalid typed array length') } if (Buffer.TYPED_ARRAY_SUPPORT) { // Return an augmented `Uint8Array` instance, for best performance that = new Uint8Array(length) that.__proto__ = Buffer.prototype } else { // Fallback: Return an object instance of the Buffer class if (that === null) { that = new Buffer(length) } that.length = length } return that } /** * The Buffer constructor returns instances of `Uint8Array` that have their * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of * `Uint8Array`, so the returned instances will have all the node `Buffer` methods * and the `Uint8Array` methods. Square bracket notation works as expected -- it * returns a single octet. * * The `Uint8Array` prototype remains unmodified. */ function Buffer (arg, encodingOrOffset, length) { if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { return new Buffer(arg, encodingOrOffset, length) } // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { throw new Error( 'If encoding is specified then the first argument must be a string' ) } return allocUnsafe(this, arg) } return from(this, arg, encodingOrOffset, length) } Buffer.poolSize = 8192 // not used by this implementation // TODO: Legacy, not needed anymore. Remove in next major version. Buffer._augment = function (arr) { arr.__proto__ = Buffer.prototype return arr } function from (that, value, encodingOrOffset, length) { if (typeof value === 'number') { throw new TypeError('"value" argument must not be a number') } if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { return fromArrayBuffer(that, value, encodingOrOffset, length) } if (typeof value === 'string') { return fromString(that, value, encodingOrOffset) } return fromObject(that, value) } /** * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError * if value is a number. * Buffer.from(str[, encoding]) * Buffer.from(array) * Buffer.from(buffer) * Buffer.from(arrayBuffer[, byteOffset[, length]]) **/ Buffer.from = function (value, encodingOrOffset, length) { return from(null, value, encodingOrOffset, length) } if (Buffer.TYPED_ARRAY_SUPPORT) { Buffer.prototype.__pr